diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index d6fdf48..8f383da 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -1,6 +1,6 @@
name: Build libsm64
-on: [push, pull_request]
+on: [ push, pull_request ]
jobs:
Build:
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..30cf57e
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,10 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Ignored default folder with query files
+/queries/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..a55e7a1
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/editor.xml b/.idea/editor.xml
new file mode 100644
index 0000000..a7ae94c
--- /dev/null
+++ b/.idea/editor.xml
@@ -0,0 +1,392 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..df87cf9
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..9f2b25a
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/LICENSE.md b/LICENSE.md
index 0e259d4..cb9b058 100644
--- a/LICENSE.md
+++ b/LICENSE.md
@@ -38,84 +38,84 @@ terms, with knowledge of his or her Copyright and Related Rights in the
Work and the meaning and intended legal effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be
-protected by copyright and related or neighboring rights ("Copyright and
-Related Rights"). Copyright and Related Rights include, but are not
-limited to, the following:
+ protected by copyright and related or neighboring rights ("Copyright and
+ Related Rights"). Copyright and Related Rights include, but are not
+ limited to, the following:
- i. the right to reproduce, adapt, distribute, perform, display,
- communicate, and translate a Work;
- ii. moral rights retained by the original author(s) and/or performer(s);
+i. the right to reproduce, adapt, distribute, perform, display,
+communicate, and translate a Work;
+ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or
- likeness depicted in a Work;
- iv. rights protecting against unfair competition in regards to a Work,
- subject to the limitations in paragraph 4(a), below;
- v. rights protecting the extraction, dissemination, use and reuse of data
- in a Work;
- vi. database rights (such as those arising under Directive 96/9/EC of the
- European Parliament and of the Council of 11 March 1996 on the legal
- protection of databases, and under any national implementation
- thereof, including any amended or successor version of such
- directive); and
+likeness depicted in a Work;
+iv. rights protecting against unfair competition in regards to a Work,
+subject to the limitations in paragraph 4(a), below;
+v. rights protecting the extraction, dissemination, use and reuse of data
+in a Work;
+vi. database rights (such as those arising under Directive 96/9/EC of the
+European Parliament and of the Council of 11 March 1996 on the legal
+protection of databases, and under any national implementation
+thereof, including any amended or successor version of such
+directive); and
vii. other similar, equivalent or corresponding rights throughout the
- world based on applicable law or treaty, and any national
- implementations thereof.
+world based on applicable law or treaty, and any national
+implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention
-of, applicable law, Affirmer hereby overtly, fully, permanently,
-irrevocably and unconditionally waives, abandons, and surrenders all of
-Affirmer's Copyright and Related Rights and associated claims and causes
-of action, whether now known or unknown (including existing as well as
-future claims and causes of action), in the Work (i) in all territories
-worldwide, (ii) for the maximum duration provided by applicable law or
-treaty (including future time extensions), (iii) in any current or future
-medium and for any number of copies, and (iv) for any purpose whatsoever,
-including without limitation commercial, advertising or promotional
-purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
-member of the public at large and to the detriment of Affirmer's heirs and
-successors, fully intending that such Waiver shall not be subject to
-revocation, rescission, cancellation, termination, or any other legal or
-equitable action to disrupt the quiet enjoyment of the Work by the public
-as contemplated by Affirmer's express Statement of Purpose.
+ of, applicable law, Affirmer hereby overtly, fully, permanently,
+ irrevocably and unconditionally waives, abandons, and surrenders all of
+ Affirmer's Copyright and Related Rights and associated claims and causes
+ of action, whether now known or unknown (including existing as well as
+ future claims and causes of action), in the Work (i) in all territories
+ worldwide, (ii) for the maximum duration provided by applicable law or
+ treaty (including future time extensions), (iii) in any current or future
+ medium and for any number of copies, and (iv) for any purpose whatsoever,
+ including without limitation commercial, advertising or promotional
+ purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
+ member of the public at large and to the detriment of Affirmer's heirs and
+ successors, fully intending that such Waiver shall not be subject to
+ revocation, rescission, cancellation, termination, or any other legal or
+ equitable action to disrupt the quiet enjoyment of the Work by the public
+ as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason
-be judged legally invalid or ineffective under applicable law, then the
-Waiver shall be preserved to the maximum extent permitted taking into
-account Affirmer's express Statement of Purpose. In addition, to the
-extent the Waiver is so judged Affirmer hereby grants to each affected
-person a royalty-free, non transferable, non sublicensable, non exclusive,
-irrevocable and unconditional license to exercise Affirmer's Copyright and
-Related Rights in the Work (i) in all territories worldwide, (ii) for the
-maximum duration provided by applicable law or treaty (including future
-time extensions), (iii) in any current or future medium and for any number
-of copies, and (iv) for any purpose whatsoever, including without
-limitation commercial, advertising or promotional purposes (the
-"License"). The License shall be deemed effective as of the date CC0 was
-applied by Affirmer to the Work. Should any part of the License for any
-reason be judged legally invalid or ineffective under applicable law, such
-partial invalidity or ineffectiveness shall not invalidate the remainder
-of the License, and in such case Affirmer hereby affirms that he or she
-will not (i) exercise any of his or her remaining Copyright and Related
-Rights in the Work or (ii) assert any associated claims and causes of
-action with respect to the Work, in either case contrary to Affirmer's
-express Statement of Purpose.
+ be judged legally invalid or ineffective under applicable law, then the
+ Waiver shall be preserved to the maximum extent permitted taking into
+ account Affirmer's express Statement of Purpose. In addition, to the
+ extent the Waiver is so judged Affirmer hereby grants to each affected
+ person a royalty-free, non transferable, non sublicensable, non exclusive,
+ irrevocable and unconditional license to exercise Affirmer's Copyright and
+ Related Rights in the Work (i) in all territories worldwide, (ii) for the
+ maximum duration provided by applicable law or treaty (including future
+ time extensions), (iii) in any current or future medium and for any number
+ of copies, and (iv) for any purpose whatsoever, including without
+ limitation commercial, advertising or promotional purposes (the
+ "License"). The License shall be deemed effective as of the date CC0 was
+ applied by Affirmer to the Work. Should any part of the License for any
+ reason be judged legally invalid or ineffective under applicable law, such
+ partial invalidity or ineffectiveness shall not invalidate the remainder
+ of the License, and in such case Affirmer hereby affirms that he or she
+ will not (i) exercise any of his or her remaining Copyright and Related
+ Rights in the Work or (ii) assert any associated claims and causes of
+ action with respect to the Work, in either case contrary to Affirmer's
+ express Statement of Purpose.
4. Limitations and Disclaimers.
- a. No trademark or patent rights held by Affirmer are waived, abandoned,
- surrendered, licensed or otherwise affected by this document.
- b. Affirmer offers the Work as-is and makes no representations or
- warranties of any kind concerning the Work, express, implied,
- statutory or otherwise, including without limitation warranties of
- title, merchantability, fitness for a particular purpose, non
- infringement, or the absence of latent or other defects, accuracy, or
- the present or absence of errors, whether or not discoverable, all to
- the greatest extent permissible under applicable law.
- c. Affirmer disclaims responsibility for clearing rights of other persons
- that may apply to the Work or any use thereof, including without
- limitation any person's Copyright and Related Rights in the Work.
- Further, Affirmer disclaims responsibility for obtaining any necessary
- consents, permissions or other rights required for any use of the
- Work.
- d. Affirmer understands and acknowledges that Creative Commons is not a
- party to this document and has no duty or obligation with respect to
- this CC0 or use of the Work.
+a. No trademark or patent rights held by Affirmer are waived, abandoned,
+surrendered, licensed or otherwise affected by this document.
+b. Affirmer offers the Work as-is and makes no representations or
+warranties of any kind concerning the Work, express, implied,
+statutory or otherwise, including without limitation warranties of
+title, merchantability, fitness for a particular purpose, non
+infringement, or the absence of latent or other defects, accuracy, or
+the present or absence of errors, whether or not discoverable, all to
+the greatest extent permissible under applicable law.
+c. Affirmer disclaims responsibility for clearing rights of other persons
+that may apply to the Work or any use thereof, including without
+limitation any person's Copyright and Related Rights in the Work.
+Further, Affirmer disclaims responsibility for obtaining any necessary
+consents, permissions or other rights required for any use of the
+Work.
+d. Affirmer understands and acknowledges that Creative Commons is not a
+party to this document and has no duty or obligation with respect to
+this CC0 or use of the Work.
diff --git a/README.md b/README.md
index cb777c8..561a560 100644
--- a/README.md
+++ b/README.md
@@ -31,10 +31,11 @@ project under the `test` directory as well, demonstrating usage of the library.
- To run the test program you'll need a SM64 US ROM in the root of the repository with the name `baserom.us.z64`.
## Building on Windows
+
- [Follow steps 1-4 for setting up MSYS2 MinGW 64 here](https://github.com/sm64-port/sm64-port#windows), but replace the repository URL with `https://github.com/libsm64/libsm64.git`
- Ensure the SDL2 and GLEW libraries are installed if you're building the test program.
- - 64 bits: `pacman -S mingw-w64-x86_64-SDL2 mingw-w64-x86_64-glew`.
- - 32 bits: `pacman -S mingw-w64-i686-SDL2 mingw-w64-i686-glew`.
+ - 64 bits: `pacman -S mingw-w64-x86_64-SDL2 mingw-w64-x86_64-glew`.
+ - 32 bits: `pacman -S mingw-w64-i686-SDL2 mingw-w64-i686-glew`.
- Run `make` to build
- To run the test program you'll need a SM64 US ROM in the root of the repository with the name `baserom.us.z64`.
diff --git a/import-mario-geo.py b/import-mario-geo.py
index 0aa1397..6a8305d 100755
--- a/import-mario-geo.py
+++ b/import-mario-geo.py
@@ -54,6 +54,7 @@ model_inc_h = """
#include "../include/PR/gbi.h"
"""
+
def main():
global model_inc_h
@@ -82,7 +83,6 @@ def main():
lines.insert(0, "#include \"../../load_tex_data.h\"")
model_inc_c = "\n".join(lines)
-
with open("src/decomp/mario/geo.inc.c", "w") as file:
file.write(geo_inc_c_header + geo_inc_c + geo_inc_c_footer)
@@ -95,5 +95,6 @@ def main():
with open("src/decomp/mario/geo.inc.h", "w") as file:
file.write(geo_inc_h)
+
if __name__ == "__main__":
main()
diff --git a/import-test-collision.py b/import-test-collision.py
index 54b2c1f..62b87ff 100755
--- a/import-test-collision.py
+++ b/import-test-collision.py
@@ -13,6 +13,7 @@ extern const struct SM64Surface surfaces[];
extern const size_t surfaces_count;
"""
+
def main():
print("Downloading " + BOB_COLLISION_URL)
in_lines = urllib.request.urlopen(BOB_COLLISION_URL).read().decode('utf8').splitlines()
@@ -28,19 +29,19 @@ def main():
tokens = line.strip().replace("(", ",").replace(")", "").split(",")
if tokens[0] == "COL_VERTEX":
- verts.append([ int(tokens[1]), int(tokens[2]), int(tokens[3]) ])
+ verts.append([int(tokens[1]), int(tokens[2]), int(tokens[3])])
elif tokens[0] == "COL_TRI_INIT":
mode = tokens[1]
elif tokens[0] == "COL_TRI":
- tris.append([ int(tokens[1]), int(tokens[2]), int(tokens[3]), mode ])
+ tris.append([int(tokens[1]), int(tokens[2]), int(tokens[3]), mode])
out_lines = []
for tri in tris:
- out_lines.append("{%s,0,TERRAIN_SNOW,{{%s,%s,%s},{%s,%s,%s},{%s,%s,%s}}}"%(tri[3], \
- verts[tri[0]][0], verts[tri[0]][1], verts[tri[0]][2], \
- verts[tri[1]][0], verts[tri[1]][1], verts[tri[1]][2], \
- verts[tri[2]][0], verts[tri[2]][1], verts[tri[2]][2]))
+ out_lines.append("{%s,0,TERRAIN_SNOW,{{%s,%s,%s},{%s,%s,%s},{%s,%s,%s}}}" % (tri[3], \
+ verts[tri[0]][0], verts[tri[0]][1], verts[tri[0]][2], \
+ verts[tri[1]][0], verts[tri[1]][1], verts[tri[1]][2], \
+ verts[tri[2]][0], verts[tri[2]][1], verts[tri[2]][2]))
out_str = ",\n".join(out_lines)
out_str = "const struct SM64Surface surfaces[] = {\n" + out_str + "};\n\n"
@@ -54,5 +55,6 @@ def main():
with open("test/level.h", "w") as file:
file.write(LEVEL_H)
+
if __name__ == "__main__":
main()
diff --git a/src/decomp/audio/copt/seq_channel_layer_process_script_copt.inc.c b/src/decomp/audio/copt/seq_channel_layer_process_script_copt.inc.c
index 7b6b777..7ff7af5 100644
--- a/src/decomp/audio/copt/seq_channel_layer_process_script_copt.inc.c
+++ b/src/decomp/audio/copt/seq_channel_layer_process_script_copt.inc.c
@@ -114,8 +114,9 @@ struct Instrument **instOut = _instOut;\
}
#endif
-void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
- struct SequencePlayer *seqPlayer; // sp5C, t4
+void seq_channel_layer_process_script(struct SequenceChannelLayer *layer)
+{
+ struct SequencePlayer *seqPlayer; // sp5C, t4
struct SequenceChannel *seqChannel; // sp58, t5
struct M64ScriptState *state;
struct Portamento *portamento;
@@ -124,51 +125,57 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
struct Drum *drum;
s32 temp_a0_5;
u8 sameSound;
- u8 cmd; // a0 sp3E, EU s2
- u8 cmdSemitone; // sp3D, t0
- u16 sp3A; // t2, a0, a1
- f32 tuning; // f0
- s32 vel; // sp30, t3
- s32 usedSemitone; // a1
- f32 freqScale; // sp28, f0
+ u8 cmd; // a0 sp3E, EU s2
+ u8 cmdSemitone; // sp3D, t0
+ u16 sp3A; // t2, a0, a1
+ f32 tuning; // f0
+ s32 vel; // sp30, t3
+ s32 usedSemitone; // a1
+ f32 freqScale; // sp28, f0
f32 sp24;
f32 temp_f12;
f32 temp_f2;
-//! Copt: manually inline these functions in the scope of this routine
-#ifdef __sgi
-#pragma inline routine(m64_read_u8)
-#pragma inline routine(m64_read_compressed_u16)
-#pragma inline routine(m64_read_s16)
-#pragma inline routine(get_instrument)
-#endif
+ //! Copt: manually inline these functions in the scope of this routine
+ #ifdef __sgi
+ #pragma inline routine(m64_read_u8)
+ #pragma inline routine(m64_read_compressed_u16)
+ #pragma inline routine(m64_read_s16)
+ #pragma inline routine(get_instrument)
+ #endif
sameSound = TRUE;
- if ((*layer).enabled == FALSE) {
+ if ((*layer).enabled == FALSE)
+ {
return;
}
- if ((*layer).delay > 1) {
+ if ((*layer).delay > 1)
+ {
(*layer).delay--;
- if (!layer->stopSomething && layer->delay <= layer->duration) {
+ if (!layer->stopSomething && layer->delay <= layer->duration)
+ {
seq_channel_layer_note_decay(layer);
layer->stopSomething = TRUE;
}
return;
}
- if (!layer->continuousNotes) {
+ if (!layer->continuousNotes)
+ {
seq_channel_layer_note_decay(layer);
}
if (PORTAMENTO_MODE(layer->portamento) == PORTAMENTO_MODE_1 ||
- PORTAMENTO_MODE(layer->portamento) == PORTAMENTO_MODE_2) {
+ PORTAMENTO_MODE(layer->portamento) == PORTAMENTO_MODE_2)
+ {
layer->portamento.mode = 0;
}
seqChannel = (*layer).seqChannel;
seqPlayer = (*seqChannel).seqPlayer;
- for (;;) {
+ for (;;)
+ {
state = &layer->scriptState;
//M64_READ_U8(state, cmd);
{
@@ -177,13 +184,16 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
cmd = *_ptr_pc;
}
- if (cmd <= 0xc0) {
+ if (cmd <= 0xc0)
+ {
break;
}
- switch (cmd) {
+ switch (cmd)
+ {
case 0xff: // layer_end; function return or end of script
- if (state->depth == 0) {
+ if (state->depth == 0)
+ {
// N.B. this function call is *not* inlined even though it's
// within the same file, unlike in the rest of this function.
seq_channel_layer_disable(layer);
@@ -204,9 +214,12 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
break;
case 0xf7: // layer_loopend
- if (--state->remLoopIters[state->depth - 1] != 0) {
+ if (--state->remLoopIters[state->depth - 1] != 0)
+ {
state->pc = state->stack[state->depth - 1];
- } else {
+ }
+ else
+ {
state->depth--;
}
break;
@@ -219,19 +232,25 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
case 0xc1: // layer_setshortnotevelocity
case 0xca: // layer_setpan
temp_a0_5 = *(state->pc++);
- if (cmd == 0xc1) {
+ if (cmd == 0xc1)
+ {
layer->velocitySquare = (f32)(temp_a0_5 * temp_a0_5);
- } else {
- layer->pan = (f32) temp_a0_5 / US_FLOAT(128.0);
+ }
+ else
+ {
+ layer->pan = (f32)temp_a0_5 / US_FLOAT(128.0);
}
break;
case 0xc2: // layer_transpose; set transposition in semitones
case 0xc9: // layer_setshortnoteduration
temp_a0_5 = *(state->pc++);
- if (cmd == 0xc9) {
+ if (cmd == 0xc9)
+ {
layer->noteDuration = temp_a0_5;
- } else {
+ }
+ else
+ {
layer->transposition = temp_a0_5;
}
break;
@@ -240,17 +259,20 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
case 0xc5: // layer_somethingoff
//! copt needs a ternary:
//layer->continuousNotes = (cmd == 0xc4) ? TRUE : FALSE;
+ {
+ u8 setting;
+ if (cmd == 0xc4)
{
- u8 setting;
- if (cmd == 0xc4) {
- setting = TRUE;
- } else {
- setting = FALSE;
- }
- layer->continuousNotes = setting;
- seq_channel_layer_note_decay(layer);
+ setting = TRUE;
}
- break;
+ else
+ {
+ setting = FALSE;
+ }
+ layer->continuousNotes = setting;
+ seq_channel_layer_note_decay(layer);
+ }
+ break;
case 0xc3: // layer_setshortnotedefaultplaypercentage
M64_READ_COMPRESSED_U16(state, sp3A);
@@ -260,7 +282,8 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
case 0xc6: // layer_setinstr
M64_READ_U8(state, cmdSemitone);
- if (cmdSemitone < 127) {
+ if (cmdSemitone < 127)
+ {
GET_INSTRUMENT(seqChannel, cmdSemitone, &(*layer).instrument, &(*layer).adsr, cmdSemitone, 1);
}
break;
@@ -273,13 +296,15 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
cmdSemitone += (*layer).transposition;
cmdSemitone += (*seqPlayer).transposition;
- if (cmdSemitone >= 0x80) {
+ if (cmdSemitone >= 0x80)
+ {
cmdSemitone = 0;
}
layer->portamentoTargetNote = cmdSemitone;
// If special, the next param is u8 instead of var
- if (PORTAMENTO_IS_SPECIAL((*layer).portamento)) {
+ if (PORTAMENTO_IS_SPECIAL((*layer).portamento))
+ {
layer->portamentoTime = *((state)->pc++);
break;
}
@@ -293,7 +318,8 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
break;
default:
- switch (cmd & 0xf0) {
+ switch (cmd & 0xf0)
+ {
case 0xd0: // layer_setshortnotevelocityfromtable
sp3A = seqPlayer->shortNoteVelocityTable[cmd & 0xf];
(*layer).velocitySquare = (f32)(sp3A * sp3A);
@@ -305,14 +331,19 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
}
}
- if (cmd == 0xc0) { // layer_delay
+ if (cmd == 0xc0)
+ { // layer_delay
M64_READ_COMPRESSED_U16(state, layer->delay);
layer->stopSomething = TRUE;
- } else {
+ }
+ else
+ {
layer->stopSomething = FALSE;
- if (seqChannel->largeNotes == TRUE) {
- switch (cmd & 0xc0) {
+ if (seqChannel->largeNotes == TRUE)
+ {
+ switch (cmd & 0xc0)
+ {
case 0x00: // layer_note0 (play percentage, velocity, duration)
M64_READ_COMPRESSED_U16(state, sp3A);
vel = *((*state).pc++);
@@ -333,11 +364,13 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
layer->noteDuration = *((*state).pc++);
goto l1090;
}
-l1090:
- cmdSemitone = cmd - (cmd & 0xc0);
+ l1090: cmdSemitone = cmd - (cmd & 0xc0);
layer->velocitySquare = vel * vel;
- } else {
- switch (cmd & 0xc0) {
+ }
+ else
+ {
+ switch (cmd & 0xc0)
+ {
case 0x00: // play note, type 0 (play percentage)
M64_READ_COMPRESSED_U16(state, sp3A);
layer->playPercentage = sp3A;
@@ -351,9 +384,7 @@ l1090:
sp3A = layer->playPercentage;
goto l1138;
}
-l1138:
-
- cmdSemitone = cmd - (cmd & 0xc0);
+ l1138: cmdSemitone = cmd - (cmd & 0xc0);
}
layer->delay = sp3A;
@@ -361,14 +392,20 @@ l1138:
if ((seqPlayer->muted && (seqChannel->muteBehavior & MUTE_BEHAVIOR_STOP_NOTES) != 0)
|| seqChannel->stopSomething2
|| !seqChannel->hasInstrument
- ) {
+ )
+ {
layer->stopSomething = TRUE;
- } else {
- if (seqChannel->instOrWave == 0) { // drum
+ }
+ else
+ {
+ if (seqChannel->instOrWave == 0)
+ { // drum
cmdSemitone += (*seqChannel).transposition + (*layer).transposition;
- if (cmdSemitone >= gCtlEntries[seqChannel->bankId].numDrums) {
+ if (cmdSemitone >= gCtlEntries[seqChannel->bankId].numDrums)
+ {
cmdSemitone = gCtlEntries[seqChannel->bankId].numDrums;
- if (cmdSemitone == 0) {
+ if (cmdSemitone == 0)
+ {
// this goto looks a bit like a function return...
layer->stopSomething = TRUE;
goto skip;
@@ -378,9 +415,12 @@ l1138:
}
drum = gCtlEntries[seqChannel->bankId].drums[cmdSemitone];
- if (drum == NULL) {
+ if (drum == NULL)
+ {
layer->stopSomething = TRUE;
- } else {
+ }
+ else
+ {
layer->adsr.envelope = drum->envelope;
layer->adsr.releaseRate = drum->releaseRate;
layer->pan = FLOAT_CAST(drum->pan) / US_FLOAT(128.0);
@@ -389,34 +429,49 @@ l1138:
}
skip:;
- } else { // instrument
+ }
+ else
+ { // instrument
cmdSemitone += (*seqPlayer).transposition + (*seqChannel).transposition + (*layer).transposition;
- if (cmdSemitone >= 0x80) {
+ if (cmdSemitone >= 0x80)
+ {
layer->stopSomething = TRUE;
- } else {
+ }
+ else
+ {
instrument = layer->instrument;
- if (instrument == NULL) {
+ if (instrument == NULL)
+ {
instrument = seqChannel->instrument;
}
- if (layer->portamento.mode != 0) {
+ if (layer->portamento.mode != 0)
+ {
//! copt needs a ternary:
//usedSemitone = (layer->portamentoTargetNote < cmdSemitone) ? cmdSemitone : layer->portamentoTargetNote;
- if (layer->portamentoTargetNote < cmdSemitone) {
+ if (layer->portamentoTargetNote < cmdSemitone)
+ {
usedSemitone = cmdSemitone;
- } else {
+ }
+ else
+ {
usedSemitone = layer->portamentoTargetNote;
}
- if (instrument != NULL) {
- sound = (u8) usedSemitone < instrument->normalRangeLo ? &instrument->lowNotesSound
- : (u8) usedSemitone <= instrument->normalRangeHi ?
- &instrument->normalNotesSound : &instrument->highNotesSound;
+ if (instrument != NULL)
+ {
+ sound = (u8)usedSemitone < instrument->normalRangeLo
+ ? &instrument->lowNotesSound
+ : (u8)usedSemitone <= instrument->normalRangeHi
+ ? &instrument->normalNotesSound
+ : &instrument->highNotesSound;
sameSound = (sound == (*layer).sound);
layer->sound = sound;
tuning = (*sound).tuning;
- } else {
+ }
+ else
+ {
layer->sound = NULL;
tuning = 1.0f;
}
@@ -425,7 +480,8 @@ l1138:
temp_f12 = gNoteFrequencies[layer->portamentoTargetNote] * tuning;
portamento = &layer->portamento;
- switch (PORTAMENTO_MODE(layer->portamento)) {
+ switch (PORTAMENTO_MODE(layer->portamento))
+ {
case PORTAMENTO_MODE_1:
case PORTAMENTO_MODE_3:
case PORTAMENTO_MODE_5:
@@ -439,29 +495,34 @@ l1138:
sp24 = temp_f12;
goto l13cc;
}
-l13cc:
- portamento->extent = sp24 / freqScale - US_FLOAT(1.0);
- if (PORTAMENTO_IS_SPECIAL((*layer).portamento)) {
+ l13cc: portamento->extent = sp24 / freqScale - US_FLOAT(1.0);
+ if (PORTAMENTO_IS_SPECIAL((*layer).portamento))
+ {
portamento->speed = US_FLOAT(32512.0) * FLOAT_CAST((*seqPlayer).tempo)
- / ((f32)(*layer).delay * (f32) gTempoInternalToExternal
+ / ((f32)(*layer).delay * (f32)gTempoInternalToExternal
* FLOAT_CAST((*layer).portamentoTime));
- } else {
+ }
+ else
+ {
portamento->speed = US_FLOAT(127.0) / FLOAT_CAST((*layer).portamentoTime);
}
portamento->cur = 0.0f;
layer->freqScale = freqScale;
- if (PORTAMENTO_MODE((*layer).portamento) == PORTAMENTO_MODE_5) {
+ if (PORTAMENTO_MODE((*layer).portamento) == PORTAMENTO_MODE_5)
+ {
layer->portamentoTargetNote = cmdSemitone;
}
- } else if (instrument != NULL) {
- sound = cmdSemitone < instrument->normalRangeLo ?
- &instrument->lowNotesSound : cmdSemitone <= instrument->normalRangeHi ?
- &instrument->normalNotesSound : &instrument->highNotesSound;
+ }
+ else if (instrument != NULL)
+ {
+ sound = cmdSemitone < instrument->normalRangeLo ? &instrument->lowNotesSound : cmdSemitone <= instrument->normalRangeHi ? &instrument->normalNotesSound : &instrument->highNotesSound;
sameSound = (sound == (*layer).sound);
layer->sound = sound;
layer->freqScale = gNoteFrequencies[cmdSemitone] * (*sound).tuning;
- } else {
+ }
+ else
+ {
layer->sound = NULL;
layer->freqScale = gNoteFrequencies[cmdSemitone];
}
@@ -471,30 +532,41 @@ l13cc:
}
}
- if (layer->stopSomething == TRUE) {
- if (layer->note != NULL || layer->continuousNotes) {
+ if (layer->stopSomething == TRUE)
+ {
+ if (layer->note != NULL || layer->continuousNotes)
+ {
seq_channel_layer_note_decay(layer);
}
return;
}
cmdSemitone = FALSE;
- if (!layer->continuousNotes) {
+ if (!layer->continuousNotes)
+ {
cmdSemitone = TRUE;
- } else if (layer->note == NULL || layer->status == SOUND_LOAD_STATUS_NOT_LOADED) {
+ }
+ else if (layer->note == NULL || layer->status == SOUND_LOAD_STATUS_NOT_LOADED)
+ {
cmdSemitone = TRUE;
- } else if (sameSound == FALSE) {
+ }
+ else if (sameSound == FALSE)
+ {
seq_channel_layer_note_decay(layer);
cmdSemitone = TRUE;
- } else if (layer->sound == NULL) {
+ }
+ else if (layer->sound == NULL)
+ {
init_synthetic_wave(layer->note, layer);
}
- if (cmdSemitone != FALSE) {
+ if (cmdSemitone != FALSE)
+ {
(*layer).note = alloc_note(layer);
}
- if (layer->note != NULL && layer->note->parentLayer == layer) {
+ if (layer->note != NULL && layer->note->parentLayer == layer)
+ {
note_vibrato_init(layer->note);
}
}
diff --git a/src/decomp/audio/data.c b/src/decomp/audio/data.c
index f8495bb..f376fab 100644
--- a/src/decomp/audio/data.c
+++ b/src/decomp/audio/data.c
@@ -10,30 +10,46 @@ extern struct OSMesgQueue OSMesgQueue3;
#ifdef VERSION_EU
struct ReverbSettingsEU sReverbSettings[] = {
- { 0x04, 0x0c, 0x2fff },
- { 0x04, 0x0a, 0x47ff },
- { 0x04, 0x10, 0x2fff },
- { 0x04, 0x0e, 0x3fff },
- { 0x04, 0x0c, 0x4fff },
- { 0x04, 0x0a, 0x37ff }
+ {0x04, 0x0c, 0x2fff},
+ {0x04, 0x0a, 0x47ff},
+ {0x04, 0x10, 0x2fff},
+ {0x04, 0x0e, 0x3fff},
+ {0x04, 0x0c, 0x4fff},
+ {0x04, 0x0a, 0x37ff}
};
struct AudioSessionSettingsEU gAudioSessionPresets[] = {
- { 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[0], 0x7fff, 0x0000, 0x00003a40, 0x00006d00,
- 0x00004400, 0x00002a00 },
- { 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[1], 0x7fff, 0x0000, 0x00003a40, 0x00006d00,
- 0x00004400, 0x00002a00 },
- { 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[2], 0x7fff, 0x0000, 0x00003a40, 0x00006d00,
- 0x00004400, 0x00002a00 },
- { 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[3], 0x7fff, 0x0000, 0x00003a40, 0x00006d00,
- 0x00004400, 0x00002a00 },
- { 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[4], 0x7fff, 0x0000, 0x00003a40, 0x00006d00,
- 0x00004400, 0x00002a00 },
- { 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[0], 0x7fff, 0x0000, 0x00004000, 0x00006e00,
- 0x00003f00, 0x00002a00 },
- { 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[1], 0x7fff, 0x0000, 0x00004100, 0x00006e00,
- 0x00004400, 0x00002a80 },
- { 0x00007d00, 0x01, 0x14, 0x01, 0x00, &sReverbSettings[5], 0x7fff, 0x0000, 0x00003500, 0x00006280,
- 0x00004000, 0x00001b00 }
+ {
+ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[0], 0x7fff, 0x0000, 0x00003a40, 0x00006d00,
+ 0x00004400, 0x00002a00
+ },
+ {
+ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[1], 0x7fff, 0x0000, 0x00003a40, 0x00006d00,
+ 0x00004400, 0x00002a00
+ },
+ {
+ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[2], 0x7fff, 0x0000, 0x00003a40, 0x00006d00,
+ 0x00004400, 0x00002a00
+ },
+ {
+ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[3], 0x7fff, 0x0000, 0x00003a40, 0x00006d00,
+ 0x00004400, 0x00002a00
+ },
+ {
+ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[4], 0x7fff, 0x0000, 0x00003a40, 0x00006d00,
+ 0x00004400, 0x00002a00
+ },
+ {
+ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[0], 0x7fff, 0x0000, 0x00004000, 0x00006e00,
+ 0x00003f00, 0x00002a00
+ },
+ {
+ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[1], 0x7fff, 0x0000, 0x00004100, 0x00006e00,
+ 0x00004400, 0x00002a80
+ },
+ {
+ 0x00007d00, 0x01, 0x14, 0x01, 0x00, &sReverbSettings[5], 0x7fff, 0x0000, 0x00003500, 0x00006280,
+ 0x00004000, 0x00001b00
+ }
};
#endif
@@ -51,7 +67,7 @@ struct AudioSessionSettingsEU gAudioSessionPresets[] = {
#if defined(VERSION_JP) || defined(VERSION_US)
struct AudioSessionSettings gAudioSessionPresets[18] = {
#ifdef VERSION_JP
- { 32000, 16, 1, 0x0800, 0x2FFF, 0x7FFF, 0x3900, 0x6000, 0x4400, 0x2A00 },
+{ 32000, 16, 1, 0x0800, 0x2FFF, 0x7FFF, 0x3900, 0x6000, 0x4400, 0x2A00 },
{ 32000, 16, 1, 0x0A00, 0x47FF, 0x7FFF, 0x3900, 0x6000, 0x4400, 0x2A00 },
{ 32000, 16, 1, 0x1000, 0x2FFF, 0x7FFF, 0x3900, 0x6000, 0x4400, 0x2A00 },
{ 32000, 16, 1, 0x0E00, 0x3FFF, 0x7FFF, 0x3900, 0x6000, 0x4400, 0x2A00 },
@@ -60,7 +76,7 @@ struct AudioSessionSettings gAudioSessionPresets[18] = {
{ 32000, 16, 1, 0x0A00, 0x47FF, 0x7FFF, 0x3F00, 0x6200, 0x4400, 0x2A80 },
{ 32000, 20, 1, 0x0800, 0x37FF, 0x7FFF, 0x3300, 0x5500, 0x4000, 0x1B00 },
#else
- { 32000, 16, 1, 0x0C00, 0x2FFF, 0x7FFF, 0x3A00, 0x6D00, 0x4400, 0x2A00 },
+{ 32000, 16, 1, 0x0C00, 0x2FFF, 0x7FFF, 0x3A00, 0x6D00, 0x4400, 0x2A00 },
{ 32000, 16, 1, 0x0A00, 0x47FF, 0x7FFF, 0x3A00, 0x6D00, 0x4400, 0x2A00 },
{ 32000, 16, 1, 0x1000, 0x2FFF, 0x7FFF, 0x3A00, 0x6D00, 0x4400, 0x2A00 },
{ 32000, 16, 1, 0x0E00, 0x3FFF, 0x7FFF, 0x3A00, 0x6D00, 0x4400, 0x2A00 },
@@ -69,7 +85,7 @@ struct AudioSessionSettings gAudioSessionPresets[18] = {
{ 32000, 16, 1, 0x0A00, 0x47FF, 0x7FFF, 0x4100, 0x6E00, 0x4400, 0x2A80 },
{ 32000, 20, 1, 0x0800, 0x37FF, 0x7FFF, 0x34C0, 0x6280, 0x4000, 0x1B00 },
#endif
- { 27000, 16, 1, 0x0800, 0x2FFF, 0x7FFF, 0x2500, 0x5500, 0x7400, 0x2400 },
+{ 27000, 16, 1, 0x0800, 0x2FFF, 0x7FFF, 0x2500, 0x5500, 0x7400, 0x2400 },
{ 27000, 16, 1, 0x0800, 0x3FFF, 0x7FFF, 0x2500, 0x5500, 0x7400, 0x2400 },
{ 27000, 16, 1, 0x1000, 0x2FFF, 0x7FFF, 0x2500, 0x5500, 0x7400, 0x2400 },
{ 27000, 16, 1, 0x1000, 0x3FFF, 0x7FFF, 0x2500, 0x5500, 0x7400, 0x2400 },
@@ -85,15 +101,15 @@ struct AudioSessionSettings gAudioSessionPresets[18] = {
#if defined(VERSION_JP) || defined(VERSION_US)
u16 gAudioCosineTable[128] = {
0x7FFF, 32764, 32757, 32744, 32727, 32704, 32677, 32644, 32607, 32564, 32517, 32464, 32407,
- 32344, 32277, 32205, 32127, 32045, 31958, 31866, 31770, 31668, 31561, 31450, 31334, 31213,
- 31087, 30957, 30822, 30682, 30537, 30388, 30234, 30075, 29912, 29744, 29572, 29395, 29214,
- 29028, 28838, 28643, 28444, 28241, 28033, 27821, 27605, 27385, 27160, 26931, 26698, 26461,
- 26220, 25975, 25726, 25473, 25216, 24956, 24691, 24423, 24151, 23875, 23596, 23313, 23026,
- 22736, 22442, 22145, 21845, 21541, 21234, 20924, 20610, 20294, 19974, 19651, 19325, 18997,
- 18665, 18331, 17993, 17653, 17310, 16965, 16617, 16266, 15913, 15558, 15200, 14840, 14477,
- 14113, 13746, 13377, 13006, 12633, 12258, 11881, 11503, 11122, 10740, 10357, 9971, 9584,
- 9196, 8806, 8415, 8023, 7630, 7235, 6839, 6442, 6044, 5646, 5246, 4845, 4444,
- 4042, 3640, 3237, 2833, 2429, 2025, 1620, 1216, 810, 405, 0,
+ 32344, 32277, 32205, 32127, 32045, 31958, 31866, 31770, 31668, 31561, 31450, 31334, 31213,
+ 31087, 30957, 30822, 30682, 30537, 30388, 30234, 30075, 29912, 29744, 29572, 29395, 29214,
+ 29028, 28838, 28643, 28444, 28241, 28033, 27821, 27605, 27385, 27160, 26931, 26698, 26461,
+ 26220, 25975, 25726, 25473, 25216, 24956, 24691, 24423, 24151, 23875, 23596, 23313, 23026,
+ 22736, 22442, 22145, 21845, 21541, 21234, 20924, 20610, 20294, 19974, 19651, 19325, 18997,
+ 18665, 18331, 17993, 17653, 17310, 16965, 16617, 16266, 15913, 15558, 15200, 14840, 14477,
+ 14113, 13746, 13377, 13006, 12633, 12258, 11881, 11503, 11122, 10740, 10357, 9971, 9584,
+ 9196, 8806, 8415, 8023, 7630, 7235, 6839, 6442, 6044, 5646, 5246, 4845, 4444,
+ 4042, 3640, 3237, 2833, 2429, 2025, 1620, 1216, 810, 405, 0,
};
#endif
@@ -106,8 +122,8 @@ f32 gPitchBendFrequencyScale[256] = {
0.5f,
#else
f32 gPitchBendFrequencyScale[255] = {
-#endif
- 0.5f, 0.502736f, 0.505488f, 0.508254f, 0.511036f, 0.513833f, 0.516645f, 0.519472f, 0.522315f,
+ #endif
+ 0.5f, 0.502736f, 0.505488f, 0.508254f, 0.511036f, 0.513833f, 0.516645f, 0.519472f, 0.522315f,
0.525174f, 0.528048f, 0.530938f, 0.533843f, 0.536765f, 0.539702f, 0.542656f, 0.545626f, 0.548612f,
0.551614f, 0.554633f, 0.557669f, 0.560721f, 0.563789f, 0.566875f, 0.569977f, 0.573097f, 0.576233f,
0.579387f, 0.582558f, 0.585746f, 0.588951f, 0.592175f, 0.595415f, 0.598674f, 0.601950f, 0.605245f,
@@ -121,7 +137,7 @@ f32 gPitchBendFrequencyScale[255] = {
0.858284f, 0.862982f, 0.867704f, 0.872453f, 0.877228f, 0.882029f, 0.886856f, 0.891709f, 0.896590f,
0.901496f, 0.906430f, 0.911391f, 0.916379f, 0.921394f, 0.926436f, 0.931507f, 0.936604f, 0.941730f,
0.946884f, 0.952066f, 0.957277f, 0.962516f, 0.967783f, 0.973080f, 0.978405f, 0.983760f, 0.989144f,
- 0.994557f, 1.0f, 1.005473f, 1.010975f, 1.016508f, 1.022071f, 1.027665f, 1.033289f, 1.038944f,
+ 0.994557f, 1.0f, 1.005473f, 1.010975f, 1.016508f, 1.022071f, 1.027665f, 1.033289f, 1.038944f,
1.044630f, 1.050347f, 1.056095f, 1.061875f, 1.067687f, 1.073530f, 1.079405f, 1.085312f, 1.091252f,
1.097224f, 1.103229f, 1.109267f, 1.115337f, 1.121441f, 1.127579f, 1.133750f, 1.139955f, 1.146193f,
1.152466f, 1.158773f, 1.165115f, 1.171491f, 1.177903f, 1.184349f, 1.190831f, 1.197348f, 1.203901f,
@@ -171,30 +187,30 @@ u8 gDefaultShortNoteDurationTable[16] = {
#if defined(VERSION_JP) || defined(VERSION_US)
// gVibratoCurve[k] = k*8
-s8 gVibratoCurve[16] = { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120 };
+s8 gVibratoCurve[16] = {0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120};
#endif
struct AdsrEnvelope gDefaultEnvelope[] = {
- { BSWAP16(4), BSWAP16(32000) }, // go from 0 to 32000 over the course of 16ms
- { BSWAP16(1000), BSWAP16(32000) }, // stay there for 4.16 seconds
- { BSWAP16(ADSR_HANG), 0 } // then continue staying there
+ {BSWAP16(4), BSWAP16(32000)}, // go from 0 to 32000 over the course of 16ms
+ {BSWAP16(1000), BSWAP16(32000)}, // stay there for 4.16 seconds
+ {BSWAP16(ADSR_HANG), 0} // then continue staying there
};
#endif
#ifdef VERSION_EU
-struct NoteSubEu gZeroNoteSub = { 0 };
-struct NoteSubEu gDefaultNoteSub = { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, { NULL } };
+struct NoteSubEu gZeroNoteSub = {0};
+struct NoteSubEu gDefaultNoteSub = {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {NULL}};
#endif
#if defined(VERSION_EU) || defined(VERSION_SH)
s16 sSawtoothWaves[256] = {
- 0, 1023, 2047, 3071, 4095, 5119, 6143, 7167, 8191, 9215, 10239,
- 11263, 0x2FFF, 13311, 0x37FF, 15359, 0x3FFF, 17407, 0x47FF, 19455, 0x4FFF, 21503,
- 22527, 23551, 24575, 25599, 26623, 27647, 28671, 29695, 30719, 31743, -0x7FFF,
- -31743, -30719, -29695, -28671, -27647, -26623, -25599, -24575, -23551, -22527, -21503,
+ 0, 1023, 2047, 3071, 4095, 5119, 6143, 7167, 8191, 9215, 10239,
+ 11263, 0x2FFF, 13311, 0x37FF, 15359, 0x3FFF, 17407, 0x47FF, 19455, 0x4FFF, 21503,
+ 22527, 23551, 24575, 25599, 26623, 27647, 28671, 29695, 30719, 31743, -0x7FFF,
+ -31743, -30719, -29695, -28671, -27647, -26623, -25599, -24575, -23551, -22527, -21503,
-0x4FFF, -19455, -0x47FF, -17407, -0x3FFF, -15359, -0x37FF, -13311, -0x2FFF, -11263, -10239,
- -9215, -8191, -7167, -6143, -5119, -4095, -3071, -2047, -1023,
- 0, 0x7FF, 0xFFF, 0x17FF, 0x1FFF, 0x27FF, 0x2FFF, 0x37FF, 0x3FFF, 0x47FF, 0x4FFF,
+ -9215, -8191, -7167, -6143, -5119, -4095, -3071, -2047, -1023,
+ 0, 0x7FF, 0xFFF, 0x17FF, 0x1FFF, 0x27FF, 0x2FFF, 0x37FF, 0x3FFF, 0x47FF, 0x4FFF,
0x57FF, 0x5FFF, 0x67FF, 0x6FFF, 0x77FF, 0x8001, 0x8801, 0x9001, 0x9801, 0xa001, 0xa801,
0xb001, 0xb801, 0xc001, 0xc801, 0xd001, 0xd801, 0xe001, 0xe801, 0xf001, 0xf801, 0x0000,
0x07ff, 0x0fff, 0x17ff, 0x1fff, 0x27ff, 0x2fff, 0x37ff, 0x3fff, 0x47ff, 0x4fff, 0x57ff,
@@ -337,52 +353,52 @@ s16 gEuUnknownWave7[256] = {
0x0000, 0x8d2e, 0x4e20, 0xe14e, 0x0000, 0x1eb2, 0xb1e0, 0x72d2, 0x0000, 0x8d2e, 0x4e20, 0xe14e,
0x0000, 0x1eb2, 0xb1e0, 0x72d2,
};
-s16 *gWaveSamples[6] = { sSawtoothWaves, sTriangleWaves, sSineWaves, sSquareWaves, sEuUnknownWave6, gEuUnknownWave7 };
+s16 *gWaveSamples[6] = {sSawtoothWaves, sTriangleWaves, sSineWaves, sSquareWaves, sEuUnknownWave6, gEuUnknownWave7};
#else
// !VERSION_EU
s16 sSineWave[0x40] = {
- 0, 3211, 6392, 9511, 12539, 15446, 18204, 20787, 23169, 25329, 27244,
- 28897, 30272, 31356, 32137, 32609, 0x7FFF, 32609, 32137, 31356, 30272, 28897,
- 27244, 25329, 23169, 20787, 18204, 15446, 12539, 9511, 6392, 3211, 0,
- -3211, -6392, -9511, -12539, -15446, -18204, -20787, -23169, -25329, -27244, -28897,
+ 0, 3211, 6392, 9511, 12539, 15446, 18204, 20787, 23169, 25329, 27244,
+ 28897, 30272, 31356, 32137, 32609, 0x7FFF, 32609, 32137, 31356, 30272, 28897,
+ 27244, 25329, 23169, 20787, 18204, 15446, 12539, 9511, 6392, 3211, 0,
+ -3211, -6392, -9511, -12539, -15446, -18204, -20787, -23169, -25329, -27244, -28897,
-30272, -31356, -32137, -32609, -0x7FFF, -32609, -32137, -31356, -30272, -28897, -27244,
- -25329, -23169, -20787, -18204, -15446, -12539, -9511, -6392, -3211,
+ -25329, -23169, -20787, -18204, -15446, -12539, -9511, -6392, -3211,
};
s16 sSquareWave[0x40] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF,
- 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF,
+ 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF,
-0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF,
};
s16 sTriangleWave[0x40] = {
- 0, 0x7FF, 0xFFF, 0x17FF, 0x1FFF, 0x27FF, 0x2FFF, 0x37FF, 0x3FFF, 0x47FF, 0x4FFF,
- 0x57FF, 0x5FFF, 0x67FF, 0x6FFF, 0x77FF, 0x7FFF, 0x77FF, 0x6FFF, 0x67FF, 0x5FFF, 0x57FF,
- 0x4FFF, 0x47FF, 0x3FFF, 0x37FF, 0x2FFF, 0x27FF, 0x1FFF, 0x17FF, 0xFFF, 0x7FF, 0,
- -0x7FF, -0xFFF, -0x17FF, -0x1FFF, -10239, -0x2FFF, -0x37FF, -0x3FFF, -0x47FF, -0x4FFF, -22527,
- -24575, -26623, -28671, -30719, -0x7FFF, -30719, -28671, -26623, -24575, -22527, -0x4FFF,
- -0x47FF, -0x3FFF, -0x37FF, -0x2FFF, -0x27FF, -0x1FFF, -0x17FF, -0xFFF, -0x7FF,
+ 0, 0x7FF, 0xFFF, 0x17FF, 0x1FFF, 0x27FF, 0x2FFF, 0x37FF, 0x3FFF, 0x47FF, 0x4FFF,
+ 0x57FF, 0x5FFF, 0x67FF, 0x6FFF, 0x77FF, 0x7FFF, 0x77FF, 0x6FFF, 0x67FF, 0x5FFF, 0x57FF,
+ 0x4FFF, 0x47FF, 0x3FFF, 0x37FF, 0x2FFF, 0x27FF, 0x1FFF, 0x17FF, 0xFFF, 0x7FF, 0,
+ -0x7FF, -0xFFF, -0x17FF, -0x1FFF, -10239, -0x2FFF, -0x37FF, -0x3FFF, -0x47FF, -0x4FFF, -22527,
+ -24575, -26623, -28671, -30719, -0x7FFF, -30719, -28671, -26623, -24575, -22527, -0x4FFF,
+ -0x47FF, -0x3FFF, -0x37FF, -0x2FFF, -0x27FF, -0x1FFF, -0x17FF, -0xFFF, -0x7FF,
};
s16 sSawtoothWave[0x40] = {
- 0, 1023, 2047, 3071, 4095, 5119, 6143, 7167, 8191, 9215, 10239,
- 11263, 0x2FFF, 13311, 0x37FF, 15359, 0x3FFF, 17407, 0x47FF, 19455, 0x4FFF, 21503,
- 22527, 23551, 24575, 25599, 26623, 27647, 28671, 29695, 30719, 31743, -0x7FFF,
- -31743, -30719, -29695, -28671, -27647, -26623, -25599, -24575, -23551, -22527, -21503,
+ 0, 1023, 2047, 3071, 4095, 5119, 6143, 7167, 8191, 9215, 10239,
+ 11263, 0x2FFF, 13311, 0x37FF, 15359, 0x3FFF, 17407, 0x47FF, 19455, 0x4FFF, 21503,
+ 22527, 23551, 24575, 25599, 26623, 27647, 28671, 29695, 30719, 31743, -0x7FFF,
+ -31743, -30719, -29695, -28671, -27647, -26623, -25599, -24575, -23551, -22527, -21503,
-0x4FFF, -19455, -0x47FF, -17407, -0x3FFF, -15359, -0x37FF, -13311, -0x2FFF, -11263, -10239,
- -9215, -8191, -7167, -6143, -5119, -4095, -3071, -2047, -1023,
+ -9215, -8191, -7167, -6143, -5119, -4095, -3071, -2047, -1023,
};
-s16 *gWaveSamples[4] = { sSawtoothWave, sTriangleWave, sSineWave, sSquareWave };
+s16 *gWaveSamples[4] = {sSawtoothWave, sTriangleWave, sSineWave, sSquareWave};
#endif
#ifdef VERSION_SH
s32 unk_sh_data_0[2] = {0, 0};
f32 gPitchBendFrequencyScale[256] = {
- 0.5f, 0.5f, 0.502736f, 0.505488f, 0.508254f, 0.511036f, 0.513833f, 0.516645f, 0.519472f,
+ 0.5f, 0.5f, 0.502736f, 0.505488f, 0.508254f, 0.511036f, 0.513833f, 0.516645f, 0.519472f,
0.522315f, 0.525174f, 0.528048f, 0.530938f, 0.533843f, 0.536765f, 0.539702f, 0.542656f, 0.545626f,
0.548612f, 0.551614f, 0.554633f, 0.557669f, 0.560721f, 0.563789f, 0.566875f, 0.569977f, 0.573097f,
0.576233f, 0.579387f, 0.582558f, 0.585746f, 0.588951f, 0.592175f, 0.595415f, 0.598674f, 0.601950f,
@@ -396,7 +412,7 @@ f32 gPitchBendFrequencyScale[256] = {
0.853613f, 0.858284f, 0.862982f, 0.867704f, 0.872453f, 0.877228f, 0.882029f, 0.886856f, 0.891709f,
0.896590f, 0.901496f, 0.906430f, 0.911391f, 0.916379f, 0.921394f, 0.926436f, 0.931507f, 0.936604f,
0.941730f, 0.946884f, 0.952066f, 0.957277f, 0.962516f, 0.967783f, 0.973080f, 0.978405f, 0.983760f,
- 0.989144f, 0.994557f, 1.0f, 1.005473f, 1.010975f, 1.016508f, 1.022071f, 1.027665f, 1.033289f,
+ 0.989144f, 0.994557f, 1.0f, 1.005473f, 1.010975f, 1.016508f, 1.022071f, 1.027665f, 1.033289f,
1.038944f, 1.044630f, 1.050347f, 1.056095f, 1.061875f, 1.067687f, 1.073530f, 1.079405f, 1.085312f,
1.091252f, 1.097224f, 1.103229f, 1.109267f, 1.115337f, 1.121441f, 1.127579f, 1.133750f, 1.139955f,
1.146193f, 1.152466f, 1.158773f, 1.165115f, 1.171491f, 1.177903f, 1.184349f, 1.190831f, 1.197348f,
@@ -416,38 +432,38 @@ f32 gPitchBendFrequencyScale[256] = {
#ifdef VERSION_SH
f32 unk_sh_data_1[] = {
- 0.890899f, 0.890899f, 0.89171f, 0.892521f, 0.893333f, 0.894146f, 0.89496f, 0.895774f,
- 0.89659f, 0.897406f, 0.898222f, 0.89904f, 0.899858f, 0.900677f, 0.901496f, 0.902317f,
- 0.903138f, 0.90396f, 0.904783f, 0.905606f, 0.90643f, 0.907255f, 0.908081f, 0.908907f,
- 0.909734f, 0.910562f, 0.911391f, 0.91222f, 0.91305f, 0.913881f, 0.914713f, 0.915545f,
- 0.916379f, 0.917213f, 0.918047f, 0.918883f, 0.919719f, 0.920556f, 0.921394f, 0.922232f,
- 0.923072f, 0.923912f, 0.924752f, 0.925594f, 0.926436f, 0.927279f, 0.928123f, 0.928968f,
- 0.929813f, 0.93066f, 0.931507f, 0.932354f, 0.933203f, 0.934052f, 0.934902f, 0.935753f,
- 0.936604f, 0.937457f, 0.93831f, 0.939164f, 0.940019f, 0.940874f, 0.94173f, 0.942587f,
- 0.943445f, 0.944304f, 0.945163f, 0.946023f, 0.946884f, 0.947746f, 0.948608f, 0.949472f,
- 0.950336f, 0.951201f, 0.952066f, 0.952933f, 0.9538f, 0.954668f, 0.955537f, 0.956406f,
- 0.957277f, 0.958148f, 0.95902f, 0.959893f, 0.960766f, 0.961641f, 0.962516f, 0.963392f,
- 0.964268f, 0.965146f, 0.966024f, 0.966903f, 0.967783f, 0.968664f, 0.969546f, 0.970428f,
- 0.971311f, 0.972195f, 0.97308f, 0.973965f, 0.974852f, 0.975739f, 0.976627f, 0.977516f,
- 0.978405f, 0.979296f, 0.980187f, 0.981079f, 0.981972f, 0.982865f, 0.98376f, 0.984655f,
- 0.985551f, 0.986448f, 0.987346f, 0.988244f, 0.989144f, 0.990044f, 0.990945f, 0.991847f,
- 0.992749f, 0.993653f, 0.994557f, 0.995462f, 0.996368f, 0.997275f, 0.998182f, 0.999091f,
- 1.0f, 1.00091f, 1.001821f, 1.002733f, 1.003645f, 1.004559f, 1.005473f, 1.006388f,
- 1.007304f, 1.00822f, 1.009138f, 1.010056f, 1.010975f, 1.011896f, 1.012816f, 1.013738f,
- 1.014661f, 1.015584f, 1.016508f, 1.017433f, 1.018359f, 1.019286f, 1.020214f, 1.021142f,
- 1.022071f, 1.023002f, 1.023933f, 1.024864f, 1.025797f, 1.026731f, 1.027665f, 1.0286f,
- 1.029536f, 1.030473f, 1.031411f, 1.03235f, 1.033289f, 1.03423f, 1.035171f, 1.036113f,
- 1.037056f, 1.038f, 1.038944f, 1.03989f, 1.040836f, 1.041783f, 1.042731f, 1.04368f,
- 1.04463f, 1.045581f, 1.046532f, 1.047485f, 1.048438f, 1.049392f, 1.050347f, 1.051303f,
- 1.05226f, 1.053217f, 1.054176f, 1.055135f, 1.056095f, 1.057056f, 1.058018f, 1.058981f,
- 1.059945f, 1.06091f, 1.061875f, 1.062842f, 1.063809f, 1.064777f, 1.065746f, 1.066716f,
- 1.067687f, 1.068658f, 1.069631f, 1.070604f, 1.071578f, 1.072554f, 1.07353f, 1.074507f,
- 1.075485f, 1.076463f, 1.077443f, 1.078424f, 1.079405f, 1.080387f, 1.08137f, 1.082355f,
- 1.08334f, 1.084325f, 1.085312f, 1.0863f, 1.087289f, 1.088278f, 1.089268f, 1.09026f,
- 1.091252f, 1.092245f, 1.093239f, 1.094234f, 1.09523f, 1.096226f, 1.097224f, 1.098223f,
- 1.099222f, 1.100222f, 1.101224f, 1.102226f, 1.103229f, 1.104233f, 1.105238f, 1.106244f,
- 1.10725f, 1.108258f, 1.109267f, 1.110276f, 1.111287f, 1.112298f, 1.11331f, 1.114323f,
- 1.115337f, 1.116352f, 1.117368f, 1.118385f, 1.119403f, 1.120422f, 1.121441f, 1.122462f,
+ 0.890899f, 0.890899f, 0.89171f, 0.892521f, 0.893333f, 0.894146f, 0.89496f, 0.895774f,
+ 0.89659f, 0.897406f, 0.898222f, 0.89904f, 0.899858f, 0.900677f, 0.901496f, 0.902317f,
+ 0.903138f, 0.90396f, 0.904783f, 0.905606f, 0.90643f, 0.907255f, 0.908081f, 0.908907f,
+ 0.909734f, 0.910562f, 0.911391f, 0.91222f, 0.91305f, 0.913881f, 0.914713f, 0.915545f,
+ 0.916379f, 0.917213f, 0.918047f, 0.918883f, 0.919719f, 0.920556f, 0.921394f, 0.922232f,
+ 0.923072f, 0.923912f, 0.924752f, 0.925594f, 0.926436f, 0.927279f, 0.928123f, 0.928968f,
+ 0.929813f, 0.93066f, 0.931507f, 0.932354f, 0.933203f, 0.934052f, 0.934902f, 0.935753f,
+ 0.936604f, 0.937457f, 0.93831f, 0.939164f, 0.940019f, 0.940874f, 0.94173f, 0.942587f,
+ 0.943445f, 0.944304f, 0.945163f, 0.946023f, 0.946884f, 0.947746f, 0.948608f, 0.949472f,
+ 0.950336f, 0.951201f, 0.952066f, 0.952933f, 0.9538f, 0.954668f, 0.955537f, 0.956406f,
+ 0.957277f, 0.958148f, 0.95902f, 0.959893f, 0.960766f, 0.961641f, 0.962516f, 0.963392f,
+ 0.964268f, 0.965146f, 0.966024f, 0.966903f, 0.967783f, 0.968664f, 0.969546f, 0.970428f,
+ 0.971311f, 0.972195f, 0.97308f, 0.973965f, 0.974852f, 0.975739f, 0.976627f, 0.977516f,
+ 0.978405f, 0.979296f, 0.980187f, 0.981079f, 0.981972f, 0.982865f, 0.98376f, 0.984655f,
+ 0.985551f, 0.986448f, 0.987346f, 0.988244f, 0.989144f, 0.990044f, 0.990945f, 0.991847f,
+ 0.992749f, 0.993653f, 0.994557f, 0.995462f, 0.996368f, 0.997275f, 0.998182f, 0.999091f,
+ 1.0f, 1.00091f, 1.001821f, 1.002733f, 1.003645f, 1.004559f, 1.005473f, 1.006388f,
+ 1.007304f, 1.00822f, 1.009138f, 1.010056f, 1.010975f, 1.011896f, 1.012816f, 1.013738f,
+ 1.014661f, 1.015584f, 1.016508f, 1.017433f, 1.018359f, 1.019286f, 1.020214f, 1.021142f,
+ 1.022071f, 1.023002f, 1.023933f, 1.024864f, 1.025797f, 1.026731f, 1.027665f, 1.0286f,
+ 1.029536f, 1.030473f, 1.031411f, 1.03235f, 1.033289f, 1.03423f, 1.035171f, 1.036113f,
+ 1.037056f, 1.038f, 1.038944f, 1.03989f, 1.040836f, 1.041783f, 1.042731f, 1.04368f,
+ 1.04463f, 1.045581f, 1.046532f, 1.047485f, 1.048438f, 1.049392f, 1.050347f, 1.051303f,
+ 1.05226f, 1.053217f, 1.054176f, 1.055135f, 1.056095f, 1.057056f, 1.058018f, 1.058981f,
+ 1.059945f, 1.06091f, 1.061875f, 1.062842f, 1.063809f, 1.064777f, 1.065746f, 1.066716f,
+ 1.067687f, 1.068658f, 1.069631f, 1.070604f, 1.071578f, 1.072554f, 1.07353f, 1.074507f,
+ 1.075485f, 1.076463f, 1.077443f, 1.078424f, 1.079405f, 1.080387f, 1.08137f, 1.082355f,
+ 1.08334f, 1.084325f, 1.085312f, 1.0863f, 1.087289f, 1.088278f, 1.089268f, 1.09026f,
+ 1.091252f, 1.092245f, 1.093239f, 1.094234f, 1.09523f, 1.096226f, 1.097224f, 1.098223f,
+ 1.099222f, 1.100222f, 1.101224f, 1.102226f, 1.103229f, 1.104233f, 1.105238f, 1.106244f,
+ 1.10725f, 1.108258f, 1.109267f, 1.110276f, 1.111287f, 1.112298f, 1.11331f, 1.114323f,
+ 1.115337f, 1.116352f, 1.117368f, 1.118385f, 1.119403f, 1.120422f, 1.121441f, 1.122462f,
};
// Shindou moved these variables down here. :/
@@ -476,43 +492,43 @@ u8 gDefaultShortNoteDurationTable[16] = {
};
struct AdsrEnvelope gDefaultEnvelope[] = {
- { BSWAP16(4), BSWAP16(32000) }, // go from 0 to 32000 over the course of 16ms
- { BSWAP16(1000), BSWAP16(32000) }, // stay there for 4.16 seconds
- { BSWAP16(ADSR_HANG), 0 } // then continue staying there
+ {BSWAP16(4), BSWAP16(32000)}, // go from 0 to 32000 over the course of 16ms
+ {BSWAP16(1000), BSWAP16(32000)}, // stay there for 4.16 seconds
+ {BSWAP16(ADSR_HANG), 0} // then continue staying there
};
-u8 unk_sh_data2[4] = { 0, 0, 0, 0 };
+u8 unk_sh_data2[4] = {0, 0, 0, 0};
-struct NoteSubEu gZeroNoteSub = { 0 };
+struct NoteSubEu gZeroNoteSub = {0};
struct NoteSubEu gDefaultNoteSub = {
- 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, { NULL },
+ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {NULL},
#ifdef VERSION_SH
- 0
+0
#endif
};
u16 gHeadsetPanQuantization[0x40] = {
-0x3C, 0x3A, 0x38, 0x36, 0x34, 0x32, 0x30, 0x2E,
-0x2C, 0x2A, 0x28, 0x26, 0x24, 0x22, 0x20, 0x1E,
-0x1C, 0x1A, 0x18, 0x16, 0x14, 0x12, 0x10, 0x0E,
-0x0C, 0x0A, 0x08, 0x06, 0x04, 0x02,
-0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0x3C, 0x3A, 0x38, 0x36, 0x34, 0x32, 0x30, 0x2E,
+ 0x2C, 0x2A, 0x28, 0x26, 0x24, 0x22, 0x20, 0x1E,
+ 0x1C, 0x1A, 0x18, 0x16, 0x14, 0x12, 0x10, 0x0E,
+ 0x0C, 0x0A, 0x08, 0x06, 0x04, 0x02,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
#endif
#ifdef VERSION_EU
-u8 euUnknownData_8030194c[4] = { 0x40, 0x20, 0x10, 0x08 };
+u8 euUnknownData_8030194c[4] = {0x40, 0x20, 0x10, 0x08};
u16 gHeadsetPanQuantization[0x10] = {
0x40, 0x40, 0x30, 0x30, 0x20, 0x20, 0x10, 0, 0, 0,
};
#elif !defined(VERSION_SH)
-u16 gHeadsetPanQuantization[10] = { 0x40, 0x30, 0x20, 0x10, 0, 0, 0, 0, 0, 0 };
+u16 gHeadsetPanQuantization[10] = {0x40, 0x30, 0x20, 0x10, 0, 0, 0, 0, 0, 0};
#endif
#if defined(VERSION_EU) || defined(VERSION_SH)
s16 euUnknownData_80301950[64] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 500, 0, 0, 0, 0, 0, 0, 0, 500, 0, 0, 0, 0, 0, 0, 0, 500, 0, 0, 0, 0, 0, 0, 0, 500, 0, 0, 0, 0,
};
#endif
@@ -522,21 +538,21 @@ s16 euUnknownData_80301950[64] = {
// f(1/2 * 127) = 1/sqrt(2)
// f(2/2 * 127) = 0
f32 gHeadsetPanVolume[128] = {
- 1.0f, 0.995386f, 0.990772f, 0.986157f, 0.981543f, 0.976929f, 0.972315f, 0.967701f, 0.963087f,
- 0.958472f, 0.953858f, 0.949244f, 0.94463f, 0.940016f, 0.935402f, 0.930787f, 0.926173f, 0.921559f,
- 0.916945f, 0.912331f, 0.907717f, 0.903102f, 0.898488f, 0.893874f, 0.88926f, 0.884646f, 0.880031f,
+ 1.0f, 0.995386f, 0.990772f, 0.986157f, 0.981543f, 0.976929f, 0.972315f, 0.967701f, 0.963087f,
+ 0.958472f, 0.953858f, 0.949244f, 0.94463f, 0.940016f, 0.935402f, 0.930787f, 0.926173f, 0.921559f,
+ 0.916945f, 0.912331f, 0.907717f, 0.903102f, 0.898488f, 0.893874f, 0.88926f, 0.884646f, 0.880031f,
0.875417f, 0.870803f, 0.866189f, 0.861575f, 0.856961f, 0.852346f, 0.847732f, 0.843118f, 0.838504f,
- 0.83389f, 0.829276f, 0.824661f, 0.820047f, 0.815433f, 0.810819f, 0.806205f, 0.801591f, 0.796976f,
- 0.792362f, 0.787748f, 0.783134f, 0.77852f, 0.773906f, 0.769291f, 0.764677f, 0.760063f, 0.755449f,
- 0.750835f, 0.74622f, 0.741606f, 0.736992f, 0.732378f, 0.727764f, 0.72315f, 0.718535f, 0.713921f,
- 0.709307f, 0.70537f, 0.70211f, 0.69885f, 0.695591f, 0.692331f, 0.689071f, 0.685811f, 0.682551f,
+ 0.83389f, 0.829276f, 0.824661f, 0.820047f, 0.815433f, 0.810819f, 0.806205f, 0.801591f, 0.796976f,
+ 0.792362f, 0.787748f, 0.783134f, 0.77852f, 0.773906f, 0.769291f, 0.764677f, 0.760063f, 0.755449f,
+ 0.750835f, 0.74622f, 0.741606f, 0.736992f, 0.732378f, 0.727764f, 0.72315f, 0.718535f, 0.713921f,
+ 0.709307f, 0.70537f, 0.70211f, 0.69885f, 0.695591f, 0.692331f, 0.689071f, 0.685811f, 0.682551f,
0.679291f, 0.676031f, 0.672772f, 0.669512f, 0.666252f, 0.662992f, 0.659732f, 0.656472f, 0.653213f,
0.649953f, 0.646693f, 0.643433f, 0.640173f, 0.636913f, 0.633654f, 0.630394f, 0.627134f, 0.623874f,
0.620614f, 0.617354f, 0.614094f, 0.610835f, 0.607575f, 0.604315f, 0.601055f, 0.597795f, 0.594535f,
0.591276f, 0.588016f, 0.584756f, 0.581496f, 0.578236f, 0.574976f, 0.571717f, 0.568457f, 0.565197f,
0.561937f, 0.558677f, 0.555417f, 0.552157f, 0.548898f, 0.545638f, 0.542378f, 0.539118f, 0.535858f,
- 0.532598f, 0.529339f, 0.526079f, 0.522819f, 0.519559f, 0.516299f, 0.513039f, 0.50978f, 0.50652f,
- 0.50326f, 0.5f
+ 0.532598f, 0.529339f, 0.526079f, 0.522819f, 0.519559f, 0.516299f, 0.513039f, 0.50978f, 0.50652f,
+ 0.50326f, 0.5f
};
// Linearly interpolated between
@@ -546,165 +562,165 @@ f32 gHeadsetPanVolume[128] = {
// f(3/4 * 127) = 0
// f(4/4 * 127) = 1/sqrt(8)
f32 gStereoPanVolume[128] = {
- 0.707f, 0.716228f, 0.725457f, 0.734685f, 0.743913f, 0.753142f, 0.76237f, 0.771598f, 0.780827f,
- 0.790055f, 0.799283f, 0.808512f, 0.81774f, 0.826968f, 0.836197f, 0.845425f, 0.854654f, 0.863882f,
- 0.87311f, 0.882339f, 0.891567f, 0.900795f, 0.910024f, 0.919252f, 0.92848f, 0.937709f, 0.946937f,
- 0.956165f, 0.965394f, 0.974622f, 0.98385f, 0.993079f, 0.997693f, 0.988465f, 0.979236f, 0.970008f,
+ 0.707f, 0.716228f, 0.725457f, 0.734685f, 0.743913f, 0.753142f, 0.76237f, 0.771598f, 0.780827f,
+ 0.790055f, 0.799283f, 0.808512f, 0.81774f, 0.826968f, 0.836197f, 0.845425f, 0.854654f, 0.863882f,
+ 0.87311f, 0.882339f, 0.891567f, 0.900795f, 0.910024f, 0.919252f, 0.92848f, 0.937709f, 0.946937f,
+ 0.956165f, 0.965394f, 0.974622f, 0.98385f, 0.993079f, 0.997693f, 0.988465f, 0.979236f, 0.970008f,
0.960779f, 0.951551f, 0.942323f, 0.933095f, 0.923866f, 0.914638f, 0.905409f, 0.896181f, 0.886953f,
0.877724f, 0.868496f, 0.859268f, 0.850039f, 0.840811f, 0.831583f, 0.822354f, 0.813126f, 0.803898f,
0.794669f, 0.785441f, 0.776213f, 0.766984f, 0.757756f, 0.748528f, 0.739299f, 0.730071f, 0.720843f,
- 0.711614f, 0.695866f, 0.673598f, 0.651331f, 0.629063f, 0.606795f, 0.584528f, 0.56226f, 0.539992f,
- 0.517724f, 0.495457f, 0.473189f, 0.450921f, 0.428654f, 0.406386f, 0.384118f, 0.36185f, 0.339583f,
- 0.317315f, 0.295047f, 0.27278f, 0.250512f, 0.228244f, 0.205976f, 0.183709f, 0.161441f, 0.139173f,
- 0.116905f, 0.094638f, 0.07237f, 0.050102f, 0.027835f, 0.005567f, 0.00835f, 0.019484f, 0.030618f,
- 0.041752f, 0.052886f, 0.06402f, 0.075154f, 0.086287f, 0.097421f, 0.108555f, 0.119689f, 0.130823f,
- 0.141957f, 0.153091f, 0.164224f, 0.175358f, 0.186492f, 0.197626f, 0.20876f, 0.219894f, 0.231028f,
+ 0.711614f, 0.695866f, 0.673598f, 0.651331f, 0.629063f, 0.606795f, 0.584528f, 0.56226f, 0.539992f,
+ 0.517724f, 0.495457f, 0.473189f, 0.450921f, 0.428654f, 0.406386f, 0.384118f, 0.36185f, 0.339583f,
+ 0.317315f, 0.295047f, 0.27278f, 0.250512f, 0.228244f, 0.205976f, 0.183709f, 0.161441f, 0.139173f,
+ 0.116905f, 0.094638f, 0.07237f, 0.050102f, 0.027835f, 0.005567f, 0.00835f, 0.019484f, 0.030618f,
+ 0.041752f, 0.052886f, 0.06402f, 0.075154f, 0.086287f, 0.097421f, 0.108555f, 0.119689f, 0.130823f,
+ 0.141957f, 0.153091f, 0.164224f, 0.175358f, 0.186492f, 0.197626f, 0.20876f, 0.219894f, 0.231028f,
0.242161f, 0.253295f, 0.264429f, 0.275563f, 0.286697f, 0.297831f, 0.308965f, 0.320098f, 0.331232f,
0.342366f, 0.3535f
};
// gDefaultVolume[k] = cos(pi/2 * k / 127)
f32 gDefaultPanVolume[128] = {
- 1.0f, 0.999924f, 0.999694f, 0.999312f, 0.998776f, 0.998088f, 0.997248f, 0.996254f, 0.995109f,
+ 1.0f, 0.999924f, 0.999694f, 0.999312f, 0.998776f, 0.998088f, 0.997248f, 0.996254f, 0.995109f,
0.993811f, 0.992361f, 0.990759f, 0.989006f, 0.987101f, 0.985045f, 0.982839f, 0.980482f, 0.977976f,
- 0.97532f, 0.972514f, 0.96956f, 0.966457f, 0.963207f, 0.959809f, 0.956265f, 0.952574f, 0.948737f,
- 0.944755f, 0.940629f, 0.936359f, 0.931946f, 0.92739f, 0.922692f, 0.917853f, 0.912873f, 0.907754f,
+ 0.97532f, 0.972514f, 0.96956f, 0.966457f, 0.963207f, 0.959809f, 0.956265f, 0.952574f, 0.948737f,
+ 0.944755f, 0.940629f, 0.936359f, 0.931946f, 0.92739f, 0.922692f, 0.917853f, 0.912873f, 0.907754f,
0.902497f, 0.897101f, 0.891567f, 0.885898f, 0.880093f, 0.874153f, 0.868079f, 0.861873f, 0.855535f,
0.849066f, 0.842467f, 0.835739f, 0.828884f, 0.821901f, 0.814793f, 0.807561f, 0.800204f, 0.792725f,
- 0.785125f, 0.777405f, 0.769566f, 0.76161f, 0.753536f, 0.745348f, 0.737045f, 0.72863f, 0.720103f,
- 0.711466f, 0.70272f, 0.693867f, 0.684908f, 0.675843f, 0.666676f, 0.657406f, 0.648036f, 0.638567f,
- 0.629f, 0.619337f, 0.609579f, 0.599728f, 0.589785f, 0.579752f, 0.56963f, 0.559421f, 0.549126f,
- 0.538748f, 0.528287f, 0.517745f, 0.507124f, 0.496425f, 0.485651f, 0.474802f, 0.46388f, 0.452888f,
+ 0.785125f, 0.777405f, 0.769566f, 0.76161f, 0.753536f, 0.745348f, 0.737045f, 0.72863f, 0.720103f,
+ 0.711466f, 0.70272f, 0.693867f, 0.684908f, 0.675843f, 0.666676f, 0.657406f, 0.648036f, 0.638567f,
+ 0.629f, 0.619337f, 0.609579f, 0.599728f, 0.589785f, 0.579752f, 0.56963f, 0.559421f, 0.549126f,
+ 0.538748f, 0.528287f, 0.517745f, 0.507124f, 0.496425f, 0.485651f, 0.474802f, 0.46388f, 0.452888f,
0.441826f, 0.430697f, 0.419502f, 0.408243f, 0.396921f, 0.385538f, 0.374097f, 0.362598f, 0.351044f,
0.339436f, 0.327776f, 0.316066f, 0.304308f, 0.292503f, 0.280653f, 0.268761f, 0.256827f, 0.244854f,
0.232844f, 0.220798f, 0.208718f, 0.196606f, 0.184465f, 0.172295f, 0.160098f, 0.147877f, 0.135634f,
- 0.12337f, 0.111087f, 0.098786f, 0.086471f, 0.074143f, 0.061803f, 0.049454f, 0.037097f, 0.024734f,
+ 0.12337f, 0.111087f, 0.098786f, 0.086471f, 0.074143f, 0.061803f, 0.049454f, 0.037097f, 0.024734f,
0.012368f, 0.0f
};
#if defined(VERSION_JP) || defined(VERSION_US)
// gVolRampingLhs136[k] = 2^16 * max(1, (256*k)^(1/17)
f32 gVolRampingLhs136[128] = {
- 65536.0f, 90811.555f, 94590.766f, 96873.96f, 98527.26f, 99829.06f, 100905.47f,
- 101824.61f, 102627.57f, 103341.086f, 103983.55f, 104568.164f, 105104.75f, 105600.8f,
- 106062.14f, 106493.46f, 106898.52f, 107280.414f, 107641.73f, 107984.62f, 108310.93f,
- 108622.23f, 108919.875f, 109205.055f, 109478.8f, 109742.0f, 109995.48f, 110239.94f,
- 110476.02f, 110704.305f, 110925.3f, 111139.45f, 111347.21f, 111548.945f, 111745.0f,
- 111935.7f, 112121.35f, 112302.2f, 112478.51f, 112650.51f, 112818.4f, 112982.38f,
- 113142.66f, 113299.37f, 113452.69f, 113602.766f, 113749.734f, 113893.73f, 114034.87f,
- 114173.26f, 114309.02f, 114442.26f, 114573.055f, 114701.5f, 114827.69f, 114951.695f,
- 115073.6f, 115193.47f, 115311.375f, 115427.39f, 115541.56f, 115653.96f, 115764.63f,
- 115873.64f, 115981.04f, 116086.86f, 116191.164f, 116293.99f, 116395.38f, 116495.38f,
- 116594.02f, 116691.34f, 116787.39f, 116882.19f, 116975.77f, 117068.17f, 117159.414f,
- 117249.54f, 117338.57f, 117426.53f, 117513.45f, 117599.35f, 117684.266f, 117768.2f,
- 117851.195f, 117933.266f, 118014.44f, 118094.72f, 118174.14f, 118252.71f, 118330.46f,
- 118407.4f, 118483.55f, 118558.914f, 118633.53f, 118707.4f, 118780.54f, 118852.97f,
- 118924.695f, 118995.74f, 119066.11f, 119135.82f, 119204.88f, 119273.31f, 119341.125f,
- 119408.32f, 119474.92f, 119540.93f, 119606.36f, 119671.22f, 119735.52f, 119799.28f,
- 119862.5f, 119925.195f, 119987.36f, 120049.02f, 120110.18f, 120170.84f, 120231.016f,
- 120290.71f, 120349.945f, 120408.7f, 120467.016f, 120524.875f, 120582.3f, 120639.28f,
- 120695.84f, 120751.984f
+ 65536.0f, 90811.555f, 94590.766f, 96873.96f, 98527.26f, 99829.06f, 100905.47f,
+ 101824.61f, 102627.57f, 103341.086f, 103983.55f, 104568.164f, 105104.75f, 105600.8f,
+ 106062.14f, 106493.46f, 106898.52f, 107280.414f, 107641.73f, 107984.62f, 108310.93f,
+ 108622.23f, 108919.875f, 109205.055f, 109478.8f, 109742.0f, 109995.48f, 110239.94f,
+ 110476.02f, 110704.305f, 110925.3f, 111139.45f, 111347.21f, 111548.945f, 111745.0f,
+ 111935.7f, 112121.35f, 112302.2f, 112478.51f, 112650.51f, 112818.4f, 112982.38f,
+ 113142.66f, 113299.37f, 113452.69f, 113602.766f, 113749.734f, 113893.73f, 114034.87f,
+ 114173.26f, 114309.02f, 114442.26f, 114573.055f, 114701.5f, 114827.69f, 114951.695f,
+ 115073.6f, 115193.47f, 115311.375f, 115427.39f, 115541.56f, 115653.96f, 115764.63f,
+ 115873.64f, 115981.04f, 116086.86f, 116191.164f, 116293.99f, 116395.38f, 116495.38f,
+ 116594.02f, 116691.34f, 116787.39f, 116882.19f, 116975.77f, 117068.17f, 117159.414f,
+ 117249.54f, 117338.57f, 117426.53f, 117513.45f, 117599.35f, 117684.266f, 117768.2f,
+ 117851.195f, 117933.266f, 118014.44f, 118094.72f, 118174.14f, 118252.71f, 118330.46f,
+ 118407.4f, 118483.55f, 118558.914f, 118633.53f, 118707.4f, 118780.54f, 118852.97f,
+ 118924.695f, 118995.74f, 119066.11f, 119135.82f, 119204.88f, 119273.31f, 119341.125f,
+ 119408.32f, 119474.92f, 119540.93f, 119606.36f, 119671.22f, 119735.52f, 119799.28f,
+ 119862.5f, 119925.195f, 119987.36f, 120049.02f, 120110.18f, 120170.84f, 120231.016f,
+ 120290.71f, 120349.945f, 120408.7f, 120467.016f, 120524.875f, 120582.3f, 120639.28f,
+ 120695.84f, 120751.984f
};
// gVolRampingRhs136[k] = 1 / max(1, (256*k)^(1/17))
f32 gVolRampingRhs136[128] = {
- 1.0f, 0.72167f, 0.692837f, 0.676508f, 0.665156f, 0.656482f, 0.649479f, 0.643616f, 0.638581f,
- 0.634172f, 0.630254f, 0.62673f, 0.62353f, 0.620601f, 0.617902f, 0.615399f, 0.613067f, 0.610885f,
- 0.608835f, 0.606901f, 0.605073f, 0.603339f, 0.60169f, 0.600119f, 0.598618f, 0.597183f, 0.595806f,
+ 1.0f, 0.72167f, 0.692837f, 0.676508f, 0.665156f, 0.656482f, 0.649479f, 0.643616f, 0.638581f,
+ 0.634172f, 0.630254f, 0.62673f, 0.62353f, 0.620601f, 0.617902f, 0.615399f, 0.613067f, 0.610885f,
+ 0.608835f, 0.606901f, 0.605073f, 0.603339f, 0.60169f, 0.600119f, 0.598618f, 0.597183f, 0.595806f,
0.594485f, 0.593215f, 0.591991f, 0.590812f, 0.589674f, 0.588573f, 0.587509f, 0.586478f, 0.585479f,
- 0.58451f, 0.583568f, 0.582654f, 0.581764f, 0.580898f, 0.580055f, 0.579233f, 0.578432f, 0.57765f,
+ 0.58451f, 0.583568f, 0.582654f, 0.581764f, 0.580898f, 0.580055f, 0.579233f, 0.578432f, 0.57765f,
0.576887f, 0.576142f, 0.575414f, 0.574701f, 0.574005f, 0.573323f, 0.572656f, 0.572002f, 0.571361f,
0.570733f, 0.570118f, 0.569514f, 0.568921f, 0.568339f, 0.567768f, 0.567207f, 0.566656f, 0.566114f,
0.565582f, 0.565058f, 0.564543f, 0.564036f, 0.563537f, 0.563046f, 0.562563f, 0.562087f, 0.561618f,
0.561156f, 0.560701f, 0.560253f, 0.559811f, 0.559375f, 0.558945f, 0.558521f, 0.558102f, 0.557689f,
- 0.557282f, 0.55688f, 0.556483f, 0.556091f, 0.555704f, 0.555322f, 0.554944f, 0.554571f, 0.554203f,
- 0.553839f, 0.553479f, 0.553123f, 0.552772f, 0.552424f, 0.55208f, 0.55174f, 0.551404f, 0.551071f,
+ 0.557282f, 0.55688f, 0.556483f, 0.556091f, 0.555704f, 0.555322f, 0.554944f, 0.554571f, 0.554203f,
+ 0.553839f, 0.553479f, 0.553123f, 0.552772f, 0.552424f, 0.55208f, 0.55174f, 0.551404f, 0.551071f,
0.550742f, 0.550417f, 0.550095f, 0.549776f, 0.549461f, 0.549148f, 0.548839f, 0.548534f, 0.548231f,
- 0.547931f, 0.547634f, 0.54734f, 0.547048f, 0.54676f, 0.546474f, 0.546191f, 0.54591f, 0.545632f,
- 0.545357f, 0.545084f, 0.544813f, 0.544545f, 0.54428f, 0.544016f, 0.543755f, 0.543496f, 0.543239f,
+ 0.547931f, 0.547634f, 0.54734f, 0.547048f, 0.54676f, 0.546474f, 0.546191f, 0.54591f, 0.545632f,
+ 0.545357f, 0.545084f, 0.544813f, 0.544545f, 0.54428f, 0.544016f, 0.543755f, 0.543496f, 0.543239f,
0.542985f, 0.542732f
};
// gVolRampingLhs144[k] = 2^16 * max(1, (256*k)^(1/18))
f32 gVolRampingLhs144[128] = {
- 65536.0f, 89180.734f, 92681.9f, 94793.33f, 96320.52f, 97522.02f, 98514.84f,
- 99362.14f, 100101.99f, 100759.16f, 101350.664f, 101888.74f, 102382.46f, 102838.75f,
- 103263.016f, 103659.58f, 104031.914f, 104382.89f, 104714.88f, 105029.89f, 105329.61f,
- 105615.5f, 105888.81f, 106150.63f, 106401.914f, 106643.49f, 106876.12f, 107100.44f,
- 107317.05f, 107526.47f, 107729.17f, 107925.6f, 108116.125f, 108301.12f, 108480.88f,
- 108655.72f, 108825.91f, 108991.68f, 109153.28f, 109310.914f, 109464.77f, 109615.04f,
- 109761.88f, 109905.46f, 110045.92f, 110183.41f, 110318.02f, 110449.91f, 110579.17f,
- 110705.914f, 110830.234f, 110952.234f, 111071.99f, 111189.59f, 111305.12f, 111418.64f,
- 111530.23f, 111639.95f, 111747.875f, 111854.05f, 111958.54f, 112061.4f, 112162.67f,
- 112262.42f, 112360.68f, 112457.51f, 112552.93f, 112647.0f, 112739.76f, 112831.23f,
- 112921.46f, 113010.484f, 113098.33f, 113185.02f, 113270.61f, 113355.11f, 113438.555f,
- 113520.97f, 113602.375f, 113682.805f, 113762.27f, 113840.81f, 113918.44f, 113995.18f,
- 114071.055f, 114146.08f, 114220.266f, 114293.65f, 114366.24f, 114438.06f, 114509.12f,
- 114579.44f, 114649.02f, 114717.91f, 114786.086f, 114853.586f, 114920.42f, 114986.6f,
- 115052.14f, 115117.055f, 115181.34f, 115245.04f, 115308.13f, 115370.65f, 115432.59f,
- 115493.98f, 115554.81f, 115615.11f, 115674.875f, 115734.12f, 115792.85f, 115851.08f,
- 115908.82f, 115966.07f, 116022.85f, 116079.16f, 116135.01f, 116190.4f, 116245.35f,
- 116299.87f, 116353.945f, 116407.6f, 116460.84f, 116513.67f, 116566.09f, 116618.125f,
- 116669.76f, 116721.01f
+ 65536.0f, 89180.734f, 92681.9f, 94793.33f, 96320.52f, 97522.02f, 98514.84f,
+ 99362.14f, 100101.99f, 100759.16f, 101350.664f, 101888.74f, 102382.46f, 102838.75f,
+ 103263.016f, 103659.58f, 104031.914f, 104382.89f, 104714.88f, 105029.89f, 105329.61f,
+ 105615.5f, 105888.81f, 106150.63f, 106401.914f, 106643.49f, 106876.12f, 107100.44f,
+ 107317.05f, 107526.47f, 107729.17f, 107925.6f, 108116.125f, 108301.12f, 108480.88f,
+ 108655.72f, 108825.91f, 108991.68f, 109153.28f, 109310.914f, 109464.77f, 109615.04f,
+ 109761.88f, 109905.46f, 110045.92f, 110183.41f, 110318.02f, 110449.91f, 110579.17f,
+ 110705.914f, 110830.234f, 110952.234f, 111071.99f, 111189.59f, 111305.12f, 111418.64f,
+ 111530.23f, 111639.95f, 111747.875f, 111854.05f, 111958.54f, 112061.4f, 112162.67f,
+ 112262.42f, 112360.68f, 112457.51f, 112552.93f, 112647.0f, 112739.76f, 112831.23f,
+ 112921.46f, 113010.484f, 113098.33f, 113185.02f, 113270.61f, 113355.11f, 113438.555f,
+ 113520.97f, 113602.375f, 113682.805f, 113762.27f, 113840.81f, 113918.44f, 113995.18f,
+ 114071.055f, 114146.08f, 114220.266f, 114293.65f, 114366.24f, 114438.06f, 114509.12f,
+ 114579.44f, 114649.02f, 114717.91f, 114786.086f, 114853.586f, 114920.42f, 114986.6f,
+ 115052.14f, 115117.055f, 115181.34f, 115245.04f, 115308.13f, 115370.65f, 115432.59f,
+ 115493.98f, 115554.81f, 115615.11f, 115674.875f, 115734.12f, 115792.85f, 115851.08f,
+ 115908.82f, 115966.07f, 116022.85f, 116079.16f, 116135.01f, 116190.4f, 116245.35f,
+ 116299.87f, 116353.945f, 116407.6f, 116460.84f, 116513.67f, 116566.09f, 116618.125f,
+ 116669.76f, 116721.01f
};
// gVolRampingRhs144[k] = 1 / max(1, (256*k)^(1/18))
f32 gVolRampingRhs144[128] = {
- 1.0f, 0.734867f, 0.707107f, 0.691357f, 0.680395f, 0.672012f, 0.66524f, 0.659567f, 0.654692f,
- 0.650422f, 0.646626f, 0.643211f, 0.64011f, 0.637269f, 0.634651f, 0.632223f, 0.629961f, 0.627842f,
+ 1.0f, 0.734867f, 0.707107f, 0.691357f, 0.680395f, 0.672012f, 0.66524f, 0.659567f, 0.654692f,
+ 0.650422f, 0.646626f, 0.643211f, 0.64011f, 0.637269f, 0.634651f, 0.632223f, 0.629961f, 0.627842f,
0.625852f, 0.623975f, 0.622199f, 0.620515f, 0.618913f, 0.617387f, 0.615929f, 0.614533f, 0.613196f,
- 0.611912f, 0.610677f, 0.609487f, 0.60834f, 0.607233f, 0.606163f, 0.605128f, 0.604125f, 0.603153f,
- 0.60221f, 0.601294f, 0.600403f, 0.599538f, 0.598695f, 0.597874f, 0.597074f, 0.596294f, 0.595533f,
- 0.59479f, 0.594064f, 0.593355f, 0.592661f, 0.591983f, 0.591319f, 0.590669f, 0.590032f, 0.589408f,
- 0.588796f, 0.588196f, 0.587608f, 0.58703f, 0.586463f, 0.585906f, 0.58536f, 0.584822f, 0.584294f,
+ 0.611912f, 0.610677f, 0.609487f, 0.60834f, 0.607233f, 0.606163f, 0.605128f, 0.604125f, 0.603153f,
+ 0.60221f, 0.601294f, 0.600403f, 0.599538f, 0.598695f, 0.597874f, 0.597074f, 0.596294f, 0.595533f,
+ 0.59479f, 0.594064f, 0.593355f, 0.592661f, 0.591983f, 0.591319f, 0.590669f, 0.590032f, 0.589408f,
+ 0.588796f, 0.588196f, 0.587608f, 0.58703f, 0.586463f, 0.585906f, 0.58536f, 0.584822f, 0.584294f,
0.583775f, 0.583265f, 0.582762f, 0.582268f, 0.581782f, 0.581303f, 0.580832f, 0.580368f, 0.579911f,
- 0.57946f, 0.579017f, 0.578579f, 0.578148f, 0.577722f, 0.577303f, 0.576889f, 0.576481f, 0.576078f,
- 0.575681f, 0.575289f, 0.574902f, 0.574519f, 0.574142f, 0.573769f, 0.5734f, 0.573036f, 0.572677f,
- 0.572321f, 0.57197f, 0.571623f, 0.57128f, 0.57094f, 0.570605f, 0.570273f, 0.569945f, 0.56962f,
+ 0.57946f, 0.579017f, 0.578579f, 0.578148f, 0.577722f, 0.577303f, 0.576889f, 0.576481f, 0.576078f,
+ 0.575681f, 0.575289f, 0.574902f, 0.574519f, 0.574142f, 0.573769f, 0.5734f, 0.573036f, 0.572677f,
+ 0.572321f, 0.57197f, 0.571623f, 0.57128f, 0.57094f, 0.570605f, 0.570273f, 0.569945f, 0.56962f,
0.569299f, 0.568981f, 0.568667f, 0.568355f, 0.568047f, 0.567743f, 0.567441f, 0.567142f, 0.566846f,
- 0.566553f, 0.566263f, 0.565976f, 0.565692f, 0.56541f, 0.565131f, 0.564854f, 0.56458f, 0.564309f,
- 0.56404f, 0.563773f, 0.563509f, 0.563247f, 0.562987f, 0.56273f, 0.562475f, 0.562222f, 0.561971f,
+ 0.566553f, 0.566263f, 0.565976f, 0.565692f, 0.56541f, 0.565131f, 0.564854f, 0.56458f, 0.564309f,
+ 0.56404f, 0.563773f, 0.563509f, 0.563247f, 0.562987f, 0.56273f, 0.562475f, 0.562222f, 0.561971f,
0.561722f, 0.561476f
};
// gVolRampingLhs128[k] = 2^16 * max(1, (256*k)^(1/16))
f32 gVolRampingLhs128[128] = {
- 65536.0f, 92681.9f, 96785.28f, 99269.31f, 101070.33f, 102489.78f, 103664.336f,
- 104667.914f, 105545.09f, 106324.92f, 107027.39f, 107666.84f, 108253.95f, 108796.87f,
- 109301.95f, 109774.29f, 110217.98f, 110636.39f, 111032.33f, 111408.164f, 111765.9f,
- 112107.234f, 112433.66f, 112746.46f, 113046.766f, 113335.555f, 113613.72f, 113882.02f,
- 114141.164f, 114391.77f, 114634.414f, 114869.58f, 115097.74f, 115319.31f, 115534.68f,
- 115744.19f, 115948.16f, 116146.875f, 116340.625f, 116529.66f, 116714.195f, 116894.46f,
- 117070.64f, 117242.945f, 117411.52f, 117576.55f, 117738.17f, 117896.54f, 118051.77f,
- 118204.0f, 118353.35f, 118499.92f, 118643.83f, 118785.16f, 118924.01f, 119060.47f,
- 119194.625f, 119326.555f, 119456.336f, 119584.03f, 119709.71f, 119833.445f, 119955.29f,
- 120075.31f, 120193.555f, 120310.08f, 120424.94f, 120538.17f, 120649.836f, 120759.97f,
- 120868.62f, 120975.82f, 121081.62f, 121186.05f, 121289.14f, 121390.94f, 121491.47f,
- 121590.766f, 121688.87f, 121785.79f, 121881.57f, 121976.24f, 122069.82f, 122162.33f,
- 122253.805f, 122344.266f, 122433.73f, 122522.23f, 122609.77f, 122696.4f, 122782.11f,
- 122866.93f, 122950.89f, 123033.99f, 123116.26f, 123197.72f, 123278.37f, 123358.24f,
- 123437.34f, 123515.69f, 123593.3f, 123670.19f, 123746.36f, 123821.84f, 123896.63f,
- 123970.76f, 124044.23f, 124117.04f, 124189.23f, 124260.78f, 124331.73f, 124402.07f,
- 124471.83f, 124540.99f, 124609.59f, 124677.63f, 124745.12f, 124812.055f, 124878.47f,
- 124944.34f, 125009.71f, 125074.57f, 125138.92f, 125202.79f, 125266.164f, 125329.06f,
- 125391.5f, 125453.47f
+ 65536.0f, 92681.9f, 96785.28f, 99269.31f, 101070.33f, 102489.78f, 103664.336f,
+ 104667.914f, 105545.09f, 106324.92f, 107027.39f, 107666.84f, 108253.95f, 108796.87f,
+ 109301.95f, 109774.29f, 110217.98f, 110636.39f, 111032.33f, 111408.164f, 111765.9f,
+ 112107.234f, 112433.66f, 112746.46f, 113046.766f, 113335.555f, 113613.72f, 113882.02f,
+ 114141.164f, 114391.77f, 114634.414f, 114869.58f, 115097.74f, 115319.31f, 115534.68f,
+ 115744.19f, 115948.16f, 116146.875f, 116340.625f, 116529.66f, 116714.195f, 116894.46f,
+ 117070.64f, 117242.945f, 117411.52f, 117576.55f, 117738.17f, 117896.54f, 118051.77f,
+ 118204.0f, 118353.35f, 118499.92f, 118643.83f, 118785.16f, 118924.01f, 119060.47f,
+ 119194.625f, 119326.555f, 119456.336f, 119584.03f, 119709.71f, 119833.445f, 119955.29f,
+ 120075.31f, 120193.555f, 120310.08f, 120424.94f, 120538.17f, 120649.836f, 120759.97f,
+ 120868.62f, 120975.82f, 121081.62f, 121186.05f, 121289.14f, 121390.94f, 121491.47f,
+ 121590.766f, 121688.87f, 121785.79f, 121881.57f, 121976.24f, 122069.82f, 122162.33f,
+ 122253.805f, 122344.266f, 122433.73f, 122522.23f, 122609.77f, 122696.4f, 122782.11f,
+ 122866.93f, 122950.89f, 123033.99f, 123116.26f, 123197.72f, 123278.37f, 123358.24f,
+ 123437.34f, 123515.69f, 123593.3f, 123670.19f, 123746.36f, 123821.84f, 123896.63f,
+ 123970.76f, 124044.23f, 124117.04f, 124189.23f, 124260.78f, 124331.73f, 124402.07f,
+ 124471.83f, 124540.99f, 124609.59f, 124677.63f, 124745.12f, 124812.055f, 124878.47f,
+ 124944.34f, 125009.71f, 125074.57f, 125138.92f, 125202.79f, 125266.164f, 125329.06f,
+ 125391.5f, 125453.47f
};
// gVolRampingRhs128[k] = 1 / max(1, (256*k)^(1/16))
f32 gVolRampingRhs128[128] = {
- 1.0f, 0.707107f, 0.677128f, 0.660184f, 0.64842f, 0.639439f, 0.632194f, 0.626133f, 0.620929f,
- 0.616375f, 0.612329f, 0.608693f, 0.605391f, 0.60237f, 0.599587f, 0.597007f, 0.594604f, 0.592355f,
+ 1.0f, 0.707107f, 0.677128f, 0.660184f, 0.64842f, 0.639439f, 0.632194f, 0.626133f, 0.620929f,
+ 0.616375f, 0.612329f, 0.608693f, 0.605391f, 0.60237f, 0.599587f, 0.597007f, 0.594604f, 0.592355f,
0.590243f, 0.588251f, 0.586369f, 0.584583f, 0.582886f, 0.581269f, 0.579725f, 0.578247f, 0.576832f,
- 0.575473f, 0.574166f, 0.572908f, 0.571696f, 0.570525f, 0.569394f, 0.5683f, 0.567241f, 0.566214f,
+ 0.575473f, 0.574166f, 0.572908f, 0.571696f, 0.570525f, 0.569394f, 0.5683f, 0.567241f, 0.566214f,
0.565218f, 0.564251f, 0.563311f, 0.562398f, 0.561508f, 0.560642f, 0.559799f, 0.558976f, 0.558173f,
- 0.55739f, 0.556625f, 0.555877f, 0.555146f, 0.554431f, 0.553732f, 0.553047f, 0.552376f, 0.551719f,
+ 0.55739f, 0.556625f, 0.555877f, 0.555146f, 0.554431f, 0.553732f, 0.553047f, 0.552376f, 0.551719f,
0.551075f, 0.550443f, 0.549823f, 0.549216f, 0.548619f, 0.548033f, 0.547458f, 0.546892f, 0.546337f,
0.545791f, 0.545254f, 0.544726f, 0.544206f, 0.543695f, 0.543192f, 0.542696f, 0.542209f, 0.541728f,
0.541255f, 0.540788f, 0.540329f, 0.539876f, 0.539429f, 0.538988f, 0.538554f, 0.538125f, 0.537702f,
0.537285f, 0.536873f, 0.536467f, 0.536065f, 0.535669f, 0.535277f, 0.534891f, 0.534509f, 0.534131f,
- 0.533759f, 0.53339f, 0.533026f, 0.532666f, 0.53231f, 0.531958f, 0.53161f, 0.531266f, 0.530925f,
+ 0.533759f, 0.53339f, 0.533026f, 0.532666f, 0.53231f, 0.531958f, 0.53161f, 0.531266f, 0.530925f,
0.530588f, 0.530255f, 0.529926f, 0.529599f, 0.529277f, 0.528957f, 0.528641f, 0.528328f, 0.528018f,
- 0.527711f, 0.527407f, 0.527106f, 0.526808f, 0.526513f, 0.52622f, 0.525931f, 0.525644f, 0.525359f,
+ 0.527711f, 0.527407f, 0.527106f, 0.526808f, 0.526513f, 0.52622f, 0.525931f, 0.525644f, 0.525359f,
0.525077f, 0.524798f, 0.524522f, 0.524247f, 0.523975f, 0.523706f, 0.523439f, 0.523174f, 0.522911f,
0.522651f, 0.522393f
};
@@ -888,11 +904,11 @@ volatile s32 gAudioLoadLock = AUDIO_LOCK_UNINITIALIZED;
#endif
#if defined(VERSION_EU)
-u8 bufferDelete2[12] = { 0 };
+u8 bufferDelete2[12] = {0};
u8 D_EU_80302010 = 0;
u8 D_EU_80302014 = 0;
-struct OSMesgQueue *OSMesgQueues[4] = { &OSMesgQueue0, &OSMesgQueue1, &OSMesgQueue2, &OSMesgQueue3 };
+struct OSMesgQueue *OSMesgQueues[4] = {&OSMesgQueue0, &OSMesgQueue1, &OSMesgQueue2, &OSMesgQueue3};
#elif defined(VERSION_JP) || defined(VERSION_US)
s8 sUnused8033EF8 = 24;
#endif
diff --git a/src/decomp/audio/effects.c b/src/decomp/audio/effects.c
index 76bb584..bd243f3 100644
--- a/src/decomp/audio/effects.c
+++ b/src/decomp/audio/effects.c
@@ -14,27 +14,30 @@
f32 gTrackVolume = 1.0f;
#if defined(VERSION_EU) || defined(VERSION_SH)
-void sequence_channel_process_sound(struct SequenceChannel *seqChannel, s32 recalculateVolume) {
+void sequence_channel_process_sound(struct SequenceChannel *seqChannel, s32 recalculateVolume)
+{
f32 channelVolume;
s32 i;
- if (seqChannel->changes.as_bitfields.volume || recalculateVolume) {
+ if (seqChannel->changes.as_bitfields.volume || recalculateVolume)
+ {
channelVolume = seqChannel->volume * seqChannel->volumeScale * seqChannel->seqPlayer->appliedFadeVolume;
- if (seqChannel->seqPlayer->muted && (seqChannel->muteBehavior & MUTE_BEHAVIOR_SOFTEN) != 0) {
+ if (seqChannel->seqPlayer->muted && (seqChannel->muteBehavior & MUTE_BEHAVIOR_SOFTEN) != 0)
+ {
channelVolume = seqChannel->seqPlayer->muteVolumeScale * channelVolume;
}
#ifdef VERSION_SH
- seqChannel->appliedVolume = channelVolume * channelVolume;
+seqChannel->appliedVolume= channelVolume* channelVolume;
#else
- seqChannel->appliedVolume = channelVolume;
+seqChannel->appliedVolume= channelVolume;
#endif
- }
+}
if (seqChannel->changes.as_bitfields.pan) {
seqChannel->pan = seqChannel->newPan * seqChannel->panChannelWeight;
}
- for (i = 0; i < 4; ++i) {
+ for (i =0; i<4;++i) {
struct SequenceChannelLayer *layer = seqChannel->layers[i];
if (layer != NULL && layer->enabled && layer->note != NULL) {
if (layer->notePropertiesNeedInit) {
@@ -55,58 +58,69 @@ void sequence_channel_process_sound(struct SequenceChannel *seqChannel, s32 reca
}
}
}
- seqChannel->changes.as_u8 = 0;
+seqChannel->changes.as_u8=0;
}
#else
-static void sequence_channel_process_sound(struct SequenceChannel *seqChannel) {
+static void sequence_channel_process_sound(struct SequenceChannel *seqChannel)
+{
f32 channelVolume;
f32 panLayerWeight;
f32 panFromChannel;
s32 i;
channelVolume = seqChannel->volume * seqChannel->volumeScale * seqChannel->seqPlayer->fadeVolume;
- if (seqChannel->seqPlayer->muted && (seqChannel->muteBehavior & MUTE_BEHAVIOR_SOFTEN) != 0) {
+ if (seqChannel->seqPlayer->muted && (seqChannel->muteBehavior & MUTE_BEHAVIOR_SOFTEN) != 0)
+ {
channelVolume *= seqChannel->seqPlayer->muteVolumeScale;
}
panFromChannel = seqChannel->pan * seqChannel->panChannelWeight;
panLayerWeight = US_FLOAT(1.0) - seqChannel->panChannelWeight;
- for (i = 0; i < 4; i++) {
+ for (i = 0; i < 4; i++)
+ {
struct SequenceChannelLayer *layer = seqChannel->layers[i];
- if (layer != NULL && layer->enabled && layer->note != NULL) {
+ if (layer != NULL && layer->enabled && layer->note != NULL)
+ {
layer->noteFreqScale = layer->freqScale * seqChannel->freqScale;
layer->noteVelocity = layer->velocitySquare * (channelVolume * gTrackVolume);
- layer->notePan = (layer->pan * panLayerWeight) + panFromChannel;
+ layer->notePan = layer->pan * panLayerWeight + panFromChannel;
}
}
}
#endif
-void sequence_player_process_sound(struct SequencePlayer *seqPlayer) {
+void sequence_player_process_sound(struct SequencePlayer *seqPlayer)
+{
s32 i;
- if (seqPlayer->fadeRemainingFrames != 0) {
+ if (seqPlayer->fadeRemainingFrames != 0)
+ {
seqPlayer->fadeVolume += seqPlayer->fadeVelocity;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
seqPlayer->recalculateVolume = TRUE;
-#endif
+ #endif
- if (seqPlayer->fadeVolume > US_FLOAT2(1)) {
+ if (seqPlayer->fadeVolume > US_FLOAT2(1))
+ {
seqPlayer->fadeVolume = US_FLOAT2(1);
}
- if (seqPlayer->fadeVolume < 0) {
+ if (seqPlayer->fadeVolume < 0)
+ {
seqPlayer->fadeVolume = 0;
}
- if (--seqPlayer->fadeRemainingFrames == 0) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
- if (seqPlayer->state == 2) {
+ if (--seqPlayer->fadeRemainingFrames == 0)
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ if (seqPlayer->state == 2)
+ {
sequence_player_disable(seqPlayer);
return;
}
-#else
- switch (seqPlayer->state) {
+ #else
+ switch (seqPlayer->state)
+ {
case SEQUENCE_PLAYER_STATE_FADE_OUT:
sequence_player_disable(seqPlayer);
return;
@@ -119,77 +133,85 @@ void sequence_player_process_sound(struct SequencePlayer *seqPlayer) {
case SEQUENCE_PLAYER_STATE_4:
break;
}
-#endif
+ #endif
}
}
-#if defined(VERSION_EU) || defined(VERSION_SH)
- if (seqPlayer->recalculateVolume) {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ if (seqPlayer->recalculateVolume)
+ {
seqPlayer->appliedFadeVolume = seqPlayer->fadeVolume * seqPlayer->fadeVolumeScale;
}
-#endif
+ #endif
// Process channels
- for (i = 0; i < CHANNELS_MAX; i++) {
+ for (i = 0; i < CHANNELS_MAX; i++)
+ {
if (IS_SEQUENCE_CHANNEL_VALID(seqPlayer->channels[i]) == TRUE
- && seqPlayer->channels[i]->enabled == TRUE) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ && seqPlayer->channels[i]->enabled == TRUE)
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
sequence_channel_process_sound(seqPlayer->channels[i], seqPlayer->recalculateVolume);
-#else
+ #else
sequence_channel_process_sound(seqPlayer->channels[i]);
-#endif
+ #endif
}
}
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
seqPlayer->recalculateVolume = FALSE;
-#endif
+ #endif
}
-f32 get_portamento_freq_scale(struct Portamento *p) {
+f32 get_portamento_freq_scale(struct Portamento *p)
+{
u32 v0;
f32 result;
-#if defined(VERSION_JP) || defined(VERSION_US)
- if (p->mode == 0) {
+ #if defined(VERSION_JP) || defined(VERSION_US)
+ if (p->mode == 0)
+ {
return 1.0f;
}
-#endif
+ #endif
p->cur += p->speed;
- v0 = (u32) p->cur;
+ v0 = (u32)p->cur;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
if (v0 > 127)
-#else
+ #else
if (v0 >= 127)
-#endif
+ #endif
{
v0 = 127;
}
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
result = US_FLOAT(1.0) + p->extent * (gPitchBendFrequencyScale[v0 + 128] - US_FLOAT(1.0));
-#else
+ #else
result = US_FLOAT(1.0) + p->extent * (gPitchBendFrequencyScale[v0 + 127] - US_FLOAT(1.0));
-#endif
+ #endif
return result;
}
#if defined(VERSION_EU) || defined(VERSION_SH)
-s16 get_vibrato_pitch_change(struct VibratoState *vib) {
+s16 get_vibrato_pitch_change(struct VibratoState *vib)
+{
s32 index;
- vib->time += (s32) vib->rate;
+ vib->time += (s32)vib->rate;
index = (vib->time >> 10) & 0x3F;
return vib->curve[index] >> 8;
}
#else
-s8 get_vibrato_pitch_change(struct VibratoState *vib) {
+s8 get_vibrato_pitch_change(struct VibratoState *vib)
+{
s32 index;
vib->time += vib->rate;
- index = (vib->time >> 10) & 0x3F;
+ index = vib->time >> 10 & 0x3F;
- switch (index & 0x30) {
+ switch (index & 0x30)
+ {
case 0x10:
index = 31 - index;
@@ -209,181 +231,226 @@ s8 get_vibrato_pitch_change(struct VibratoState *vib) {
}
#endif
-f32 get_vibrato_freq_scale(struct VibratoState *vib) {
+f32 get_vibrato_freq_scale(struct VibratoState *vib)
+{
s32 pitchChange;
f32 extent;
f32 result;
- if (vib->delay != 0) {
+ if (vib->delay != 0)
+ {
vib->delay--;
return 1;
}
- if (vib->extentChangeTimer) {
- if (vib->extentChangeTimer == 1) {
- vib->extent = (s32) vib->seqChannel->vibratoExtentTarget;
- } else {
+ if (vib->extentChangeTimer)
+ {
+ if (vib->extentChangeTimer == 1)
+ {
+ vib->extent = (s32)vib->seqChannel->vibratoExtentTarget;
+ }
+ else
+ {
vib->extent +=
- ((s32) vib->seqChannel->vibratoExtentTarget - vib->extent) / (s32) vib->extentChangeTimer;
+ ((s32)vib->seqChannel->vibratoExtentTarget - vib->extent) / (s32)vib->extentChangeTimer;
}
vib->extentChangeTimer--;
- } else if (vib->seqChannel->vibratoExtentTarget != (s32) vib->extent) {
- if ((vib->extentChangeTimer = vib->seqChannel->vibratoExtentChangeDelay) == 0) {
- vib->extent = (s32) vib->seqChannel->vibratoExtentTarget;
+ }
+ else if (vib->seqChannel->vibratoExtentTarget != (s32)vib->extent)
+ {
+ if ((vib->extentChangeTimer = vib->seqChannel->vibratoExtentChangeDelay) == 0)
+ {
+ vib->extent = (s32)vib->seqChannel->vibratoExtentTarget;
}
}
- if (vib->rateChangeTimer) {
- if (vib->rateChangeTimer == 1) {
- vib->rate = (s32) vib->seqChannel->vibratoRateTarget;
- } else {
- vib->rate += ((s32) vib->seqChannel->vibratoRateTarget - vib->rate) / (s32) vib->rateChangeTimer;
+ if (vib->rateChangeTimer)
+ {
+ if (vib->rateChangeTimer == 1)
+ {
+ vib->rate = (s32)vib->seqChannel->vibratoRateTarget;
+ }
+ else
+ {
+ vib->rate += ((s32)vib->seqChannel->vibratoRateTarget - vib->rate) / (s32)vib->rateChangeTimer;
}
vib->rateChangeTimer--;
- } else if (vib->seqChannel->vibratoRateTarget != (s32) vib->rate) {
- if ((vib->rateChangeTimer = vib->seqChannel->vibratoRateChangeDelay) == 0) {
- vib->rate = (s32) vib->seqChannel->vibratoRateTarget;
+ }
+ else if (vib->seqChannel->vibratoRateTarget != (s32)vib->rate)
+ {
+ if ((vib->rateChangeTimer = vib->seqChannel->vibratoRateChangeDelay) == 0)
+ {
+ vib->rate = (s32)vib->seqChannel->vibratoRateTarget;
}
}
- if (vib->extent == 0) {
+ if (vib->extent == 0)
+ {
return 1.0f;
}
pitchChange = get_vibrato_pitch_change(vib);
- extent = (f32) vib->extent / US_FLOAT(4096.0);
+ extent = (f32)vib->extent / US_FLOAT(4096.0);
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
result = US_FLOAT(1.0) + extent * (gPitchBendFrequencyScale[pitchChange + 128] - US_FLOAT(1.0));
-#else
+ #else
result = US_FLOAT(1.0) + extent * (gPitchBendFrequencyScale[pitchChange + 127] - US_FLOAT(1.0));
-#endif
+ #endif
return result;
}
-void note_vibrato_update(struct Note *note) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
- if (note->portamento.mode != 0) {
+void note_vibrato_update(struct Note *note)
+{
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ if (note->portamento.mode != 0)
+ {
note->portamentoFreqScale = get_portamento_freq_scale(¬e->portamento);
}
- if (note->vibratoState.active && note->parentLayer != NO_LAYER) {
+ if (note->vibratoState.active && note->parentLayer != NO_LAYER)
+ {
note->vibratoFreqScale = get_vibrato_freq_scale(¬e->vibratoState);
}
-#else
- if (note->vibratoState.active) {
+ #else
+ if (note->vibratoState.active)
+ {
note->portamentoFreqScale = get_portamento_freq_scale(¬e->portamento);
- if (note->parentLayer != NO_LAYER) {
+ if (note->parentLayer != NO_LAYER)
+ {
note->vibratoFreqScale = get_vibrato_freq_scale(¬e->vibratoState);
}
}
-#endif
+ #endif
}
-void note_vibrato_init(struct Note *note) {
+void note_vibrato_init(struct Note *note)
+{
struct VibratoState *vib;
- UNUSED struct SequenceChannel *seqChannel;
-#if defined(VERSION_EU) || defined(VERSION_SH)
- struct NotePlaybackState *seqPlayerState = (struct NotePlaybackState *) ¬e->priority;
-#endif
+ UNUSED
+ struct SequenceChannel *seqChannel;
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ struct NotePlaybackState *seqPlayerState = (struct NotePlaybackState *)¬e->priority;
+ #endif
note->vibratoFreqScale = 1.0f;
note->portamentoFreqScale = 1.0f;
vib = ¬e->vibratoState;
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #if defined(VERSION_JP) || defined(VERSION_US)
if (note->parentLayer->seqChannel->vibratoExtentStart == 0
&& note->parentLayer->seqChannel->vibratoExtentTarget == 0
- && note->parentLayer->portamento.mode == 0) {
+ && note->parentLayer->portamento.mode == 0)
+ {
vib->active = FALSE;
return;
}
-#endif
+ #endif
vib->active = TRUE;
vib->time = 0;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
vib->curve = gWaveSamples[2];
vib->seqChannel = note->parentLayer->seqChannel;
- if ((vib->extentChangeTimer = vib->seqChannel->vibratoExtentChangeDelay) == 0) {
+ if ((vib->extentChangeTimer = vib->seqChannel->vibratoExtentChangeDelay) == 0)
+ {
vib->extent = FLOAT_CAST(vib->seqChannel->vibratoExtentTarget);
- } else {
+ }
+ else
+ {
vib->extent = FLOAT_CAST(vib->seqChannel->vibratoExtentStart);
}
- if ((vib->rateChangeTimer = vib->seqChannel->vibratoRateChangeDelay) == 0) {
+ if ((vib->rateChangeTimer = vib->seqChannel->vibratoRateChangeDelay) == 0)
+ {
vib->rate = FLOAT_CAST(vib->seqChannel->vibratoRateTarget);
- } else {
+ }
+ else
+ {
vib->rate = FLOAT_CAST(vib->seqChannel->vibratoRateStart);
}
vib->delay = vib->seqChannel->vibratoDelay;
seqPlayerState->portamento = seqPlayerState->parentLayer->portamento;
-#else
+ #else
vib->curve = gVibratoCurve;
vib->seqChannel = note->parentLayer->seqChannel;
seqChannel = vib->seqChannel;
- if ((vib->extentChangeTimer = seqChannel->vibratoExtentChangeDelay) == 0) {
+ if ((vib->extentChangeTimer = seqChannel->vibratoExtentChangeDelay) == 0)
+ {
vib->extent = seqChannel->vibratoExtentTarget;
- } else {
+ }
+ else
+ {
vib->extent = seqChannel->vibratoExtentStart;
}
- if ((vib->rateChangeTimer = seqChannel->vibratoRateChangeDelay) == 0) {
+ if ((vib->rateChangeTimer = seqChannel->vibratoRateChangeDelay) == 0)
+ {
vib->rate = seqChannel->vibratoRateTarget;
- } else {
+ }
+ else
+ {
vib->rate = seqChannel->vibratoRateStart;
}
vib->delay = seqChannel->vibratoDelay;
note->portamento = note->parentLayer->portamento;
-#endif
+ #endif
}
-void adsr_init(struct AdsrState *adsr, struct AdsrEnvelope *envelope, UNUSED s16 *volOut) {
+void adsr_init(struct AdsrState *adsr, struct AdsrEnvelope *envelope, UNUSED s16 *volOut)
+{
adsr->action = 0;
adsr->state = ADSR_STATE_DISABLED;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
adsr->delay = 0;
adsr->envelope = envelope;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
adsr->sustain = 0.0f;
-#endif
+ #endif
adsr->current = 0.0f;
-#else
+ #else
adsr->initial = 0;
adsr->delay = 0;
adsr->velocity = 0;
adsr->envelope = envelope;
adsr->volOut = volOut;
-#endif
+ #endif
}
#if defined(VERSION_EU) || defined(VERSION_SH)
-f32 adsr_update(struct AdsrState *adsr) {
+f32 adsr_update(struct AdsrState *adsr)
+{
+
+
#else
-s32 adsr_update(struct AdsrState *adsr) {
-#endif
+s32 adsr_update(struct AdsrState *adsr)
+{
+ #endif
u8 action = adsr->action;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
u8 state = adsr->state;
switch (state) {
-#else
- switch (adsr->state) {
-#endif
+ #else
+ switch (adsr->state)
+ {
+ #endif
case ADSR_STATE_DISABLED:
return 0;
- case ADSR_STATE_INITIAL: {
-#if defined(VERSION_JP) || defined(VERSION_US)
+ case ADSR_STATE_INITIAL:
+ {
+ #if defined(VERSION_JP) || defined(VERSION_US)
adsr->current = adsr->initial;
adsr->target = adsr->initial;
-#endif
- if (action & ADSR_ACTION_HANG) {
+ #endif
+ if (action & ADSR_ACTION_HANG)
+ {
adsr->state = ADSR_STATE_HANG;
break;
}
@@ -392,18 +459,19 @@ s32 adsr_update(struct AdsrState *adsr) {
case ADSR_STATE_START_LOOP:
adsr->envIndex = 0;
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #if defined(VERSION_JP) || defined(VERSION_US)
adsr->currentHiRes = adsr->current << 0x10;
-#endif
+ #endif
adsr->state = ADSR_STATE_LOOP;
// fallthrough
-#ifdef VERSION_SH
- restart:
-#endif
+ #ifdef VERSION_SH
+ restart:
+ #endif
case ADSR_STATE_LOOP:
adsr->delay = BSWAP16(adsr->envelope[adsr->envIndex].delay);
- switch (adsr->delay) {
+ switch (adsr->delay)
+ {
case ADSR_DISABLE:
adsr->state = ADSR_STATE_DISABLED;
break;
@@ -412,134 +480,149 @@ s32 adsr_update(struct AdsrState *adsr) {
break;
case ADSR_GOTO:
adsr->envIndex = BSWAP16(adsr->envelope[adsr->envIndex].arg);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
goto restart;
-#else
+ #else
break;
-#endif
+ #endif
case ADSR_RESTART:
adsr->state = ADSR_STATE_INITIAL;
break;
default:
-#if defined(VERSION_EU) || defined(VERSION_SH)
- if (adsr->delay >= 4) {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ if (adsr->delay >= 4)
+ {
adsr->delay = adsr->delay * gAudioBufferParameters.updatesPerFrame
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
/ gAudioBufferParameters.presetUnk4
-#endif
+ #endif
/ 4;
}
-#if defined(VERSION_SH)
- if (adsr->delay == 0) {
+ #if defined(VERSION_SH)
+ if (adsr->delay == 0)
+ {
adsr->delay = 1;
}
- adsr->target = (f32) BSWAP16(adsr->envelope[adsr->envIndex].arg) / 32767.0f;
-#elif defined(VERSION_EU)
- adsr->target = (f32) BSWAP16(adsr->envelope[adsr->envIndex].arg) / 32767.0;
-#endif
+ adsr->target = (f32)BSWAP16(adsr->envelope[adsr->envIndex].arg) / 32767.0f;
+ #elif defined(VERSION_EU)
+ adsr->target = (f32)BSWAP16(adsr->envelope[adsr->envIndex].arg) / 32767.0;
+ #endif
adsr->target = adsr->target * adsr->target;
adsr->velocity = (adsr->target - adsr->current) / adsr->delay;
-#else
+ #else
adsr->target = BSWAP16(adsr->envelope[adsr->envIndex].arg);
adsr->velocity = ((adsr->target - adsr->current) << 0x10) / adsr->delay;
-#endif
+ #endif
adsr->state = ADSR_STATE_FADE;
adsr->envIndex++;
break;
}
- if (adsr->state != ADSR_STATE_FADE) {
+ if (adsr->state != ADSR_STATE_FADE)
+ {
break;
}
- // fallthrough
+ // fallthrough
case ADSR_STATE_FADE:
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
adsr->current += adsr->velocity;
-#else
+ #else
adsr->currentHiRes += adsr->velocity;
adsr->current = adsr->currentHiRes >> 0x10;
-#endif
- if (--adsr->delay <= 0) {
+ #endif
+ if (--adsr->delay <= 0)
+ {
adsr->state = ADSR_STATE_LOOP;
}
- // fallthrough
+ // fallthrough
case ADSR_STATE_HANG:
break;
case ADSR_STATE_DECAY:
- case ADSR_STATE_RELEASE: {
+ case ADSR_STATE_RELEASE:
+ {
adsr->current -= adsr->fadeOutVel;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
if (adsr->sustain != 0.0f && state == ADSR_STATE_DECAY) {
-#else
- if (adsr->sustain != 0 && adsr->state == ADSR_STATE_DECAY) {
-#endif
- if (adsr->current < adsr->sustain) {
+ #else
+ if (adsr->sustain != 0 && adsr->state == ADSR_STATE_DECAY)
+ {
+ #endif
+ if (adsr->current < adsr->sustain)
+ {
adsr->current = adsr->sustain;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
adsr->delay = 128;
-#else
+ #else
adsr->delay = adsr->sustain / 16;
-#endif
+ #endif
adsr->state = ADSR_STATE_SUSTAIN;
}
break;
}
-#if defined(VERSION_SH)
- if (adsr->current < 0.00001f) {
+ #if defined(VERSION_SH)
+ if (adsr->current < 0.00001f)
+ {
adsr->current = 0.0f;
adsr->state = ADSR_STATE_DISABLED;
}
-#elif defined(VERSION_EU)
- if (adsr->current < 0) {
+ #elif defined(VERSION_EU)
+ if (adsr->current < 0)
+ {
adsr->current = 0.0f;
adsr->state = ADSR_STATE_DISABLED;
}
-#else
- if (adsr->current < 100) {
+ #else
+ if (adsr->current < 100)
+ {
adsr->current = 0;
adsr->state = ADSR_STATE_DISABLED;
}
-#endif
+ #endif
break;
}
case ADSR_STATE_SUSTAIN:
adsr->delay -= 1;
- if (adsr->delay == 0) {
+ if (adsr->delay == 0)
+ {
adsr->state = ADSR_STATE_RELEASE;
}
break;
}
- if ((action & ADSR_ACTION_DECAY)) {
+ if (action & ADSR_ACTION_DECAY)
+ {
adsr->state = ADSR_STATE_DECAY;
adsr->action = action & ~ADSR_ACTION_DECAY;
}
- if ((action & ADSR_ACTION_RELEASE)) {
+ if (action & ADSR_ACTION_RELEASE)
+ {
adsr->state = ADSR_STATE_RELEASE;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
adsr->action = action & ~ADSR_ACTION_RELEASE;
-#else
+ #else
adsr->action = action & ~(ADSR_ACTION_RELEASE | ADSR_ACTION_DECAY);
-#endif
+ #endif
}
-#if defined(VERSION_EU) || defined(VERSION_SH)
- if (adsr->current < 0.0f) {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ if (adsr->current < 0.0f)
+ {
return 0.0f;
}
- if (adsr->current > 1.0f) {
+ if (adsr->current > 1.0f)
+ {
eu_stubbed_printf_1("Audio:Envp: overflow %f\n", adsr->current);
return 1.0f;
}
return adsr->current;
-#else
+ #else
*adsr->volOut = adsr->current;
return 0;
-#endif
+ #endif
}
diff --git a/src/decomp/audio/effects.h b/src/decomp/audio/effects.h
index 56709e8..e705fbc 100644
--- a/src/decomp/audio/effects.h
+++ b/src/decomp/audio/effects.h
@@ -36,8 +36,11 @@
extern f32 gTrackVolume;
void sequence_player_process_sound(struct SequencePlayer *seqPlayer);
+
void note_vibrato_update(struct Note *note);
+
void note_vibrato_init(struct Note *note);
+
void adsr_init(struct AdsrState *adsr, struct AdsrEnvelope *envelope, s16 *volOut);
#if defined(VERSION_EU) || defined(VERSION_SH)
f32 adsr_update(struct AdsrState *adsr);
diff --git a/src/decomp/audio/external.c b/src/decomp/audio/external.c
index 0d525cd..f872d51 100644
--- a/src/decomp/audio/external.c
+++ b/src/decomp/audio/external.c
@@ -35,14 +35,16 @@
#define SAMPLES_TO_OVERPRODUCE 0x10
#define EXTRA_BUFFERED_AI_SAMPLES_TARGET 0x40
-struct ChannelVolumeScaleFade {
+struct ChannelVolumeScaleFade
+{
f32 velocity;
u8 target;
f32 current;
u16 remainingFrames;
}; // size = 0x10
-struct SoundCharacteristics {
+struct SoundCharacteristics
+{
f32 *x;
f32 *y;
f32 *z;
@@ -58,7 +60,8 @@ struct SoundCharacteristics {
// Also the number of frames a discrete sound can be in the WAITING state before being deleted
#define SOUND_MAX_FRESHNESS 10
-struct SequenceQueueItem {
+struct SequenceQueueItem
+{
u8 seqId;
u8 priority;
}; // size = 0x2
@@ -101,23 +104,23 @@ u8 gAudioReverb = 0.0f;
u8 sDialogSpeaker[] = {
// 0 1 2 3 4 5 6 7 8 9
- /* 0*/ _, BOMB, BOMB, BOMB, BOMB, KOOPA, KOOPA, KOOPA, _, KOOPA,
- /* 1*/ _, _, _, _, _, _, _, KBOMB, _, _,
- /* 2*/ _, BOWS1, BOWS1, BOWS1, BOWS1, BOWS1, BOWS1, BOWS1, BOWS1, BOWS1,
- /* 3*/ _, _, _, _, _, _, _, DIFF, _, _,
- /* 4*/ _, KOOPA, _, _, _, _, _, BOMB, _, _,
- /* 5*/ _, _, _, _, _, TUXIE, TUXIE, TUXIE, TUXIE, TUXIE,
- /* 6*/ _, _, _, _, _, _, _, BOWS2, _, _,
- /* 7*/ _, _, _, _, _, _, _, _, _, UKIKI,
- /* 8*/ UKIKI, _, _, _, _, BOO, _, _, _, _,
- /* 9*/ BOWS2, _, BOWS2, BOWS2, _, _, _, _, BOO, BOO,
- /*10*/ UKIKI, UKIKI, _, _, _, BOMB, BOMB, BOO, BOO, _,
- /*11*/ _, _, _, _, GRUNT, GRUNT, KBOMB, GRUNT, GRUNT, _,
- /*12*/ _, _, _, _, _, _, _, _, KBOMB, _,
- /*13*/ _, _, TUXIE, _, _, _, _, _, _, _,
- /*14*/ _, _, _, _, _, _, _, _, _, _,
- /*15*/ WIGLR, WIGLR, WIGLR, _, _, _, _, _, _, _,
- /*16*/ _, YOSHI, _, _, _, _, _, _, WIGLR, _
+ /* 0*/ _, BOMB, BOMB, BOMB, BOMB, KOOPA, KOOPA, KOOPA, _, KOOPA,
+ /* 1*/ _, _, _, _, _, _, _, KBOMB, _, _,
+ /* 2*/ _, BOWS1, BOWS1, BOWS1, BOWS1, BOWS1, BOWS1, BOWS1, BOWS1, BOWS1,
+ /* 3*/ _, _, _, _, _, _, _, DIFF, _, _,
+ /* 4*/ _, KOOPA, _, _, _, _, _, BOMB, _, _,
+ /* 5*/ _, _, _, _, _, TUXIE, TUXIE, TUXIE, TUXIE, TUXIE,
+ /* 6*/ _, _, _, _, _, _, _, BOWS2, _, _,
+ /* 7*/ _, _, _, _, _, _, _, _, _, UKIKI,
+ /* 8*/ UKIKI, _, _, _, _, BOO, _, _, _, _,
+ /* 9*/ BOWS2, _, BOWS2, BOWS2, _, _, _, _, BOO, BOO,
+ /*10*/ UKIKI, UKIKI, _, _, _, BOMB, BOMB, BOO, BOO, _,
+ /*11*/ _, _, _, _, GRUNT, GRUNT, KBOMB, GRUNT, GRUNT, _,
+ /*12*/ _, _, _, _, _, _, _, _, KBOMB, _,
+ /*13*/ _, _, TUXIE, _, _, _, _, _, _, _,
+ /*14*/ _, _, _, _, _, _, _, _, _, _,
+ /*15*/ WIGLR, WIGLR, WIGLR, _, _, _, _, _, _, _,
+ /*16*/ _, YOSHI, _, _, _, _, _, _, WIGLR, _
};
#undef _
@@ -133,12 +136,12 @@ s32 sDialogSpeakerVoice[] = {
SOUND_OBJ2_BOSS_DIALOG_GRUNT,
SOUND_OBJ_WIGGLER_TALK,
SOUND_GENERAL_YOSHI_TALK,
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #if defined(VERSION_JP) || defined(VERSION_US)
NO_SOUND,
NO_SOUND,
NO_SOUND,
NO_SOUND,
-#endif
+ #endif
};
u8 sNumProcessedSoundRequests = 0;
@@ -179,7 +182,7 @@ s16 sDynUnk38[] = {
DYN1(MARIO_IS_IN_AREA, 3, 7),
0,
};
-s16 sDynNone[] = { SEQ_SOUND_PLAYER, 0 };
+s16 sDynNone[] = {SEQ_SOUND_PLAYER, 0};
u8 sCurrentMusicDynamic = 0xff;
u8 sBackgroundMusicForDynamics = SEQUENCE_NONE;
@@ -195,31 +198,38 @@ s16 *sLevelDynamics[LEVEL_COUNT] = {
#undef STUB_LEVEL
#undef DEFINE_LEVEL
-struct MusicDynamic {
- /*0x0*/ s16 bits1;
- /*0x2*/ u16 volScale1;
- /*0x4*/ s16 dur1;
- /*0x6*/ s16 bits2;
- /*0x8*/ u16 volScale2;
- /*0xA*/ s16 dur2;
+struct MusicDynamic
+{
+ /*0x0*/
+ s16 bits1;
+ /*0x2*/
+ u16 volScale1;
+ /*0x4*/
+ s16 dur1;
+ /*0x6*/
+ s16 bits2;
+ /*0x8*/
+ u16 volScale2;
+ /*0xA*/
+ s16 dur2;
}; // size = 0xC
struct MusicDynamic sMusicDynamics[8] = {
- { 0x0000, 127, 100, 0x0e43, 0, 100 }, // SEQ_LEVEL_WATER
- { 0x0003, 127, 100, 0x0e40, 0, 100 }, // SEQ_LEVEL_WATER
- { 0x0e43, 127, 200, 0x0000, 0, 200 }, // SEQ_LEVEL_WATER
- { 0x02ff, 127, 100, 0x0100, 0, 100 }, // SEQ_LEVEL_UNDERGROUND
- { 0x03f7, 127, 100, 0x0008, 0, 100 }, // SEQ_LEVEL_UNDERGROUND
- { 0x0070, 127, 10, 0x0000, 0, 100 }, // SEQ_LEVEL_SPOOKY
- { 0x0000, 127, 100, 0x0070, 0, 10 }, // SEQ_LEVEL_SPOOKY
- { 0xffff, 127, 100, 0x0000, 0, 100 }, // any (unused)
+ {0x0000, 127, 100, 0x0e43, 0, 100}, // SEQ_LEVEL_WATER
+ {0x0003, 127, 100, 0x0e40, 0, 100}, // SEQ_LEVEL_WATER
+ {0x0e43, 127, 200, 0x0000, 0, 200}, // SEQ_LEVEL_WATER
+ {0x02ff, 127, 100, 0x0100, 0, 100}, // SEQ_LEVEL_UNDERGROUND
+ {0x03f7, 127, 100, 0x0008, 0, 100}, // SEQ_LEVEL_UNDERGROUND
+ {0x0070, 127, 10, 0x0000, 0, 100}, // SEQ_LEVEL_SPOOKY
+ {0x0000, 127, 100, 0x0070, 0, 10}, // SEQ_LEVEL_SPOOKY
+ {0xffff, 127, 100, 0x0000, 0, 100}, // any (unused)
};
#define STUB_LEVEL(_0, _1, _2, _3, echo1, echo2, echo3, _7, _8) { echo1, echo2, echo3 },
#define DEFINE_LEVEL(_0, _1, _2, _3, _4, _5, echo1, echo2, echo3, _9, _10) { echo1, echo2, echo3 },
u8 sLevelAreaReverbs[LEVEL_COUNT][3] = {
- { 0x00, 0x00, 0x00 }, // LEVEL_NONE
+ {0x00, 0x00, 0x00}, // LEVEL_NONE
};
#undef STUB_LEVEL
#undef DEFINE_LEVEL
@@ -253,51 +263,56 @@ u16 sLevelAcousticReaches[LEVEL_COUNT] = {
// Default volume for background music sequences (playing on player 0).
u8 sBackgroundMusicDefaultVolume[] = {
127, // SEQ_SOUND_PLAYER
- 80, // SEQ_EVENT_CUTSCENE_COLLECT_STAR
- 80, // SEQ_MENU_TITLE_SCREEN
- 75, // SEQ_LEVEL_GRASS
- 70, // SEQ_LEVEL_INSIDE_CASTLE
- 75, // SEQ_LEVEL_WATER
- 75, // SEQ_LEVEL_HOT
- 75, // SEQ_LEVEL_BOSS_KOOPA
- 70, // SEQ_LEVEL_SNOW
- 65, // SEQ_LEVEL_SLIDE
- 80, // SEQ_LEVEL_SPOOKY
- 65, // SEQ_EVENT_PIRANHA_PLANT
- 85, // SEQ_LEVEL_UNDERGROUND
- 75, // SEQ_MENU_STAR_SELECT
- 65, // SEQ_EVENT_POWERUP
- 70, // SEQ_EVENT_METAL_CAP
- 65, // SEQ_EVENT_KOOPA_MESSAGE
- 70, // SEQ_LEVEL_KOOPA_ROAD
- 70, // SEQ_EVENT_HIGH_SCORE
- 65, // SEQ_EVENT_MERRY_GO_ROUND
- 80, // SEQ_EVENT_RACE
- 70, // SEQ_EVENT_CUTSCENE_STAR_SPAWN
- 85, // SEQ_EVENT_BOSS
- 75, // SEQ_EVENT_CUTSCENE_COLLECT_KEY
- 75, // SEQ_EVENT_ENDLESS_STAIRS
- 85, // SEQ_LEVEL_BOSS_KOOPA_FINAL
- 70, // SEQ_EVENT_CUTSCENE_CREDITS
- 80, // SEQ_EVENT_SOLVE_PUZZLE
- 80, // SEQ_EVENT_TOAD_MESSAGE
- 70, // SEQ_EVENT_PEACH_MESSAGE
- 75, // SEQ_EVENT_CUTSCENE_INTRO
- 80, // SEQ_EVENT_CUTSCENE_VICTORY
- 70, // SEQ_EVENT_CUTSCENE_ENDING
- 65, // SEQ_MENU_FILE_SELECT
- 0, // SEQ_EVENT_CUTSCENE_LAKITU (not in JP)
+ 80, // SEQ_EVENT_CUTSCENE_COLLECT_STAR
+ 80, // SEQ_MENU_TITLE_SCREEN
+ 75, // SEQ_LEVEL_GRASS
+ 70, // SEQ_LEVEL_INSIDE_CASTLE
+ 75, // SEQ_LEVEL_WATER
+ 75, // SEQ_LEVEL_HOT
+ 75, // SEQ_LEVEL_BOSS_KOOPA
+ 70, // SEQ_LEVEL_SNOW
+ 65, // SEQ_LEVEL_SLIDE
+ 80, // SEQ_LEVEL_SPOOKY
+ 65, // SEQ_EVENT_PIRANHA_PLANT
+ 85, // SEQ_LEVEL_UNDERGROUND
+ 75, // SEQ_MENU_STAR_SELECT
+ 65, // SEQ_EVENT_POWERUP
+ 70, // SEQ_EVENT_METAL_CAP
+ 65, // SEQ_EVENT_KOOPA_MESSAGE
+ 70, // SEQ_LEVEL_KOOPA_ROAD
+ 70, // SEQ_EVENT_HIGH_SCORE
+ 65, // SEQ_EVENT_MERRY_GO_ROUND
+ 80, // SEQ_EVENT_RACE
+ 70, // SEQ_EVENT_CUTSCENE_STAR_SPAWN
+ 85, // SEQ_EVENT_BOSS
+ 75, // SEQ_EVENT_CUTSCENE_COLLECT_KEY
+ 75, // SEQ_EVENT_ENDLESS_STAIRS
+ 85, // SEQ_LEVEL_BOSS_KOOPA_FINAL
+ 70, // SEQ_EVENT_CUTSCENE_CREDITS
+ 80, // SEQ_EVENT_SOLVE_PUZZLE
+ 80, // SEQ_EVENT_TOAD_MESSAGE
+ 70, // SEQ_EVENT_PEACH_MESSAGE
+ 75, // SEQ_EVENT_CUTSCENE_INTRO
+ 80, // SEQ_EVENT_CUTSCENE_VICTORY
+ 70, // SEQ_EVENT_CUTSCENE_ENDING
+ 65, // SEQ_MENU_FILE_SELECT
+ 0, // SEQ_EVENT_CUTSCENE_LAKITU (not in JP)
};
-STATIC_ASSERT(ARRAY_COUNT(sBackgroundMusicDefaultVolume) == SEQ_COUNT,
- "change this array if you are adding sequences");
+STATIC_ASSERT (ARRAY_COUNT
+(sBackgroundMusicDefaultVolume)
+==
+SEQ_COUNT
+,
+"change this array if you are adding sequences"
+);
u8 sCurrentBackgroundMusicSeqId = SEQUENCE_NONE;
u8 sMusicDynamicDelay = 0;
-u8 sSoundBankUsedListBack[SOUND_BANK_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-u8 sSoundBankFreeListFront[SOUND_BANK_COUNT] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
-u8 sNumSoundsInBank[SOUND_BANK_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // only used for debugging
-u8 sMaxChannelsForSoundBank[SOUND_BANK_COUNT] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
+u8 sSoundBankUsedListBack[SOUND_BANK_COUNT] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+u8 sSoundBankFreeListFront[SOUND_BANK_COUNT] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
+u8 sNumSoundsInBank[SOUND_BANK_COUNT] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // only used for debugging
+u8 sMaxChannelsForSoundBank[SOUND_BANK_COUNT] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
// Banks 2 and 7 both grew from 0x30 sounds to 0x40 in size in US.
#ifdef VERSION_JP
@@ -316,13 +331,13 @@ u8 sNumSoundsPerBank[SOUND_BANK_COUNT] = {
#define TARGET_VOLUME_VALUE_MASK 0x7f
#define TARGET_VOLUME_UNSET 0x00
-f32 gGlobalSoundSource[3] = { 0.0f, 0.0f, 0.0f };
-f32 sUnusedSoundArgs[3] = { 1.0f, 1.0f, 1.0f };
-u8 sSoundBankDisabled[16] = { 0 };
+f32 gGlobalSoundSource[3] = {0.0f, 0.0f, 0.0f};
+f32 sUnusedSoundArgs[3] = {1.0f, 1.0f, 1.0f};
+u8 sSoundBankDisabled[16] = {0};
u8 D_80332108 = 0;
u8 sHasStartedFadeOut = FALSE;
u16 sSoundBanksThatLowerBackgroundMusic = 0;
-u8 sUnused80332114 = 0; // never read, set to 0
+u8 sUnused80332114 = 0; // never read, set to 0
u16 sUnused80332118 = 0; // never read, set to 0
u8 sBackgroundMusicMaxTargetVolume = TARGET_VOLUME_UNSET;
u8 D_80332120 = 0;
@@ -388,7 +403,7 @@ struct EuAudioCmd sAudioCmd[0x100];
OSMesg OSMesg0;
s32 pad1; // why is there 1 s32 here
OSMesg OSMesg1;
-s32 pad2[2]; // it's not just that the struct is bigger than we think, because there are 2 here
+s32 pad2[2]; // it's not just that the struct is bigger than we think, because there are 2 here
OSMesg OSMesg2; // and none here. wth nintendo
OSMesg OSMesg3;
#else // VERSION_SH
@@ -404,18 +419,26 @@ typedef s32 FadeT;
// some sort of main thread -> sound thread dispatchers
extern void func_802ad728(u32 bits, f32 arg);
+
extern void func_802ad74c(u32 bits, u32 arg);
+
extern void func_802ad770(u32 bits, s8 arg);
static void update_background_music_after_sound(u8 bank, u8 soundIndex);
+
void update_game_sound(void);
+
static void fade_channel_volume_scale(u8 player, u8 channelId, u8 targetScale, u16 fadeTimer);
+
void process_level_music_dynamics(void);
+
static u8 begin_background_music_fade(u16 fadeDuration);
+
void func_80320ED8(void);
#ifndef VERSION_JP
-void unused_8031E4F0(void) {
+void unused_8031E4F0(void)
+{
// This is a debug function which is almost entirely optimized away,
// except for loops, string literals, and a read of a volatile variable.
// The string literals have allowed it to be partially reconstructed.
@@ -435,7 +458,8 @@ void unused_8031E4F0(void) {
stubbed_printf("[%2x] <%5x / %5x>\n", gSeqLoadedPool.persistent.numEntries,
gSeqLoadedPool.persistent.pool.cur - gSeqLoadedPool.persistent.pool.start,
gSeqLoadedPool.persistent.pool.size);
- for (i = 0; (u32) i < gSeqLoadedPool.persistent.numEntries; i++) {
+ for (i = 0; (u32)i < gSeqLoadedPool.persistent.numEntries; i++)
+ {
stubbed_printf("%2x ", gSeqLoadedPool.persistent.entries[i].id);
}
stubbed_printf("\n");
@@ -444,7 +468,8 @@ void unused_8031E4F0(void) {
stubbed_printf("[%2x] <%5x / %5x>\n", gBankLoadedPool.persistent.numEntries,
gBankLoadedPool.persistent.pool.cur - gBankLoadedPool.persistent.pool.start,
gBankLoadedPool.persistent.pool.size);
- for (i = 0; (u32) i < gBankLoadedPool.persistent.numEntries; i++) {
+ for (i = 0; (u32)i < gBankLoadedPool.persistent.numEntries; i++)
+ {
stubbed_printf("%2x ", gBankLoadedPool.persistent.entries[i].id);
}
stubbed_printf("\n\n");
@@ -454,13 +479,15 @@ void unused_8031E4F0(void) {
// gSeqLoadStatus/gBankLoadStatus, 4 entries at a time?
stubbed_printf("SEQ ");
- for (i = 0; i < 40; i++) {
+ for (i = 0; i < 40; i++)
+ {
stubbed_printf("%1x", 0);
}
stubbed_printf("\n");
stubbed_printf("BNK ");
- for (i = 0; i < 40; i += 4) {
+ for (i = 0; i < 40; i += 4)
+ {
stubbed_printf("%1x", 0);
}
stubbed_printf("\n");
@@ -479,7 +506,8 @@ void unused_8031E4F0(void) {
stubbed_printf("DEBUGFLAG %8x\n", gAudioErrorFlags);
}
-void unused_8031E568(void) {
+void unused_8031E568(void)
+{
stubbed_printf("COUNT %8d\n", gAudioFrameCount);
}
#endif
@@ -494,21 +522,22 @@ const char unusedErrorStr2[] = "specchg error\n";
* Called from threads: thread5_game_loop
*/
#if defined(VERSION_EU) || defined(VERSION_SH)
-void audio_reset_session_eu(s32 presetId) {
+void audio_reset_session_eu(s32 presetId)
+{
OSMesg mesg;
#ifdef VERSION_SH
- osRecvMesg(D_SH_80350FA8, &mesg, OS_MESG_NOBLOCK);
- osSendMesg(D_SH_80350F88, (OSMesg) presetId, OS_MESG_NOBLOCK);
- osRecvMesg(D_SH_80350FA8, &mesg, OS_MESG_BLOCK);
- if ((s32) mesg != presetId) {
+osRecvMesg(D_SH_80350FA8, &mesg, OS_MESG_NOBLOCK);
+osSendMesg(D_SH_80350F88, (OSMesg)presetId, OS_MESG_NOBLOCK);
+osRecvMesg(D_SH_80350FA8, &mesg, OS_MESG_BLOCK);
+ if ((s32) mesg!= presetId) {
osRecvMesg(D_SH_80350FA8, &mesg, OS_MESG_BLOCK);
}
#else
- osRecvMesg(OSMesgQueues[3], &mesg, OS_MESG_NOBLOCK);
- osSendMesg(OSMesgQueues[2], (OSMesg) presetId, OS_MESG_NOBLOCK);
- osRecvMesg(OSMesgQueues[3], &mesg, OS_MESG_BLOCK);
- if ((s32) mesg != presetId) {
+osRecvMesg (OSMesgQueues[3], &mesg, OS_MESG_NOBLOCK);
+osSendMesg (OSMesgQueues[2], (OSMesg) presetId, OS_MESG_NOBLOCK);
+osRecvMesg (OSMesgQueues[3], &mesg, OS_MESG_BLOCK);
+ if ((s32) mesg!= presetId) {
osRecvMesg(OSMesgQueues[3], &mesg, OS_MESG_BLOCK);
}
#endif
@@ -519,28 +548,31 @@ void audio_reset_session_eu(s32 presetId) {
/**
* Called from threads: thread3_main, thread5_game_loop
*/
-static void seq_player_fade_to_zero_volume(s32 player, FadeT fadeDuration) {
+static void seq_player_fade_to_zero_volume(s32 player, FadeT fadeDuration)
+{
struct SequencePlayer *seqPlayer = &gSequencePlayers[player];
#ifndef VERSION_JP
- // fadeDuration is never 0 in practice
- if (fadeDuration == 0) {
+// fadeDuration is never 0 in practice
+if (fadeDuration== 0) {
fadeDuration++;
}
#endif
- seqPlayer->fadeVelocity = -(seqPlayer->fadeVolume / fadeDuration);
- seqPlayer->state = SEQUENCE_PLAYER_STATE_FADE_OUT;
- seqPlayer->fadeRemainingFrames = fadeDuration;
+seqPlayer->fadeVelocity=-(seqPlayer->fadeVolume/ fadeDuration);
+seqPlayer->state= SEQUENCE_PLAYER_STATE_FADE_OUT;
+seqPlayer->fadeRemainingFrames= fadeDuration;
}
/**
* Called from threads: thread4_sound, thread5_game_loop
*/
-static void func_8031D690(s32 player, FadeT fadeInTime) {
+static void func_8031D690(s32 player, FadeT fadeInTime)
+{
struct SequencePlayer *seqPlayer = &gSequencePlayers[player];
- if (fadeInTime == 0 || seqPlayer->state == SEQUENCE_PLAYER_STATE_FADE_OUT) {
+ if (fadeInTime == 0 || seqPlayer->state == SEQUENCE_PLAYER_STATE_FADE_OUT)
+ {
return;
}
@@ -554,34 +586,38 @@ static void func_8031D690(s32 player, FadeT fadeInTime) {
/**
* Called from threads: thread5_game_loop
*/
-static void seq_player_fade_to_percentage_of_volume(s32 player, FadeT fadeDuration, u8 percentage) {
+static void seq_player_fade_to_percentage_of_volume(s32 player, FadeT fadeDuration, u8 percentage)
+{
struct SequencePlayer *seqPlayer = &gSequencePlayers[player];
f32 targetVolume;
-#if defined(VERSION_EU) || defined(VERSION_SH)
- if (seqPlayer->state == 2) {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ if (seqPlayer->state == 2)
+ {
return;
}
-#else
- if (seqPlayer->state == SEQUENCE_PLAYER_STATE_FADE_OUT) {
+ #else
+ if (seqPlayer->state == SEQUENCE_PLAYER_STATE_FADE_OUT)
+ {
return;
}
-#endif
+ #endif
- targetVolume = (FLOAT_CAST(percentage) / EU_FLOAT(100.0)) * seqPlayer->fadeVolume;
+ targetVolume = FLOAT_CAST(percentage) / EU_FLOAT(100.0) * seqPlayer->fadeVolume;
seqPlayer->volume = seqPlayer->fadeVolume;
seqPlayer->fadeRemainingFrames = 0;
- if (fadeDuration == 0) {
+ if (fadeDuration == 0)
+ {
seqPlayer->fadeVolume = targetVolume;
return;
}
seqPlayer->fadeVelocity = (targetVolume - seqPlayer->fadeVolume) / fadeDuration;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
seqPlayer->state = 0;
-#else
+ #else
seqPlayer->state = SEQUENCE_PLAYER_STATE_4;
-#endif
+ #endif
seqPlayer->fadeRemainingFrames = fadeDuration;
}
@@ -589,30 +625,34 @@ static void seq_player_fade_to_percentage_of_volume(s32 player, FadeT fadeDurati
/**
* Called from threads: thread3_main, thread4_sound, thread5_game_loop
*/
-static void seq_player_fade_to_normal_volume(s32 player, FadeT fadeDuration) {
+static void seq_player_fade_to_normal_volume(s32 player, FadeT fadeDuration)
+{
struct SequencePlayer *seqPlayer = &gSequencePlayers[player];
-#if defined(VERSION_EU) || defined(VERSION_SH)
- if (seqPlayer->state == 2) {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ if (seqPlayer->state == 2)
+ {
return;
}
-#else
- if (seqPlayer->state == SEQUENCE_PLAYER_STATE_FADE_OUT) {
+ #else
+ if (seqPlayer->state == SEQUENCE_PLAYER_STATE_FADE_OUT)
+ {
return;
}
-#endif
+ #endif
seqPlayer->fadeRemainingFrames = 0;
- if (fadeDuration == 0) {
+ if (fadeDuration == 0)
+ {
seqPlayer->fadeVolume = seqPlayer->volume;
return;
}
seqPlayer->fadeVelocity = (seqPlayer->volume - seqPlayer->fadeVolume) / fadeDuration;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
seqPlayer->state = 0;
-#else
+ #else
seqPlayer->state = SEQUENCE_PLAYER_STATE_2;
-#endif
+ #endif
seqPlayer->fadeRemainingFrames = fadeDuration;
}
@@ -620,29 +660,32 @@ static void seq_player_fade_to_normal_volume(s32 player, FadeT fadeDuration) {
/**
* Called from threads: thread3_main, thread4_sound, thread5_game_loop
*/
-static void seq_player_fade_to_target_volume(s32 player, FadeT fadeDuration, u8 targetVolume) {
+static void seq_player_fade_to_target_volume(s32 player, FadeT fadeDuration, u8 targetVolume)
+{
struct SequencePlayer *seqPlayer = &gSequencePlayers[player];
-#if defined(VERSION_JP) || defined(VERSION_US)
- if (seqPlayer->state == SEQUENCE_PLAYER_STATE_FADE_OUT) {
+ #if defined(VERSION_JP) || defined(VERSION_US)
+ if (seqPlayer->state == SEQUENCE_PLAYER_STATE_FADE_OUT)
+ {
return;
}
-#endif
+ #endif
seqPlayer->fadeRemainingFrames = 0;
- if (fadeDuration == 0) {
- seqPlayer->fadeVolume = (FLOAT_CAST(targetVolume) / EU_FLOAT(127.0));
+ if (fadeDuration == 0)
+ {
+ seqPlayer->fadeVolume = FLOAT_CAST(targetVolume) / EU_FLOAT(127.0);
return;
}
seqPlayer->fadeVelocity =
- (((f32)(FLOAT_CAST(targetVolume) / EU_FLOAT(127.0)) - seqPlayer->fadeVolume)
- / (f32) fadeDuration);
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ ((f32)(FLOAT_CAST(targetVolume) / EU_FLOAT(127.0)) - seqPlayer->fadeVolume)
+ / (f32)fadeDuration;
+ #if defined(VERSION_EU) || defined(VERSION_SH)
seqPlayer->state = 0;
-#else
+ #else
seqPlayer->state = SEQUENCE_PLAYER_STATE_4;
-#endif
+ #endif
seqPlayer->fadeRemainingFrames = fadeDuration;
}
@@ -657,22 +700,25 @@ extern void func_sh_802F64C8(void);
/**
* Called from threads: thread5_game_loop
*/
-void maybe_tick_game_sound(void) {
- if (sGameLoopTicked != 0) {
+void maybe_tick_game_sound(void)
+{
+ if (sGameLoopTicked != 0)
+ {
update_game_sound();
sGameLoopTicked = 0;
}
#ifdef VERSION_EU
- func_802ad7a0();
+func_802ad7a0();
#else
- func_sh_802F64C8(); // moved in SH
+func_sh_802F64C8(); // moved in SH
#endif
}
-void func_eu_802e9bec(s32 player, s32 channel, s32 arg2) {
+void func_eu_802e9bec(s32 player, s32 channel, s32 arg2)
+{
// EU verson of unused_803209D8
// chan->stopSomething2 = arg2?
- func_802ad770(0x08000000 | (player & 0xff) << 16 | (channel & 0xff) << 8, (s8) arg2);
+ func_802ad770(0x08000000 | (player & 0xff) << 16 | (channel & 0xff) << 8, (s8)arg2);
}
#else
@@ -681,7 +727,8 @@ void func_eu_802e9bec(s32 player, s32 channel, s32 arg2) {
/**
* Called from threads: thread4_sound
*/
-struct SPTask *create_next_audio_frame_task(void) {
+struct SPTask *create_next_audio_frame_task(void)
+{
u32 samplesRemainingInAI;
s32 writtenCmds;
s32 index;
@@ -690,7 +737,8 @@ struct SPTask *create_next_audio_frame_task(void) {
s32 flags;
gAudioFrameCount++;
- if (gAudioLoadLock != AUDIO_LOCK_NOT_LOADING) {
+ if (gAudioLoadLock != AUDIO_LOCK_NOT_LOADING)
+ {
stubbed_printf("DAC:Lost 1 Frame.\n");
return NULL;
}
@@ -712,7 +760,8 @@ struct SPTask *create_next_audio_frame_task(void) {
// - the RSP is now expected to be finished, and we can send its output
// on to the AI
// Here we thus send to the AI the sound that was generated two frames ago.
- if (gAiBufferLengths[index] != 0) {
+ if (gAiBufferLengths[index] != 0)
+ {
osAiSetNextBuffer(gAiBuffers[index], gAiBufferLengths[index] * 4);
}
@@ -720,7 +769,8 @@ struct SPTask *create_next_audio_frame_task(void) {
// There has to be some sort of no-op if here, but it's not exactly clear
// how it should look... It's also very unclear why gCurrAudioFrameDmaQueue
// isn't read from here, despite gCurrAudioFrameDmaCount being reset.
- if (oldDmaCount > AUDIO_FRAME_DMA_QUEUE_SIZE) {
+ if (oldDmaCount > AUDIO_FRAME_DMA_QUEUE_SIZE)
+ {
stubbed_printf("DMA: Request queue over.( %d )\n", oldDmaCount);
}
gCurrAudioFrameDmaCount = 0;
@@ -731,16 +781,19 @@ struct SPTask *create_next_audio_frame_task(void) {
index = gCurrAiBufferIndex;
gCurrAiBuffer = gAiBuffers[index];
gAiBufferLengths[index] =
- ((gSamplesPerFrameTarget - samplesRemainingInAI + EXTRA_BUFFERED_AI_SAMPLES_TARGET) & ~0xf)
- + SAMPLES_TO_OVERPRODUCE;
- if (gAiBufferLengths[index] < gMinAiBufferLength) {
+ ((gSamplesPerFrameTarget - samplesRemainingInAI + EXTRA_BUFFERED_AI_SAMPLES_TARGET) & ~0xf)
+ + SAMPLES_TO_OVERPRODUCE;
+ if (gAiBufferLengths[index] < gMinAiBufferLength)
+ {
gAiBufferLengths[index] = gMinAiBufferLength;
}
- if (gAiBufferLengths[index] > gSamplesPerFrameTarget + SAMPLES_TO_OVERPRODUCE) {
+ if (gAiBufferLengths[index] > gSamplesPerFrameTarget + SAMPLES_TO_OVERPRODUCE)
+ {
gAiBufferLengths[index] = gSamplesPerFrameTarget + SAMPLES_TO_OVERPRODUCE;
}
- if (sGameLoopTicked != 0) {
+ if (sGameLoopTicked != 0)
+ {
update_game_sound();
sGameLoopTicked = 0;
}
@@ -759,7 +812,7 @@ struct SPTask *create_next_audio_frame_task(void) {
task->type = M_AUDTASK;
task->flags = flags;
task->ucode_boot = rspF3DBootStart;
- task->ucode_boot_size = (u8 *) rspF3DBootEnd - (u8 *) rspF3DBootStart;
+ task->ucode_boot_size = (u8 *)rspF3DBootEnd - (u8 *)rspF3DBootStart;
task->ucode = rspAspMainStart;
task->ucode_size = 0x800; // (this size is ignored)
task->ucode_data = rspAspMainDataStart;
@@ -774,29 +827,33 @@ struct SPTask *create_next_audio_frame_task(void) {
// The audio task never yields, so having a yield buffer is pointless.
// This wastefulness was fixed in US.
#ifdef VERSION_JP
- task->yield_data_ptr = (u64 *) gAudioSPTaskYieldBuffer;
- task->yield_data_size = OS_YIELD_AUDIO_SIZE;
+task->yield_data_ptr= (u64 *) gAudioSPTaskYieldBuffer;
+task->yield_data_size= OS_YIELD_AUDIO_SIZE;
#else
- task->yield_data_ptr = NULL;
- task->yield_data_size = 0;
+task->yield_data_ptr=NULL;
+task->yield_data_size=0;
#endif
- decrease_sample_dma_ttls();
+decrease_sample_dma_ttls();
return gAudioTask;
}
#else
-struct SPTask *create_next_audio_frame_task(void) {
+struct SPTask *create_next_audio_frame_task(void)
+{
return NULL;
}
-void create_next_audio_buffer(s16 *samples, u32 num_samples) {
+
+void create_next_audio_buffer(s16 *samples, u32 num_samples)
+{
gAudioFrameCount++;
- if (sGameLoopTicked != 0) {
+ if (sGameLoopTicked != 0)
+ {
update_game_sound();
sGameLoopTicked = 0;
}
s32 writtenCmds;
synthesis_execute(gAudioCmdBuffers[0], &writtenCmds, samples, num_samples);
- gAudioRandom = ((gAudioRandom + gAudioFrameCount) * gAudioFrameCount);
+ gAudioRandom = (gAudioRandom + gAudioFrameCount) * gAudioFrameCount;
decrease_sample_dma_ttls();
}
#endif
@@ -805,7 +862,8 @@ void create_next_audio_buffer(s16 *samples, u32 num_samples) {
/**
* Called from threads: thread4_sound, thread5_game_loop (EU only)
*/
-static void process_sound_request(u32 bits, f32 *pos) {
+static void process_sound_request(u32 bits, f32 *pos)
+{
u8 bank;
u8 soundIndex;
u8 counter = 0;
@@ -816,29 +874,33 @@ static void process_sound_request(u32 bits, f32 *pos) {
bank = (bits & SOUNDARGS_MASK_BANK) >> SOUNDARGS_SHIFT_BANK;
soundId = (bits & SOUNDARGS_MASK_SOUNDID) >> SOUNDARGS_SHIFT_SOUNDID;
- if (soundId >= sNumSoundsPerBank[bank] || sSoundBankDisabled[bank]) {
- //DEBUG_PRINT("process_sound_request: invalid soundId %d\n", soundId);
+ if (soundId >= sNumSoundsPerBank[bank] || sSoundBankDisabled[bank])
+ {
+ //DEBUG_PRINT("process_sound_request: invalid soundId %d\n", soundId);
return;
}
soundIndex = sSoundBanks[bank][0].next;
- while (soundIndex != 0xff && soundIndex != 0) {
- //DEBUG_PRINT("process_sound_request: soundIndex %d\n", soundIndex);
+ while (soundIndex != 0xff && soundIndex != 0)
+ {
+ //DEBUG_PRINT("process_sound_request: soundIndex %d\n", soundIndex);
// If an existing sound from the same source exists in the bank, then we should either
// interrupt that sound and replace it with the new sound, or we should drop the new sound.
- if (sSoundBanks[bank][soundIndex].x == pos) {
+ if (sSoundBanks[bank][soundIndex].x == pos)
+ {
// If the existing sound has lower or equal priority, then we should replace it.
// Otherwise the new sound will be dropped.
if ((sSoundBanks[bank][soundIndex].soundBits & SOUNDARGS_MASK_PRIORITY)
- <= (bits & SOUNDARGS_MASK_PRIORITY)) {
-
+ <= (bits & SOUNDARGS_MASK_PRIORITY))
+ {
// If the existing sound is discrete or is a different continuous sound, then
// interrupt it and play the new sound instead.
// Otherwise the new sound is continuous and equals the existing sound, so we just
// need to update the sound's freshness.
if ((sSoundBanks[bank][soundIndex].soundBits & SOUND_DISCRETE) != 0
|| (bits & SOUNDARGS_MASK_SOUNDID)
- != (sSoundBanks[bank][soundIndex].soundBits & SOUNDARGS_MASK_SOUNDID)) {
+ != (sSoundBanks[bank][soundIndex].soundBits & SOUNDARGS_MASK_SOUNDID))
+ {
update_background_music_after_sound(bank, soundIndex);
sSoundBanks[bank][soundIndex].soundBits = bits;
// In practice, the starting status is always WAITING
@@ -856,19 +918,23 @@ static void process_sound_request(u32 bits, f32 *pos) {
// Prevent allocating a new node - if the existing sound had higher piority, then the
// new sound will be dropped
soundIndex = 0;
- } else {
+ }
+ else
+ {
soundIndex = sSoundBanks[bank][soundIndex].next;
}
counter++;
}
- if (counter == 0) {
+ if (counter == 0)
+ {
sSoundMovingSpeed[bank] = 32;
}
// If free list has more than one element remaining
- if (sSoundBanks[bank][sSoundBankFreeListFront[bank]].next != 0xff && soundIndex != 0) {
- DEBUG_PRINT("process_sound_request2: soundIndex %d\n", soundIndex);
+ if (sSoundBanks[bank][sSoundBankFreeListFront[bank]].next != 0xff && soundIndex != 0)
+ {
+ DEBUG_PRINT("process_sound_request2: soundIndex %d\n", soundIndex);
// Allocate from free list
soundIndex = sSoundBankFreeListFront[bank];
@@ -897,25 +963,31 @@ static void process_sound_request(u32 bits, f32 *pos) {
*
* Called from threads: thread4_sound, thread5_game_loop (EU only)
*/
-static void process_all_sound_requests(void) {
+static void process_all_sound_requests(void)
+{
struct Sound *sound;
- while (sSoundRequestCount != sNumProcessedSoundRequests) {
+ while (sSoundRequestCount != sNumProcessedSoundRequests)
+ {
sound = &sSoundRequests[sNumProcessedSoundRequests];
process_sound_request(sound->soundBits, sound->position);
sNumProcessedSoundRequests++;
- //DEBUG_PRINT("processed sounds: %d\n", sNumProcessedSoundRequests);
+ //DEBUG_PRINT("processed sounds: %d\n", sNumProcessedSoundRequests);
}
}
/**
* Called from threads: thread4_sound, thread5_game_loop (EU only)
*/
-static void delete_sound_from_bank(u8 bank, u8 soundIndex) {
- if (sSoundBankUsedListBack[bank] == soundIndex) {
+static void delete_sound_from_bank(u8 bank, u8 soundIndex)
+{
+ if (sSoundBankUsedListBack[bank] == soundIndex)
+ {
// Remove from end of used list
sSoundBankUsedListBack[bank] = sSoundBanks[bank][soundIndex].prev;
- } else {
+ }
+ else
+ {
// Set sound.next.prev to sound.prev
sSoundBanks[bank][sSoundBanks[bank][soundIndex].next].prev = sSoundBanks[bank][soundIndex].prev;
}
@@ -933,9 +1005,11 @@ static void delete_sound_from_bank(u8 bank, u8 soundIndex) {
/**
* Called from threads: thread3_main, thread4_sound, thread5_game_loop
*/
-static void update_background_music_after_sound(u8 bank, u8 soundIndex) {
- if (sSoundBanks[bank][soundIndex].soundBits & SOUND_LOWER_BACKGROUND_MUSIC) {
- sSoundBanksThatLowerBackgroundMusic &= (1 << bank) ^ 0xffff;
+static void update_background_music_after_sound(u8 bank, u8 soundIndex)
+{
+ if (sSoundBanks[bank][soundIndex].soundBits & SOUND_LOWER_BACKGROUND_MUSIC)
+ {
+ sSoundBanksThatLowerBackgroundMusic &= 1 << bank ^ 0xffff;
begin_background_music_fade(50);
}
}
@@ -943,20 +1017,27 @@ static void update_background_music_after_sound(u8 bank, u8 soundIndex) {
/**
* Called from threads: thread4_sound, thread5_game_loop (EU only)
*/
-static void select_current_sounds(u8 bank) {
+static void select_current_sounds(u8 bank)
+{
u32 isDiscreteAndStatus;
u8 latestSoundIndex;
u8 i;
u8 j;
u8 soundIndex;
- u32 liveSoundPriorities[16] = { 0x10000000, 0x10000000, 0x10000000, 0x10000000,
- 0x10000000, 0x10000000, 0x10000000, 0x10000000,
- 0x10000000, 0x10000000, 0x10000000, 0x10000000,
- 0x10000000, 0x10000000, 0x10000000, 0x10000000 };
- u8 liveSoundIndices[16] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
- u8 liveSoundStatuses[16] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+ u32 liveSoundPriorities[16] = {
+ 0x10000000, 0x10000000, 0x10000000, 0x10000000,
+ 0x10000000, 0x10000000, 0x10000000, 0x10000000,
+ 0x10000000, 0x10000000, 0x10000000, 0x10000000,
+ 0x10000000, 0x10000000, 0x10000000, 0x10000000
+ };
+ u8 liveSoundIndices[16] = {
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+ };
+ u8 liveSoundStatuses[16] = {
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+ };
u8 numSoundsInBank = 0;
u8 requestedPriority;
@@ -964,21 +1045,26 @@ static void select_current_sounds(u8 bank) {
// Delete stale sounds and prioritize remaining sounds into the liveSound arrays
//
soundIndex = sSoundBanks[bank][0].next;
- while (soundIndex != 0xff) {
+ while (soundIndex != 0xff)
+ {
latestSoundIndex = soundIndex;
// If a discrete sound goes 10 frames without being played (because it is too low
// priority), then mark it for deletion
if ((sSoundBanks[bank][soundIndex].soundBits & (SOUND_DISCRETE | SOUNDARGS_MASK_STATUS))
- == (SOUND_DISCRETE | SOUND_STATUS_WAITING)) {
- if (sSoundBanks[bank][soundIndex].freshness-- == 0) {
+ == (SOUND_DISCRETE | SOUND_STATUS_WAITING))
+ {
+ if (sSoundBanks[bank][soundIndex].freshness-- == 0)
+ {
sSoundBanks[bank][soundIndex].soundBits = NO_SOUND;
}
}
// If a continuous sound goes 2 frames without play_sound being called, then mark it for
// deletion
- else if ((sSoundBanks[bank][soundIndex].soundBits & SOUND_DISCRETE) == 0) {
- if (sSoundBanks[bank][soundIndex].freshness-- == SOUND_MAX_FRESHNESS - 2) {
+ else if ((sSoundBanks[bank][soundIndex].soundBits & SOUND_DISCRETE) == 0)
+ {
+ if (sSoundBanks[bank][soundIndex].freshness-- == SOUND_MAX_FRESHNESS - 2)
+ {
update_background_music_after_sound(bank, soundIndex);
sSoundBanks[bank][soundIndex].soundBits = NO_SOUND;
}
@@ -986,7 +1072,8 @@ static void select_current_sounds(u8 bank) {
// If a sound was marked for deletion and hasn't started playing yet, delete it now
if (sSoundBanks[bank][soundIndex].soundBits == NO_SOUND
- && sSoundBanks[bank][soundIndex].soundStatus == SOUND_STATUS_WAITING) {
+ && sSoundBanks[bank][soundIndex].soundStatus == SOUND_STATUS_WAITING)
+ {
// Since the current sound will be deleted, the next iteration should process
// sound.prev.next
latestSoundIndex = sSoundBanks[bank][soundIndex].prev;
@@ -997,14 +1084,14 @@ static void select_current_sounds(u8 bank) {
// If the current sound was not just deleted, consider it as a candidate for the currently
// playing sound
if (sSoundBanks[bank][soundIndex].soundStatus != SOUND_STATUS_STOPPED
- && soundIndex == latestSoundIndex) {
-
+ && soundIndex == latestSoundIndex)
+ {
// Recompute distance each frame since the sound's position may have changed
sSoundBanks[bank][soundIndex].distance =
- sqrtf((*sSoundBanks[bank][soundIndex].x * *sSoundBanks[bank][soundIndex].x)
- + (*sSoundBanks[bank][soundIndex].y * *sSoundBanks[bank][soundIndex].y)
- + (*sSoundBanks[bank][soundIndex].z * *sSoundBanks[bank][soundIndex].z))
- * 1;
+ sqrtf(*sSoundBanks[bank][soundIndex].x * *sSoundBanks[bank][soundIndex].x
+ + *sSoundBanks[bank][soundIndex].y * *sSoundBanks[bank][soundIndex].y
+ + *sSoundBanks[bank][soundIndex].z * *sSoundBanks[bank][soundIndex].z)
+ * 1;
requestedPriority = (sSoundBanks[bank][soundIndex].soundBits & SOUNDARGS_MASK_PRIORITY)
>> SOUNDARGS_SHIFT_PRIORITY;
@@ -1013,27 +1100,35 @@ static void select_current_sounds(u8 bank) {
// camera.
// (Note that the sound's priority is the opposite of requestedPriority; lower is
// more important)
- if (sSoundBanks[bank][soundIndex].soundBits & SOUND_NO_PRIORITY_LOSS) {
+ if (sSoundBanks[bank][soundIndex].soundBits & SOUND_NO_PRIORITY_LOSS)
+ {
sSoundBanks[bank][soundIndex].priority = 0x4c * (0xff - requestedPriority);
- } else if (*sSoundBanks[bank][soundIndex].z > 0.0f) {
+ }
+ else if (*sSoundBanks[bank][soundIndex].z > 0.0f)
+ {
sSoundBanks[bank][soundIndex].priority =
- (u32) sSoundBanks[bank][soundIndex].distance
- + (u32)(*sSoundBanks[bank][soundIndex].z / US_FLOAT(6.0))
- + 0x4c * (0xff - requestedPriority);
- } else {
+ (u32)sSoundBanks[bank][soundIndex].distance
+ + (u32)(*sSoundBanks[bank][soundIndex].z / US_FLOAT(6.0))
+ + 0x4c * (0xff - requestedPriority);
+ }
+ else
+ {
sSoundBanks[bank][soundIndex].priority =
- (u32) sSoundBanks[bank][soundIndex].distance + 0x4c * (0xff - requestedPriority);
+ (u32)sSoundBanks[bank][soundIndex].distance + 0x4c * (0xff - requestedPriority);
}
// Insert the sound into the liveSound arrays, keeping the arrays sorted by priority.
// If more than sMaxChannelsForSoundBank[bank] sounds are live, then the
// sound with lowest priority will be removed from the arrays.
// In practice sMaxChannelsForSoundBank is always 1, so this code is overly general.
- for (i = 0; i < sMaxChannelsForSoundBank[bank]; i++) {
+ for (i = 0; i < sMaxChannelsForSoundBank[bank]; i++)
+ {
// If the correct position is found
- if (liveSoundPriorities[i] >= sSoundBanks[bank][soundIndex].priority) {
+ if (liveSoundPriorities[i] >= sSoundBanks[bank][soundIndex].priority)
+ {
// Shift remaining sounds to the right
- for (j = sMaxChannelsForSoundBank[bank] - 1; j > i; j--) {
+ for (j = sMaxChannelsForSoundBank[bank] - 1; j > i; j--)
+ {
liveSoundPriorities[j] = liveSoundPriorities[j - 1];
liveSoundIndices[j] = liveSoundIndices[j - 1];
liveSoundStatuses[j] = liveSoundStatuses[j - 1];
@@ -1060,11 +1155,14 @@ static void select_current_sounds(u8 bank) {
// Remove any sounds from liveSoundIndices that are already playing.
// Stop any currently playing sounds that are not in liveSoundIndices.
//
- for (i = 0; i < sUsedChannelsForSoundBank[bank]; i++) {
+ for (i = 0; i < sUsedChannelsForSoundBank[bank]; i++)
+ {
// Check if sCurrentSound[bank][i] is present in the liveSound arrays.
- for (soundIndex = 0; soundIndex < sUsedChannelsForSoundBank[bank]; soundIndex++) {
+ for (soundIndex = 0; soundIndex < sUsedChannelsForSoundBank[bank]; soundIndex++)
+ {
if (liveSoundIndices[soundIndex] != 0xff
- && sCurrentSound[bank][i] == liveSoundIndices[soundIndex]) {
+ && sCurrentSound[bank][i] == liveSoundIndices[soundIndex])
+ {
// If found, remove it from liveSoundIndices
liveSoundIndices[soundIndex] = 0xff;
soundIndex = 0xfe; // Break. Afterward soundIndex will be 0xff
@@ -1072,11 +1170,15 @@ static void select_current_sounds(u8 bank) {
}
// If it is not present in the liveSound arrays, then stop playing it
- if (soundIndex != 0xff) {
- if (sCurrentSound[bank][i] != 0xff) {
+ if (soundIndex != 0xff)
+ {
+ if (sCurrentSound[bank][i] != 0xff)
+ {
// If the sound was marked for deletion and is playing, delete it
- if (sSoundBanks[bank][sCurrentSound[bank][i]].soundBits == NO_SOUND) {
- if (sSoundBanks[bank][sCurrentSound[bank][i]].soundStatus == SOUND_STATUS_PLAYING) {
+ if (sSoundBanks[bank][sCurrentSound[bank][i]].soundBits == NO_SOUND)
+ {
+ if (sSoundBanks[bank][sCurrentSound[bank][i]].soundStatus == SOUND_STATUS_PLAYING)
+ {
sSoundBanks[bank][sCurrentSound[bank][i]].soundStatus = SOUND_STATUS_STOPPED;
delete_sound_from_bank(bank, sCurrentSound[bank][i]);
}
@@ -1086,14 +1188,15 @@ static void select_current_sounds(u8 bank) {
isDiscreteAndStatus = sSoundBanks[bank][sCurrentSound[bank][i]].soundBits
& (SOUND_DISCRETE | SOUNDARGS_MASK_STATUS);
if (isDiscreteAndStatus >= (SOUND_DISCRETE | SOUND_STATUS_PLAYING)
- && sSoundBanks[bank][sCurrentSound[bank][i]].soundStatus != SOUND_STATUS_STOPPED) {
-//! @bug On JP, if a discrete sound that lowers the background music is
-// interrupted in this way, it will keep the background music low afterward.
-// There are only a few of these sounds, and it probably isn't possible to do
-// it in practice without using a time stop glitch like triple star spawn.
-#ifndef VERSION_JP
+ && sSoundBanks[bank][sCurrentSound[bank][i]].soundStatus != SOUND_STATUS_STOPPED)
+ {
+ //! @bug On JP, if a discrete sound that lowers the background music is
+ // interrupted in this way, it will keep the background music low afterward.
+ // There are only a few of these sounds, and it probably isn't possible to do
+ // it in practice without using a time stop glitch like triple star spawn.
+ #ifndef VERSION_JP
update_background_music_after_sound(bank, sCurrentSound[bank][i]);
-#endif
+ #endif
sSoundBanks[bank][sCurrentSound[bank][i]].soundBits = NO_SOUND;
sSoundBanks[bank][sCurrentSound[bank][i]].soundStatus = SOUND_STATUS_STOPPED;
@@ -1101,10 +1204,12 @@ static void select_current_sounds(u8 bank) {
}
// If the sound is continuous and is playing, then stop playing it but don't delete
// it. (A continuous sound shouldn't be deleted until it stops being requested)
- else {
+ else
+ {
if (isDiscreteAndStatus == SOUND_STATUS_PLAYING
&& sSoundBanks[bank][sCurrentSound[bank][i]].soundStatus
- != SOUND_STATUS_STOPPED) {
+ != SOUND_STATUS_STOPPED)
+ {
sSoundBanks[bank][sCurrentSound[bank][i]].soundStatus = SOUND_STATUS_WAITING;
}
}
@@ -1116,21 +1221,25 @@ static void select_current_sounds(u8 bank) {
//
// Start playing the remaining sounds from liveSoundIndices.
//
- for (soundIndex = 0; soundIndex < sUsedChannelsForSoundBank[bank]; soundIndex++) {
- if (liveSoundIndices[soundIndex] != 0xff) {
- for (i = 0; i < sUsedChannelsForSoundBank[bank]; i++) {
- if (sCurrentSound[bank][i] == 0xff) {
+ for (soundIndex = 0; soundIndex < sUsedChannelsForSoundBank[bank]; soundIndex++)
+ {
+ if (liveSoundIndices[soundIndex] != 0xff)
+ {
+ for (i = 0; i < sUsedChannelsForSoundBank[bank]; i++)
+ {
+ if (sCurrentSound[bank][i] == 0xff)
+ {
sCurrentSound[bank][i] = liveSoundIndices[soundIndex];
// Set (soundBits & status) to WAITING (soundStatus will be updated
// shortly after in update_game_sound)
sSoundBanks[bank][liveSoundIndices[soundIndex]].soundBits =
- (sSoundBanks[bank][liveSoundIndices[soundIndex]].soundBits
- & ~SOUNDARGS_MASK_STATUS)
- + SOUND_STATUS_WAITING;
+ (sSoundBanks[bank][liveSoundIndices[soundIndex]].soundBits
+ & ~SOUNDARGS_MASK_STATUS)
+ + SOUND_STATUS_WAITING;
liveSoundIndices[i] = 0xff; // doesn't do anything
- i = 0xfe; // break
+ i = 0xfe; // break
}
}
}
@@ -1148,18 +1257,21 @@ static void select_current_sounds(u8 bank) {
*
* Called from threads: thread4_sound, thread5_game_loop (EU only)
*/
-static f32 get_sound_pan(f32 x, f32 z) {
+static f32 get_sound_pan(f32 x, f32 z)
+{
f32 absX;
f32 absZ;
f32 pan;
- absX = (x < 0 ? -x : x);
- if (absX > AUDIO_MAX_DISTANCE) {
+ absX = x < 0 ? -x : x;
+ if (absX > AUDIO_MAX_DISTANCE)
+ {
absX = AUDIO_MAX_DISTANCE;
}
- absZ = (z < 0 ? -z : z);
- if (absZ > AUDIO_MAX_DISTANCE) {
+ absZ = z < 0 ? -z : z;
+ if (absZ > AUDIO_MAX_DISTANCE)
+ {
absZ = AUDIO_MAX_DISTANCE;
}
@@ -1168,16 +1280,23 @@ static f32 get_sound_pan(f32 x, f32 z) {
// 2. far right pan: between 1:30 and 4:30
// 3. far left pan: between 7:30 and 10:30
// 4. center pan: between 4:30 and 7:30 or between 10:30 and 1:30
- if (x == US_FLOAT(0.0) && z == US_FLOAT(0.0)) {
+ if (x == US_FLOAT(0.0) && z == US_FLOAT(0.0))
+ {
// x and z being 0 results in a center pan
pan = US_FLOAT(0.5);
- } else if (x >= US_FLOAT(0.0) && absX >= absZ) {
+ }
+ else if (x >= US_FLOAT(0.0) && absX >= absZ)
+ {
// far right pan
pan = US_FLOAT(1.0) - (2 * AUDIO_MAX_DISTANCE - absX) / (US_FLOAT(3.0) * (2 * AUDIO_MAX_DISTANCE - absZ));
- } else if (x < 0 && absX > absZ) {
+ }
+ else if (x < 0 && absX > absZ)
+ {
// far left pan
pan = (2 * AUDIO_MAX_DISTANCE - absX) / (US_FLOAT(3.0) * (2 * AUDIO_MAX_DISTANCE - absZ));
- } else {
+ }
+ else
+ {
// center pan
//! @bug (JP PU sound glitch) If |x|, |z| > AUDIO_MAX_DISTANCE, we'll
// end up in this case, and pan may be set to something outside of [0,1]
@@ -1193,53 +1312,67 @@ static f32 get_sound_pan(f32 x, f32 z) {
/**
* Called from threads: thread4_sound, thread5_game_loop (EU only)
*/
-static f32 get_sound_volume(u8 bank, u8 soundIndex, f32 volumeRange) {
+static f32 get_sound_volume(u8 bank, u8 soundIndex, f32 volumeRange)
+{
f32 maxSoundDistance;
f32 intensity;
-#ifndef VERSION_JP
+ #ifndef VERSION_JP
s32 div = bank < 3 ? 2 : 3;
-#endif
+ #endif
- if (!(sSoundBanks[bank][soundIndex].soundBits & SOUND_NO_VOLUME_LOSS)) {
-#ifdef VERSION_JP
+ if (!(sSoundBanks[bank][soundIndex].soundBits & SOUND_NO_VOLUME_LOSS))
+ {
+ #ifdef VERSION_JP
// Intensity linearly lowers from 1 at the camera to 0 at maxSoundDistance
maxSoundDistance = sLevelAcousticReaches[gCurrLevelNum];
- if (maxSoundDistance < sSoundBanks[bank][soundIndex].distance) {
+ if (maxSoundDistance < sSoundBanks[bank][soundIndex].distance)
+ {
intensity = 0.0f;
- } else {
+ }
+ else
+ {
intensity = 1.0 - sSoundBanks[bank][soundIndex].distance / maxSoundDistance;
}
-#else
+ #else
// Intensity linearly lowers from 1 at the camera to 1 - volumeRange at maxSoundDistance,
// then it goes from 1 - volumeRange at maxSoundDistance to 0 at AUDIO_MAX_DISTANCE
- if (sSoundBanks[bank][soundIndex].distance > AUDIO_MAX_DISTANCE) {
+ if (sSoundBanks[bank][soundIndex].distance > AUDIO_MAX_DISTANCE)
+ {
intensity = 0.0f;
- } else {
+ }
+ else
+ {
maxSoundDistance = sLevelAcousticReaches[gCurrLevelNum] / div;
- if (maxSoundDistance < sSoundBanks[bank][soundIndex].distance) {
- intensity = ((AUDIO_MAX_DISTANCE - sSoundBanks[bank][soundIndex].distance)
- / (AUDIO_MAX_DISTANCE - maxSoundDistance))
+ if (maxSoundDistance < sSoundBanks[bank][soundIndex].distance)
+ {
+ intensity = (AUDIO_MAX_DISTANCE - sSoundBanks[bank][soundIndex].distance)
+ / (AUDIO_MAX_DISTANCE - maxSoundDistance)
* (1.0f - volumeRange);
- } else {
+ }
+ else
+ {
intensity =
- 1.0f - sSoundBanks[bank][soundIndex].distance / maxSoundDistance * volumeRange;
+ 1.0f - sSoundBanks[bank][soundIndex].distance / maxSoundDistance * volumeRange;
}
}
-#endif
+ #endif
- if (sSoundBanks[bank][soundIndex].soundBits & SOUND_VIBRATO) {
-#ifdef VERSION_JP
+ if (sSoundBanks[bank][soundIndex].soundBits & SOUND_VIBRATO)
+ {
+ #ifdef VERSION_JP
//! @bug Intensity is 0 when the sound is far away. Due to the subtraction below, it is possible to end up with a negative intensity.
// When it is, objects with a volumeRange of 1 can still occasionally be lightly heard.
if (intensity != 0.0)
-#else
+ #else
if (intensity >= 0.08f)
-#endif
+ #endif
{
intensity -= (f32)(gAudioRandom & 0xf) / US_FLOAT(192.0);
}
}
- } else {
+ }
+ else
+ {
intensity = 1.0f;
}
@@ -1250,15 +1383,20 @@ static f32 get_sound_volume(u8 bank, u8 soundIndex, f32 volumeRange) {
/**
* Called from threads: thread4_sound, thread5_game_loop (EU only)
*/
-static f32 get_sound_freq_scale(u8 bank, u8 item) {
+static f32 get_sound_freq_scale(u8 bank, u8 item)
+{
f32 amount;
- if (!(sSoundBanks[bank][item].soundBits & SOUND_CONSTANT_FREQUENCY)) {
+ if (!(sSoundBanks[bank][item].soundBits & SOUND_CONSTANT_FREQUENCY))
+ {
amount = sSoundBanks[bank][item].distance / AUDIO_MAX_DISTANCE;
- if (sSoundBanks[bank][item].soundBits & SOUND_VIBRATO) {
+ if (sSoundBanks[bank][item].soundBits & SOUND_VIBRATO)
+ {
amount += (f32)(gAudioRandom & 0xff) / US_FLOAT(64.0);
}
- } else {
+ }
+ else
+ {
amount = 0.0f;
}
@@ -1270,26 +1408,31 @@ static f32 get_sound_freq_scale(u8 bank, u8 item) {
/**
* Called from threads: thread4_sound, thread5_game_loop (EU only)
*/
-static u8 get_sound_reverb(UNUSED u8 bank, UNUSED u8 soundIndex, u8 channelIndex) {
+static u8 get_sound_reverb(UNUSED u8 bank, UNUSED u8 soundIndex, u8 channelIndex)
+{
u8 area;
u8 level;
u8 reverb;
-#ifndef VERSION_JP
+ #ifndef VERSION_JP
// Disable level reverb if NO_ECHO is set
- if (sSoundBanks[bank][soundIndex].soundBits & SOUND_NO_ECHO) {
+ if (sSoundBanks[bank][soundIndex].soundBits & SOUND_NO_ECHO)
+ {
level = 0;
area = 0;
- } else {
-#endif
- level = (gCurrLevelNum > LEVEL_MAX ? LEVEL_MAX : gCurrLevelNum);
+ }
+ else
+ {
+ #endif
+ level = gCurrLevelNum > LEVEL_MAX ? LEVEL_MAX : gCurrLevelNum;
area = gCurrAreaIndex - 1;
- if (area > 2) {
+ if (area > 2)
+ {
area = 2;
}
-#ifndef VERSION_JP
+ #ifndef VERSION_JP
}
-#endif
+ #endif
// reverb = reverb adjustment + level reverb + a volume-dependent value
// The volume-dependent value is 0 when volume is at maximum, and raises to
@@ -1301,13 +1444,15 @@ static u8 get_sound_reverb(UNUSED u8 bank, UNUSED u8 soundIndex, u8 channelIndex
reverb = gAudioReverb;
- if (reverb > 0x7f) {
+ if (reverb > 0x7f)
+ {
reverb = 0x7f;
}
return reverb;
}
-static void noop_8031EEC8(void) {
+static void noop_8031EEC8(void)
+{
}
/**
@@ -1316,50 +1461,58 @@ static void noop_8031EEC8(void) {
*
* Called from threads: thread5_game_loop
*/
-void audio_signal_game_loop_tick(void) {
+void audio_signal_game_loop_tick(void)
+{
sGameLoopTicked = 1;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
maybe_tick_game_sound();
-#endif
+ #endif
noop_8031EEC8();
}
/**
* Called from threads: thread4_sound, thread5_game_loop (EU and SH only)
*/
-void update_game_sound(void) {
+void update_game_sound(void)
+{
u8 soundStatus;
u8 i;
u8 soundId;
u8 bank;
u8 channelIndex = 0;
u8 soundIndex;
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #if defined(VERSION_JP) || defined(VERSION_US)
f32 value;
-#endif
+ #endif
process_all_sound_requests();
process_level_music_dynamics();
- if (gSequencePlayers[SEQ_PLAYER_SFX].channels[0] == &gSequenceChannelNone) {
+ if (gSequencePlayers[SEQ_PLAYER_SFX].channels[0] == &gSequenceChannelNone)
+ {
return;
}
- for (bank = 0; bank < SOUND_BANK_COUNT; bank++) {
+ for (bank = 0; bank < SOUND_BANK_COUNT; bank++)
+ {
select_current_sounds(bank);
- for (i = 0; i < MAX_CHANNELS_PER_SOUND_BANK; i++) {
+ for (i = 0; i < MAX_CHANNELS_PER_SOUND_BANK; i++)
+ {
soundIndex = sCurrentSound[bank][i];
if (soundIndex < 0xff
- && sSoundBanks[bank][soundIndex].soundStatus != SOUND_STATUS_STOPPED) {
+ && sSoundBanks[bank][soundIndex].soundStatus != SOUND_STATUS_STOPPED)
+ {
soundStatus = sSoundBanks[bank][soundIndex].soundBits & SOUNDARGS_MASK_STATUS;
- soundId = (sSoundBanks[bank][soundIndex].soundBits >> SOUNDARGS_SHIFT_SOUNDID);
+ soundId = sSoundBanks[bank][soundIndex].soundBits >> SOUNDARGS_SHIFT_SOUNDID;
sSoundBanks[bank][soundIndex].soundStatus = soundStatus;
- if (soundStatus == SOUND_STATUS_WAITING) {
- if (sSoundBanks[bank][soundIndex].soundBits & SOUND_LOWER_BACKGROUND_MUSIC) {
+ if (soundStatus == SOUND_STATUS_WAITING)
+ {
+ if (sSoundBanks[bank][soundIndex].soundBits & SOUND_LOWER_BACKGROUND_MUSIC)
+ {
sSoundBanksThatLowerBackgroundMusic |= 1 << bank;
begin_background_music_fade(50);
}
@@ -1372,90 +1525,98 @@ void update_game_sound(void) {
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->soundScriptIO[4] = soundId;
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->soundScriptIO[0] = 1;
- switch (bank) {
+ switch (bank)
+ {
case SOUND_BANK_MOVING:
- if (!(sSoundBanks[bank][soundIndex].soundBits & SOUND_CONSTANT_FREQUENCY)) {
- if (sSoundMovingSpeed[bank] > 8) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ if (!(sSoundBanks[bank][soundIndex].soundBits & SOUND_CONSTANT_FREQUENCY))
+ {
+ if (sSoundMovingSpeed[bank] > 8)
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad728(
0x02020000 | ((channelIndex & 0xff) << 8),
get_sound_volume(bank, soundIndex, VOLUME_RANGE_UNK1));
-#else
+ #else
value = get_sound_volume(bank, soundIndex, VOLUME_RANGE_UNK1);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->volume =
- value;
-#endif
- } else {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ value;
+ #endif
+ }
+ else
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad728(0x02020000 | ((channelIndex & 0xff) << 8),
get_sound_volume(bank, soundIndex, VOLUME_RANGE_UNK1)
- * ((sSoundMovingSpeed[bank] + 8.0f) / 16));
-#else
+ * ((sSoundMovingSpeed[bank] + 8.0f) / 16));
+ #else
value = get_sound_volume(bank, soundIndex, VOLUME_RANGE_UNK1);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->volume =
- (sSoundMovingSpeed[bank] + 8.0f) / 16 * value;
-#endif
+ (sSoundMovingSpeed[bank] + 8.0f) / 16 * value;
+ #endif
}
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad770(0x03020000 | ((channelIndex & 0xff) << 8),
get_sound_pan(*sSoundBanks[bank][soundIndex].x,
*sSoundBanks[bank][soundIndex].z));
-#else
+ #else
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->pan =
- get_sound_pan(*sSoundBanks[bank][soundIndex].x,
- *sSoundBanks[bank][soundIndex].z);
-#endif
+ get_sound_pan(*sSoundBanks[bank][soundIndex].x,
+ *sSoundBanks[bank][soundIndex].z);
+ #endif
if ((sSoundBanks[bank][soundIndex].soundBits & SOUNDARGS_MASK_SOUNDID)
- == (SOUND_MOVING_FLYING & SOUNDARGS_MASK_SOUNDID)) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ == (SOUND_MOVING_FLYING & SOUNDARGS_MASK_SOUNDID))
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad728(
0x04020000 | ((channelIndex & 0xff) << 8),
get_sound_freq_scale(bank, soundIndex)
- + ((f32) sSoundMovingSpeed[bank] / US_FLOAT(80.0)));
-#else
+ + ((f32)sSoundMovingSpeed[bank] / US_FLOAT(80.0)));
+ #else
value = get_sound_freq_scale(bank, soundIndex);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale =
- ((f32) sSoundMovingSpeed[bank] / US_FLOAT(80.0)) + value;
-#endif
- } else {
-#if defined(VERSION_EU) || defined(VERSION_SH)
- func_802ad728(
- 0x04020000 | ((channelIndex & 0xff) << 8),
- get_sound_freq_scale(bank, soundIndex)
- + ((f32) sSoundMovingSpeed[bank] / US_FLOAT(400.0)));
-#else
- value = get_sound_freq_scale(bank, soundIndex);
- gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale =
- ((f32) sSoundMovingSpeed[bank] / US_FLOAT(400.0)) + value;
-#endif
+ (f32)sSoundMovingSpeed[bank] / US_FLOAT(80.0) + value;
+ #endif
}
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ else
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ func_802ad728(
+ 0x04020000 | ((channelIndex & 0xff) << 8),
+ get_sound_freq_scale(bank, soundIndex)
+ + ((f32)sSoundMovingSpeed[bank] / US_FLOAT(400.0)));
+ #else
+ value = get_sound_freq_scale(bank, soundIndex);
+ gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale =
+ (f32)sSoundMovingSpeed[bank] / US_FLOAT(400.0) + value;
+ #endif
+ }
+ #if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad770(0x05020000 | ((channelIndex & 0xff) << 8),
get_sound_reverb(bank, soundIndex, channelIndex));
-#else
+ #else
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->reverbVol =
- get_sound_reverb(bank, soundIndex, channelIndex);
-#endif
+ get_sound_reverb(bank, soundIndex, channelIndex);
+ #endif
break;
}
// fallthrough
case SOUND_BANK_MENU:
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad728(0x02020000 | ((channelIndex & 0xff) << 8), 1);
func_802ad770(0x03020000 | ((channelIndex & 0xff) << 8), 64);
func_802ad728(0x04020000 | ((channelIndex & 0xff) << 8),
get_sound_freq_scale(bank, soundIndex));
-#else
+ #else
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->volume = 1.0f;
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->pan = 0.5f;
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale = 1.0f;
-#endif
+ #endif
break;
case SOUND_BANK_ACTION:
case SOUND_BANK_VOICE:
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad770(0x05020000 | ((channelIndex & 0xff) << 8),
get_sound_reverb(bank, soundIndex, channelIndex));
func_802ad728(0x02020000 | ((channelIndex & 0xff) << 8),
@@ -1463,21 +1624,21 @@ void update_game_sound(void) {
func_802ad770(0x03020000 | ((channelIndex & 0xff) << 8),
get_sound_pan(*sSoundBanks[bank][soundIndex].x,
*sSoundBanks[bank][soundIndex].z)
- * 127.0f
- + 0.5f);
+ * 127.0f
+ + 0.5f);
func_802ad728(0x04020000 | ((channelIndex & 0xff) << 8),
get_sound_freq_scale(bank, soundIndex));
-#else
+ #else
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->volume =
- get_sound_volume(bank, soundIndex, VOLUME_RANGE_UNK1);
+ get_sound_volume(bank, soundIndex, VOLUME_RANGE_UNK1);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->pan =
- get_sound_pan(*sSoundBanks[bank][soundIndex].x,
- *sSoundBanks[bank][soundIndex].z);
+ get_sound_pan(*sSoundBanks[bank][soundIndex].x,
+ *sSoundBanks[bank][soundIndex].z);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale =
- get_sound_freq_scale(bank, soundIndex);
+ get_sound_freq_scale(bank, soundIndex);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->reverbVol =
- get_sound_reverb(bank, soundIndex, channelIndex);
-#endif
+ get_sound_reverb(bank, soundIndex, channelIndex);
+ #endif
break;
case SOUND_BANK_GENERAL:
case SOUND_BANK_ENV:
@@ -1485,7 +1646,7 @@ void update_game_sound(void) {
case SOUND_BANK_AIR:
case SOUND_BANK_GENERAL2:
case SOUND_BANK_OBJ2:
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad770(0x05020000 | ((channelIndex & 0xff) << 8),
get_sound_reverb(bank, soundIndex, channelIndex));
func_802ad728(0x02020000 | ((channelIndex & 0xff) << 8),
@@ -1493,25 +1654,25 @@ void update_game_sound(void) {
func_802ad770(0x03020000 | ((channelIndex & 0xff) << 8),
get_sound_pan(*sSoundBanks[bank][soundIndex].x,
*sSoundBanks[bank][soundIndex].z)
- * 127.0f
- + 0.5f);
+ * 127.0f
+ + 0.5f);
func_802ad728(0x04020000 | ((channelIndex & 0xff) << 8),
get_sound_freq_scale(bank, soundIndex));
-#else
+ #else
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->reverbVol =
- get_sound_reverb(bank, soundIndex, channelIndex);
+ get_sound_reverb(bank, soundIndex, channelIndex);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->volume =
- get_sound_volume(bank, soundIndex, VOLUME_RANGE_UNK2);
+ get_sound_volume(bank, soundIndex, VOLUME_RANGE_UNK2);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->pan =
- get_sound_pan(*sSoundBanks[bank][soundIndex].x,
- *sSoundBanks[bank][soundIndex].z);
+ get_sound_pan(*sSoundBanks[bank][soundIndex].x,
+ *sSoundBanks[bank][soundIndex].z);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale =
- get_sound_freq_scale(bank, soundIndex);
-#endif
+ get_sound_freq_scale(bank, soundIndex);
+ #endif
break;
}
}
-#ifdef VERSION_JP
+ #ifdef VERSION_JP
// If the sound was marked for deletion (bits set to NO_SOUND), then stop playing it
// and delete it
// @bug (JP double red coin sound) If the sound finished within the same frame as
@@ -1521,24 +1682,28 @@ void update_game_sound(void) {
// whose sound spawners deactivate 30 frames after the sound starts to play, while
// the sound itself runs for 1.20 seconds. With enough lag these may coincide.
// Fixed on US by checking that layer0->finished is FALSE.
- else if (soundStatus == SOUND_STATUS_STOPPED) {
+ else if (soundStatus == SOUND_STATUS_STOPPED)
+ {
update_background_music_after_sound(bank, soundIndex);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->soundScriptIO[0] = 0;
delete_sound_from_bank(bank, soundIndex);
}
-#else
- else if (gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->layers[0] == NULL) {
+ #else
+ else if (gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->layers[0] == NULL)
+ {
update_background_music_after_sound(bank, soundIndex);
sSoundBanks[bank][soundIndex].soundStatus = SOUND_STATUS_STOPPED;
delete_sound_from_bank(bank, soundIndex);
- } else if (soundStatus == SOUND_STATUS_STOPPED
- && gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]
- ->layers[0]->finished == FALSE) {
+ }
+ else if (soundStatus == SOUND_STATUS_STOPPED
+ && gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]
+ ->layers[0]->finished == FALSE)
+ {
update_background_music_after_sound(bank, soundIndex);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->soundScriptIO[0] = 0;
delete_sound_from_bank(bank, soundIndex);
}
-#endif
+ #endif
// If sound has finished playing, then delete it
// @bug (JP sound glitch) On JP, ...->layers[0] has not been checked for null,
// so this access can crash if an earlier layer allocation failed due to too
@@ -1546,100 +1711,111 @@ void update_game_sound(void) {
// speedrunners even have a setup for avoiding it within the SSL pyramid:
// https://www.youtube.com/watch?v=QetyTgbQxcw
else if (gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->layers[0]->enabled
- == FALSE) {
+ == FALSE)
+ {
update_background_music_after_sound(bank, soundIndex);
sSoundBanks[bank][soundIndex].soundStatus = SOUND_STATUS_STOPPED;
delete_sound_from_bank(bank, soundIndex);
- } else {
+ }
+ else
+ {
// Exactly the same code as before. Unfortunately we can't
// make a macro out of this, because then everything ends up
// on the same line after preprocessing, and the compiler,
// somehow caring about line numbers, makes it not match (it
// computes function arguments in the wrong order).
- switch (bank) {
+ switch (bank)
+ {
case SOUND_BANK_MOVING:
- if (!(sSoundBanks[bank][soundIndex].soundBits & SOUND_CONSTANT_FREQUENCY)) {
- if (sSoundMovingSpeed[bank] > 8) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ if (!(sSoundBanks[bank][soundIndex].soundBits & SOUND_CONSTANT_FREQUENCY))
+ {
+ if (sSoundMovingSpeed[bank] > 8)
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad728(
0x02020000 | ((channelIndex & 0xff) << 8),
get_sound_volume(bank, soundIndex, VOLUME_RANGE_UNK1));
-#else
+ #else
value = get_sound_volume(bank, soundIndex, VOLUME_RANGE_UNK1);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->volume =
- value;
-#endif
- } else {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ value;
+ #endif
+ }
+ else
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad728(0x02020000 | ((channelIndex & 0xff) << 8),
get_sound_volume(bank, soundIndex, VOLUME_RANGE_UNK1)
- * ((sSoundMovingSpeed[bank] + 8.0f) / 16));
-#else
+ * ((sSoundMovingSpeed[bank] + 8.0f) / 16));
+ #else
value = get_sound_volume(bank, soundIndex, VOLUME_RANGE_UNK1);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->volume =
- (sSoundMovingSpeed[bank] + 8.0f) / 16 * value;
-#endif
+ (sSoundMovingSpeed[bank] + 8.0f) / 16 * value;
+ #endif
}
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad770(0x03020000 | ((channelIndex & 0xff) << 8),
get_sound_pan(*sSoundBanks[bank][soundIndex].x,
*sSoundBanks[bank][soundIndex].z));
-#else
+ #else
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->pan =
- get_sound_pan(*sSoundBanks[bank][soundIndex].x,
- *sSoundBanks[bank][soundIndex].z);
-#endif
+ get_sound_pan(*sSoundBanks[bank][soundIndex].x,
+ *sSoundBanks[bank][soundIndex].z);
+ #endif
if ((sSoundBanks[bank][soundIndex].soundBits & SOUNDARGS_MASK_SOUNDID)
- == (SOUND_MOVING_FLYING & SOUNDARGS_MASK_SOUNDID)) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ == (SOUND_MOVING_FLYING & SOUNDARGS_MASK_SOUNDID))
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad728(
0x04020000 | ((channelIndex & 0xff) << 8),
get_sound_freq_scale(bank, soundIndex)
- + ((f32) sSoundMovingSpeed[bank] / US_FLOAT(80.0)));
-#else
+ + ((f32)sSoundMovingSpeed[bank] / US_FLOAT(80.0)));
+ #else
value = get_sound_freq_scale(bank, soundIndex);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale =
- ((f32) sSoundMovingSpeed[bank] / US_FLOAT(80.0)) + value;
-#endif
- } else {
-#if defined(VERSION_EU) || defined(VERSION_SH)
- func_802ad728(
- 0x04020000 | ((channelIndex & 0xff) << 8),
- get_sound_freq_scale(bank, soundIndex)
- + ((f32) sSoundMovingSpeed[bank] / US_FLOAT(400.0)));
-#else
- value = get_sound_freq_scale(bank, soundIndex);
- gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale =
- ((f32) sSoundMovingSpeed[bank] / US_FLOAT(400.0)) + value;
-#endif
+ (f32)sSoundMovingSpeed[bank] / US_FLOAT(80.0) + value;
+ #endif
}
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ else
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ func_802ad728(
+ 0x04020000 | ((channelIndex & 0xff) << 8),
+ get_sound_freq_scale(bank, soundIndex)
+ + ((f32)sSoundMovingSpeed[bank] / US_FLOAT(400.0)));
+ #else
+ value = get_sound_freq_scale(bank, soundIndex);
+ gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale =
+ (f32)sSoundMovingSpeed[bank] / US_FLOAT(400.0) + value;
+ #endif
+ }
+ #if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad770(0x05020000 | ((channelIndex & 0xff) << 8),
get_sound_reverb(bank, soundIndex, channelIndex));
-#else
+ #else
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->reverbVol =
- get_sound_reverb(bank, soundIndex, channelIndex);
-#endif
+ get_sound_reverb(bank, soundIndex, channelIndex);
+ #endif
break;
}
// fallthrough
case SOUND_BANK_MENU:
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad728(0x02020000 | ((channelIndex & 0xff) << 8), 1);
func_802ad770(0x03020000 | ((channelIndex & 0xff) << 8), 64);
func_802ad728(0x04020000 | ((channelIndex & 0xff) << 8),
get_sound_freq_scale(bank, soundIndex));
-#else
+ #else
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->volume = 1.0f;
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->pan = 0.5f;
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale = 1.0f;
-#endif
+ #endif
break;
case SOUND_BANK_ACTION:
case SOUND_BANK_VOICE:
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad770(0x05020000 | ((channelIndex & 0xff) << 8),
get_sound_reverb(bank, soundIndex, channelIndex));
func_802ad728(0x02020000 | ((channelIndex & 0xff) << 8),
@@ -1647,21 +1823,21 @@ void update_game_sound(void) {
func_802ad770(0x03020000 | ((channelIndex & 0xff) << 8),
get_sound_pan(*sSoundBanks[bank][soundIndex].x,
*sSoundBanks[bank][soundIndex].z)
- * 127.0f
- + 0.5f);
+ * 127.0f
+ + 0.5f);
func_802ad728(0x04020000 | ((channelIndex & 0xff) << 8),
get_sound_freq_scale(bank, soundIndex));
-#else
+ #else
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->volume =
- get_sound_volume(bank, soundIndex, VOLUME_RANGE_UNK1);
+ get_sound_volume(bank, soundIndex, VOLUME_RANGE_UNK1);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->pan =
- get_sound_pan(*sSoundBanks[bank][soundIndex].x,
- *sSoundBanks[bank][soundIndex].z);
+ get_sound_pan(*sSoundBanks[bank][soundIndex].x,
+ *sSoundBanks[bank][soundIndex].z);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale =
- get_sound_freq_scale(bank, soundIndex);
+ get_sound_freq_scale(bank, soundIndex);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->reverbVol =
- get_sound_reverb(bank, soundIndex, channelIndex);
-#endif
+ get_sound_reverb(bank, soundIndex, channelIndex);
+ #endif
break;
case SOUND_BANK_GENERAL:
case SOUND_BANK_ENV:
@@ -1669,7 +1845,7 @@ void update_game_sound(void) {
case SOUND_BANK_AIR:
case SOUND_BANK_GENERAL2:
case SOUND_BANK_OBJ2:
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad770(0x05020000 | ((channelIndex & 0xff) << 8),
get_sound_reverb(bank, soundIndex, channelIndex));
func_802ad728(0x02020000 | ((channelIndex & 0xff) << 8),
@@ -1677,21 +1853,21 @@ void update_game_sound(void) {
func_802ad770(0x03020000 | ((channelIndex & 0xff) << 8),
get_sound_pan(*sSoundBanks[bank][soundIndex].x,
*sSoundBanks[bank][soundIndex].z)
- * 127.0f
- + 0.5f);
+ * 127.0f
+ + 0.5f);
func_802ad728(0x04020000 | ((channelIndex & 0xff) << 8),
get_sound_freq_scale(bank, soundIndex));
-#else
+ #else
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->reverbVol =
- get_sound_reverb(bank, soundIndex, channelIndex);
+ get_sound_reverb(bank, soundIndex, channelIndex);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->volume =
- get_sound_volume(bank, soundIndex, VOLUME_RANGE_UNK2);
+ get_sound_volume(bank, soundIndex, VOLUME_RANGE_UNK2);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->pan =
- get_sound_pan(*sSoundBanks[bank][soundIndex].x,
- *sSoundBanks[bank][soundIndex].z);
+ get_sound_pan(*sSoundBanks[bank][soundIndex].x,
+ *sSoundBanks[bank][soundIndex].z);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale =
- get_sound_freq_scale(bank, soundIndex);
-#endif
+ get_sound_freq_scale(bank, soundIndex);
+ #endif
break;
}
}
@@ -1711,76 +1887,90 @@ void update_game_sound(void) {
/**
* Called from threads: thread4_sound, thread5_game_loop
*/
-void seq_player_play_sequence(u8 player, u8 seqId, u16 arg2) {
+void seq_player_play_sequence(u8 player, u8 seqId, u16 arg2)
+{
u8 targetVolume;
u8 i;
- if (player == SEQ_PLAYER_LEVEL) {
+ if (player == SEQ_PLAYER_LEVEL)
+ {
sCurrentBackgroundMusicSeqId = seqId & SEQ_BASE_ID;
sBackgroundMusicForDynamics = SEQUENCE_NONE;
sCurrentMusicDynamic = 0xff;
sMusicDynamicDelay = 2;
}
- for (i = 0; i < CHANNELS_MAX; i++) {
+ for (i = 0; i < CHANNELS_MAX; i++)
+ {
D_80360928[player][i].remainingFrames = 0;
}
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad770(0x46000000 | ((u8)(u32) player) << 16, seqId & SEQ_VARIATION);
func_802ad74c(0x82000000 | ((u8)(u32) player) << 16 | ((u8)(seqId & SEQ_BASE_ID)) << 8, arg2);
- if (player == SEQ_PLAYER_LEVEL) {
+ if (player == SEQ_PLAYER_LEVEL)
+ {
targetVolume = begin_background_music_fade(0);
- if (targetVolume != 0xff) {
- gSequencePlayers[SEQ_PLAYER_LEVEL].fadeVolumeScale = (f32) targetVolume / US_FLOAT(127.0);
+ if (targetVolume != 0xff)
+ {
+ gSequencePlayers[SEQ_PLAYER_LEVEL].fadeVolumeScale = (f32)targetVolume / US_FLOAT(127.0);
}
}
-#else
+ #else
gSequencePlayers[player].seqVariation = seqId & SEQ_VARIATION;
load_sequence(player, seqId & SEQ_BASE_ID, 0);
- if (player == SEQ_PLAYER_LEVEL) {
+ if (player == SEQ_PLAYER_LEVEL)
+ {
targetVolume = begin_background_music_fade(0);
- if (targetVolume != 0xff) {
+ if (targetVolume != 0xff)
+ {
gSequencePlayers[SEQ_PLAYER_LEVEL].state = SEQUENCE_PLAYER_STATE_4;
- gSequencePlayers[SEQ_PLAYER_LEVEL].fadeVolume = (f32) targetVolume / US_FLOAT(127.0);
+ gSequencePlayers[SEQ_PLAYER_LEVEL].fadeVolume = (f32)targetVolume / US_FLOAT(127.0);
}
- } else {
+ }
+ else
+ {
func_8031D690(player, arg2);
}
-#endif
+ #endif
}
/**
* Called from threads: thread5_game_loop
*/
-void seq_player_fade_out(u8 player, u16 fadeDuration) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
-#ifdef VERSION_EU
+void seq_player_fade_out(u8 player, u16 fadeDuration)
+{
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ #ifdef VERSION_EU
u32 fd = fadeDuration;
-#else
+ #else
s32 fd = fadeDuration; // will also match if we change function signature func_802ad74c to use s32 as arg1
-#endif
- if (!player) {
+ #endif
+ if (!player)
+ {
sCurrentBackgroundMusicSeqId = SEQUENCE_NONE;
}
func_802ad74c(0x83000000 | (player & 0xff) << 16, fd);
-#else
- if (player == SEQ_PLAYER_LEVEL) {
+ #else
+ if (player == SEQ_PLAYER_LEVEL)
+ {
sCurrentBackgroundMusicSeqId = SEQUENCE_NONE;
}
seq_player_fade_to_zero_volume(player, fadeDuration);
-#endif
+ #endif
}
/**
* Called from threads: thread5_game_loop
*/
-void fade_volume_scale(u8 player, u8 targetScale, u16 fadeDuration) {
+void fade_volume_scale(u8 player, u8 targetScale, u16 fadeDuration)
+{
u8 i;
- for (i = 0; i < CHANNELS_MAX; i++) {
+ for (i = 0; i < CHANNELS_MAX; i++)
+ {
fade_channel_volume_scale(player, i, targetScale, fadeDuration);
}
}
@@ -1788,13 +1978,15 @@ void fade_volume_scale(u8 player, u8 targetScale, u16 fadeDuration) {
/**
* Called from threads: thread3_main, thread4_sound, thread5_game_loop
*/
-static void fade_channel_volume_scale(u8 player, u8 channelIndex, u8 targetScale, u16 fadeDuration) {
+static void fade_channel_volume_scale(u8 player, u8 channelIndex, u8 targetScale, u16 fadeDuration)
+{
struct ChannelVolumeScaleFade *temp;
- if (gSequencePlayers[player].channels[channelIndex] != &gSequenceChannelNone) {
+ if (gSequencePlayers[player].channels[channelIndex] != &gSequenceChannelNone)
+ {
temp = &D_80360928[player][channelIndex];
temp->remainingFrames = fadeDuration;
- temp->velocity = ((f32)(targetScale / US_FLOAT(127.0))
+ temp->velocity = (targetScale / US_FLOAT(127.0)
- gSequencePlayers[player].channels[channelIndex]->volumeScale)
/ fadeDuration;
temp->target = targetScale;
@@ -1805,32 +1997,36 @@ static void fade_channel_volume_scale(u8 player, u8 channelIndex, u8 targetScale
/**
* Called from threads: thread4_sound, thread5_game_loop (EU only)
*/
-static void func_8031F96C(u8 player) {
+static void func_8031F96C(u8 player)
+{
u8 i;
// Loop over channels
- for (i = 0; i < CHANNELS_MAX; i++) {
+ for (i = 0; i < CHANNELS_MAX; i++)
+ {
if (gSequencePlayers[player].channels[i] != &gSequenceChannelNone
- && D_80360928[player][i].remainingFrames != 0) {
+ && D_80360928[player][i].remainingFrames != 0)
+ {
D_80360928[player][i].current += D_80360928[player][i].velocity;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad728(0x01000000 | (player & 0xff) << 16 | (i & 0xff) << 8,
D_80360928[player][i].current);
-#else
+ #else
gSequencePlayers[player].channels[i]->volumeScale = D_80360928[player][i].current;
-#endif
+ #endif
D_80360928[player][i].remainingFrames--;
- if (D_80360928[player][i].remainingFrames == 0) {
-#if defined(VERSION_EU)
+ if (D_80360928[player][i].remainingFrames == 0)
+ {
+ #if defined(VERSION_EU)
func_802ad728(0x01000000 | (player & 0xff) << 16 | (i & 0xff) << 8,
FLOAT_CAST(D_80360928[player][i].target) / 127.0);
-#elif defined(VERSION_SH)
+ #elif defined(VERSION_SH)
func_802ad728(0x01000000 | (player & 0xff) << 16 | (i & 0xff) << 8,
FLOAT_CAST(D_80360928[player][i].target) / 127.0f);
-#else
+ #else
gSequencePlayers[player].channels[i]->volumeScale =
- D_80360928[player][i].target / 127.0f;
-#endif
+ D_80360928[player][i].target / 127.0f;
+ #endif
}
}
}
@@ -1839,7 +2035,8 @@ static void func_8031F96C(u8 player) {
/**
* Called from threads: thread4_sound, thread5_game_loop (EU only)
*/
-void process_level_music_dynamics(void) {
+void process_level_music_dynamics(void)
+{
u32 conditionBits;
u16 tempBits;
UNUSED u16 pad;
@@ -1856,25 +2053,32 @@ void process_level_music_dynamics(void) {
func_8031F96C(0);
func_8031F96C(2);
func_80320ED8();
- if (sMusicDynamicDelay != 0) {
+ if (sMusicDynamicDelay != 0)
+ {
sMusicDynamicDelay--;
- } else {
+ }
+ else
+ {
sBackgroundMusicForDynamics = sCurrentBackgroundMusicSeqId;
}
- if (sBackgroundMusicForDynamics != sLevelDynamics[gCurrLevelNum][0]) {
+ if (sBackgroundMusicForDynamics != sLevelDynamics[gCurrLevelNum][0])
+ {
return;
}
conditionBits = sLevelDynamics[gCurrLevelNum][1] & 0xff00;
- musicDynIndex = (u8) sLevelDynamics[gCurrLevelNum][1] & 0xff;
+ musicDynIndex = (u8)sLevelDynamics[gCurrLevelNum][1] & 0xff;
i = 2;
- while (conditionBits & 0xff00) {
+ while (conditionBits & 0xff00)
+ {
j = 0;
condIndex = 0;
bit = 0x8000;
- while (j < 8) {
- if (conditionBits & bit) {
+ while (j < 8)
+ {
+ if (conditionBits & bit)
+ {
conditionValues[condIndex] = sLevelDynamics[gCurrLevelNum][i++];
conditionTypes[condIndex] = j;
condIndex++;
@@ -1884,16 +2088,22 @@ void process_level_music_dynamics(void) {
bit = bit >> 1;
}
- for (j = 0; j < condIndex; j++) {
- switch (conditionTypes[j]) {
- case MARIO_IS_IN_AREA: {
- if (gCurrAreaIndex != conditionValues[j]) {
+ for (j = 0; j < condIndex; j++)
+ {
+ switch (conditionTypes[j])
+ {
+ case MARIO_IS_IN_AREA:
+ {
+ if (gCurrAreaIndex != conditionValues[j])
+ {
j = condIndex + 1;
}
break;
}
- case MARIO_IS_IN_ROOM: {
- if (gMarioCurrentRoom != conditionValues[j]) {
+ case MARIO_IS_IN_ROOM:
+ {
+ if (gMarioCurrentRoom != conditionValues[j])
+ {
j = condIndex + 1;
}
break;
@@ -1901,11 +2111,14 @@ void process_level_music_dynamics(void) {
}
}
- if (j == condIndex) {
+ if (j == condIndex)
+ {
// The area matches. Break out of the loop.
tempBits = 0;
- } else {
- tempBits = sLevelDynamics[gCurrLevelNum][i] & 0xff00;
+ }
+ else
+ {
+ tempBits = sLevelDynamics[gCurrLevelNum][i] & 0xff00;
musicDynIndex = sLevelDynamics[gCurrLevelNum][i] & 0xff;
i++;
}
@@ -1913,24 +2126,31 @@ void process_level_music_dynamics(void) {
conditionBits = tempBits;
}
- if (sCurrentMusicDynamic != musicDynIndex) {
+ if (sCurrentMusicDynamic != musicDynIndex)
+ {
tempBits = 1;
- if (sCurrentMusicDynamic == 0xff) {
+ if (sCurrentMusicDynamic == 0xff)
+ {
dur1 = 1;
dur2 = 1;
- } else {
+ }
+ else
+ {
dur1 = sMusicDynamics[musicDynIndex].dur1;
dur2 = sMusicDynamics[musicDynIndex].dur2;
}
- for (i = 0; i < CHANNELS_MAX; i++) {
+ for (i = 0; i < CHANNELS_MAX; i++)
+ {
conditionBits = tempBits;
tempBits = 0;
- if (sMusicDynamics[musicDynIndex].bits1 & conditionBits) {
+ if (sMusicDynamics[musicDynIndex].bits1 & conditionBits)
+ {
fade_channel_volume_scale(SEQ_PLAYER_LEVEL, i, sMusicDynamics[musicDynIndex].volScale1,
dur1);
}
- if (sMusicDynamics[musicDynIndex].bits2 & conditionBits) {
+ if (sMusicDynamics[musicDynIndex].bits2 & conditionBits)
+ {
fade_channel_volume_scale(SEQ_PLAYER_LEVEL, i, sMusicDynamics[musicDynIndex].volScale2,
dur2);
}
@@ -1941,22 +2161,31 @@ void process_level_music_dynamics(void) {
}
}
-void unused_8031FED0(u8 player, u32 bits, s8 arg2) {
+void unused_8031FED0(u8 player, u32 bits, s8 arg2)
+{
u8 i;
- if (arg2 < 0) {
+ if (arg2 < 0)
+ {
arg2 = -arg2;
}
- for (i = 0; i < CHANNELS_MAX; i++) {
- if (gSequencePlayers[player].channels[i] != &gSequenceChannelNone) {
- if ((bits & 3) == 0) {
+ for (i = 0; i < CHANNELS_MAX; i++)
+ {
+ if (gSequencePlayers[player].channels[i] != &gSequenceChannelNone)
+ {
+ if ((bits & 3) == 0)
+ {
gSequencePlayers[player].channels[i]->volumeScale = 1.0f;
- } else if ((bits & 1) != 0) {
- gSequencePlayers[player].channels[i]->volumeScale = (f32) arg2 / US_FLOAT(127.0);
- } else {
+ }
+ else if ((bits & 1) != 0)
+ {
+ gSequencePlayers[player].channels[i]->volumeScale = (f32)arg2 / US_FLOAT(127.0);
+ }
+ else
+ {
gSequencePlayers[player].channels[i]->volumeScale =
- US_FLOAT(1.0) - (f32) arg2 / US_FLOAT(127.0);
+ US_FLOAT(1.0) - (f32)arg2 / US_FLOAT(127.0);
}
}
bits >>= 2;
@@ -1970,11 +2199,15 @@ void unused_8031FED0(u8 player, u32 bits, s8 arg2) {
*
* Called from threads: thread5_game_loop
*/
-void seq_player_lower_volume(u8 player, u16 fadeDuration, u8 percentage) {
- if (player == SEQ_PLAYER_LEVEL) {
+void seq_player_lower_volume(u8 player, u16 fadeDuration, u8 percentage)
+{
+ if (player == SEQ_PLAYER_LEVEL)
+ {
sLowerBackgroundMusicVolume = TRUE;
begin_background_music_fade(fadeDuration);
- } else if (gSequencePlayers[player].enabled == TRUE) {
+ }
+ else if (gSequencePlayers[player].enabled == TRUE)
+ {
seq_player_fade_to_percentage_of_volume(player, fadeDuration, percentage);
}
}
@@ -1987,14 +2220,20 @@ void seq_player_lower_volume(u8 player, u16 fadeDuration, u8 percentage) {
*
* Called from threads: thread5_game_loop
*/
-void seq_player_unlower_volume(u8 player, u16 fadeDuration) {
+void seq_player_unlower_volume(u8 player, u16 fadeDuration)
+{
sLowerBackgroundMusicVolume = FALSE;
- if (player == SEQ_PLAYER_LEVEL) {
- if (gSequencePlayers[player].state != SEQUENCE_PLAYER_STATE_FADE_OUT) {
+ if (player == SEQ_PLAYER_LEVEL)
+ {
+ if (gSequencePlayers[player].state != SEQUENCE_PLAYER_STATE_FADE_OUT)
+ {
begin_background_music_fade(fadeDuration);
}
- } else {
- if (gSequencePlayers[player].enabled == TRUE) {
+ }
+ else
+ {
+ if (gSequencePlayers[player].enabled == TRUE)
+ {
seq_player_fade_to_normal_volume(player, fadeDuration);
}
}
@@ -2009,45 +2248,57 @@ void seq_player_unlower_volume(u8 player, u16 fadeDuration) {
*
* Called from threads: thread3_main, thread4_sound, thread5_game_loop
*/
-static u8 begin_background_music_fade(u16 fadeDuration) {
+static u8 begin_background_music_fade(u16 fadeDuration)
+{
u8 targetVolume = 0xff;
if (sCurrentBackgroundMusicSeqId == SEQUENCE_NONE
- || sCurrentBackgroundMusicSeqId == SEQ_EVENT_CUTSCENE_CREDITS) {
+ || sCurrentBackgroundMusicSeqId == SEQ_EVENT_CUTSCENE_CREDITS)
+ {
return 0xff;
}
- if (gSequencePlayers[SEQ_PLAYER_LEVEL].volume == 0.0f && fadeDuration) {
+ if (gSequencePlayers[SEQ_PLAYER_LEVEL].volume == 0.0f && fadeDuration)
+ {
gSequencePlayers[SEQ_PLAYER_LEVEL].volume = gSequencePlayers[SEQ_PLAYER_LEVEL].fadeVolume;
}
- if (sBackgroundMusicTargetVolume != TARGET_VOLUME_UNSET) {
- targetVolume = (sBackgroundMusicTargetVolume & TARGET_VOLUME_VALUE_MASK);
+ if (sBackgroundMusicTargetVolume != TARGET_VOLUME_UNSET)
+ {
+ targetVolume = sBackgroundMusicTargetVolume & TARGET_VOLUME_VALUE_MASK;
}
- if (sBackgroundMusicMaxTargetVolume != TARGET_VOLUME_UNSET) {
- u8 maxTargetVolume = (sBackgroundMusicMaxTargetVolume & TARGET_VOLUME_VALUE_MASK);
- if (targetVolume > maxTargetVolume) {
+ if (sBackgroundMusicMaxTargetVolume != TARGET_VOLUME_UNSET)
+ {
+ u8 maxTargetVolume = sBackgroundMusicMaxTargetVolume & TARGET_VOLUME_VALUE_MASK;
+ if (targetVolume > maxTargetVolume)
+ {
targetVolume = maxTargetVolume;
}
}
- if (sLowerBackgroundMusicVolume && targetVolume > 40) {
+ if (sLowerBackgroundMusicVolume && targetVolume > 40)
+ {
targetVolume = 40;
}
- if (sSoundBanksThatLowerBackgroundMusic != 0 && targetVolume > 20) {
+ if (sSoundBanksThatLowerBackgroundMusic != 0 && targetVolume > 20)
+ {
targetVolume = 20;
}
- if (gSequencePlayers[SEQ_PLAYER_LEVEL].enabled == TRUE) {
- if (targetVolume != 0xff) {
+ if (gSequencePlayers[SEQ_PLAYER_LEVEL].enabled == TRUE)
+ {
+ if (targetVolume != 0xff)
+ {
seq_player_fade_to_target_volume(SEQ_PLAYER_LEVEL, fadeDuration, targetVolume);
- } else {
-#if defined(VERSION_JP) || defined(VERSION_US)
+ }
+ else
+ {
+ #if defined(VERSION_JP) || defined(VERSION_US)
gSequencePlayers[SEQ_PLAYER_LEVEL].volume =
- sBackgroundMusicDefaultVolume[sCurrentBackgroundMusicSeqId] / 127.0f;
-#endif
+ sBackgroundMusicDefaultVolume[sCurrentBackgroundMusicSeqId] / 127.0f;
+ #endif
seq_player_fade_to_normal_volume(SEQ_PLAYER_LEVEL, fadeDuration);
}
}
@@ -2058,36 +2309,42 @@ static u8 begin_background_music_fade(u16 fadeDuration) {
/**
* Called from threads: thread5_game_loop
*/
-void set_audio_muted(u8 muted) {
+void set_audio_muted(u8 muted)
+{
u8 i;
- for (i = 0; i < SEQUENCE_PLAYERS; i++) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ for (i = 0; i < SEQUENCE_PLAYERS; i++)
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
if (muted)
func_802ad74c(0xf1000000, 0);
else
func_802ad74c(0xf2000000, 0);
-#else
+ #else
gSequencePlayers[i].muted = muted;
-#endif
+ #endif
}
}
/**
* Called from threads: thread4_sound
*/
-void sound_init(void) {
+void sound_init(void)
+{
u8 i;
u8 j;
- for (i = 0; i < SOUND_BANK_COUNT; i++) {
+ for (i = 0; i < SOUND_BANK_COUNT; i++)
+ {
// Set each sound in the bank to STOPPED
- for (j = 0; j < 40; j++) {
+ for (j = 0; j < 40; j++)
+ {
sSoundBanks[i][j].soundStatus = SOUND_STATUS_STOPPED;
}
// Remove current sounds
- for (j = 0; j < MAX_CHANNELS_PER_SOUND_BANK; j++) {
+ for (j = 0; j < MAX_CHANNELS_PER_SOUND_BANK; j++)
+ {
sCurrentSound[i][j] = 0xff;
}
@@ -2096,13 +2353,15 @@ void sound_init(void) {
sNumSoundsInBank[i] = 0;
}
- for (i = 0; i < SOUND_BANK_COUNT; i++) {
+ for (i = 0; i < SOUND_BANK_COUNT; i++)
+ {
// Set used list to empty
sSoundBanks[i][0].prev = 0xff;
sSoundBanks[i][0].next = 0xff;
// Set free list to contain every sound slot
- for (j = 1; j < 40 - 1; j++) {
+ for (j = 1; j < 40 - 1; j++)
+ {
sSoundBanks[i][j].prev = j - 1;
sSoundBanks[i][j].next = j + 1;
}
@@ -2110,13 +2369,16 @@ void sound_init(void) {
sSoundBanks[i][j].next = 0xff;
}
- for (j = 0; j < 3; j++) {
- for (i = 0; i < CHANNELS_MAX; i++) {
+ for (j = 0; j < 3; j++)
+ {
+ for (i = 0; i < CHANNELS_MAX; i++)
+ {
D_80360928[j][i].remainingFrames = 0;
}
}
- for (i = 0; i < MAX_BACKGROUND_MUSIC_QUEUE_SIZE; i++) {
+ for (i = 0; i < MAX_BACKGROUND_MUSIC_QUEUE_SIZE; i++)
+ {
sBackgroundMusicQueue[i].priority = 0;
}
@@ -2138,12 +2400,15 @@ void sound_init(void) {
}
// (unused)
-void get_currently_playing_sound(u8 bank, u8 *numPlayingSounds, u8 *numSoundsInBank, u8 *soundId) {
+void get_currently_playing_sound(u8 bank, u8 *numPlayingSounds, u8 *numSoundsInBank, u8 *soundId)
+{
u8 i;
u8 count = 0;
- for (i = 0; i < sMaxChannelsForSoundBank[bank]; i++) {
- if (sCurrentSound[bank][i] != 0xff) {
+ for (i = 0; i < sMaxChannelsForSoundBank[bank]; i++)
+ {
+ if (sCurrentSound[bank][i] != 0xff)
+ {
count++;
}
}
@@ -2151,9 +2416,12 @@ void get_currently_playing_sound(u8 bank, u8 *numPlayingSounds, u8 *numSoundsInB
*numSoundsInBank = sNumSoundsInBank[bank];
- if (sCurrentSound[bank][0] != 0xff) {
+ if (sCurrentSound[bank][0] != 0xff)
+ {
*soundId = (u8)(sSoundBanks[bank][sCurrentSound[bank][0]].soundBits >> SOUNDARGS_SHIFT_SOUNDID);
- } else {
+ }
+ else
+ {
*soundId = 0xff;
}
}
@@ -2161,21 +2429,25 @@ void get_currently_playing_sound(u8 bank, u8 *numPlayingSounds, u8 *numSoundsInB
/**
* Called from threads: thread5_game_loop
*/
-void stop_sound(u32 soundBits, f32 *pos) {
+void stop_sound(u32 soundBits, f32 *pos)
+{
u8 bank = (soundBits & SOUNDARGS_MASK_BANK) >> SOUNDARGS_SHIFT_BANK;
u8 soundIndex = sSoundBanks[bank][0].next;
- while (soundIndex != 0xff) {
+ while (soundIndex != 0xff)
+ {
// If sound has same id and source position pointer
if ((u16)(soundBits >> SOUNDARGS_SHIFT_SOUNDID)
- == (u16)(sSoundBanks[bank][soundIndex].soundBits >> SOUNDARGS_SHIFT_SOUNDID)
- && sSoundBanks[bank][soundIndex].x == pos) {
-
+ == (u16)(sSoundBanks[bank][soundIndex].soundBits >> SOUNDARGS_SHIFT_SOUNDID)
+ && sSoundBanks[bank][soundIndex].x == pos)
+ {
// Mark sound for deletion
update_background_music_after_sound(bank, soundIndex);
sSoundBanks[bank][soundIndex].soundBits = NO_SOUND;
soundIndex = 0xff; // break
- } else {
+ }
+ else
+ {
soundIndex = sSoundBanks[bank][soundIndex].next;
}
}
@@ -2184,14 +2456,18 @@ void stop_sound(u32 soundBits, f32 *pos) {
/**
* Called from threads: thread5_game_loop
*/
-void stop_sounds_from_source(f32 *pos) {
+void stop_sounds_from_source(f32 *pos)
+{
u8 bank;
u8 soundIndex;
- for (bank = 0; bank < SOUND_BANK_COUNT; bank++) {
+ for (bank = 0; bank < SOUND_BANK_COUNT; bank++)
+ {
soundIndex = sSoundBanks[bank][0].next;
- while (soundIndex != 0xff) {
- if (sSoundBanks[bank][soundIndex].x == pos) {
+ while (soundIndex != 0xff)
+ {
+ if (sSoundBanks[bank][soundIndex].x == pos)
+ {
update_background_music_after_sound(bank, soundIndex);
sSoundBanks[bank][soundIndex].soundBits = NO_SOUND;
}
@@ -2203,10 +2479,12 @@ void stop_sounds_from_source(f32 *pos) {
/**
* Called from threads: thread3_main, thread5_game_loop
*/
-static void stop_sounds_in_bank(u8 bank) {
+static void stop_sounds_in_bank(u8 bank)
+{
u8 soundIndex = sSoundBanks[bank][0].next;
- while (soundIndex != 0xff) {
+ while (soundIndex != 0xff)
+ {
update_background_music_after_sound(bank, soundIndex);
sSoundBanks[bank][soundIndex].soundBits = NO_SOUND;
soundIndex = sSoundBanks[bank][soundIndex].next;
@@ -2220,7 +2498,8 @@ static void stop_sounds_in_bank(u8 bank) {
*
* Called from threads: thread3_main, thread5_game_loop
*/
-void stop_sounds_in_continuous_banks(void) {
+void stop_sounds_in_continuous_banks(void)
+{
stop_sounds_in_bank(SOUND_BANK_MOVING);
stop_sounds_in_bank(SOUND_BANK_ENV);
stop_sounds_in_bank(SOUND_BANK_AIR);
@@ -2229,11 +2508,14 @@ void stop_sounds_in_continuous_banks(void) {
/**
* Called from threads: thread3_main, thread5_game_loop
*/
-void sound_banks_disable(UNUSED u8 player, u16 bankMask) {
+void sound_banks_disable(UNUSED u8 player, u16 bankMask)
+{
u8 i;
- for (i = 0; i < SOUND_BANK_COUNT; i++) {
- if (bankMask & 1) {
+ for (i = 0; i < SOUND_BANK_COUNT; i++)
+ {
+ if (bankMask & 1)
+ {
sSoundBankDisabled[i] = TRUE;
}
bankMask = bankMask >> 1;
@@ -2243,10 +2525,12 @@ void sound_banks_disable(UNUSED u8 player, u16 bankMask) {
/**
* Called from threads: thread5_game_loop
*/
-static void disable_all_sequence_players(void) {
+static void disable_all_sequence_players(void)
+{
u8 i;
- for (i = 0; i < SEQUENCE_PLAYERS; i++) {
+ for (i = 0; i < SEQUENCE_PLAYERS; i++)
+ {
sequence_player_disable(&gSequencePlayers[i]);
}
}
@@ -2254,26 +2538,33 @@ static void disable_all_sequence_players(void) {
/**
* Called from threads: thread5_game_loop
*/
-void sound_banks_enable(UNUSED u8 player, u16 bankMask) {
+void sound_banks_enable(UNUSED u8 player, u16 bankMask)
+{
u8 i;
- for (i = 0; i < SOUND_BANK_COUNT; i++) {
- if (bankMask & 1) {
+ for (i = 0; i < SOUND_BANK_COUNT; i++)
+ {
+ if (bankMask & 1)
+ {
sSoundBankDisabled[i] = FALSE;
}
bankMask = bankMask >> 1;
}
}
-u8 unused_803209D8(u8 player, u8 channelIndex, u8 arg2) {
+u8 unused_803209D8(u8 player, u8 channelIndex, u8 arg2)
+{
u8 ret = 0;
- if (gSequencePlayers[player].channels[channelIndex] != &gSequenceChannelNone) {
+ if (gSequencePlayers[player].channels[channelIndex] != &gSequenceChannelNone)
+ {
gSequencePlayers[player].channels[channelIndex]->stopSomething2 = arg2;
ret = arg2;
}
return ret;
}
-void func_80320A4C(u8 bankIndex, u8 arg1) {
+
+void func_80320A4C(u8 bankIndex, u8 arg1)
+{
sSoundMovingSpeed[bankIndex] = arg1;
}
@@ -2283,14 +2574,16 @@ void func_80320A4C(u8 bankIndex, u8 arg1) {
*
* Called from threads: thread5_game_loop
*/
-void set_sound_moving_speed(u8 bank, u8 speed) {
+void set_sound_moving_speed(u8 bank, u8 speed)
+{
sSoundMovingSpeed[bank] = speed;
}
/**
* Called from threads: thread5_game_loop
*/
-void play_music(u8 player, u16 seqArgs, u16 fadeTimer) {
+void play_music(u8 player, u16 seqArgs, u16 fadeTimer)
+{
u8 seqId = seqArgs & 0xff;
u8 priority = seqArgs >> 8;
u8 i;
@@ -2298,24 +2591,31 @@ void play_music(u8 player, u16 seqArgs, u16 fadeTimer) {
// Except for the background music player, we don't support queued
// sequences. Just play them immediately, stopping any old sequence.
- if (player != SEQ_PLAYER_LEVEL) {
+ if (player != SEQ_PLAYER_LEVEL)
+ {
seq_player_play_sequence(player, seqId, fadeTimer);
return;
}
// Abort if the queue is already full.
- if (sBackgroundMusicQueueSize == MAX_BACKGROUND_MUSIC_QUEUE_SIZE) {
+ if (sBackgroundMusicQueueSize == MAX_BACKGROUND_MUSIC_QUEUE_SIZE)
+ {
return;
}
// If already in the queue, abort, after first restarting the sequence if
// it is first, and handling disabled music somehow.
// (That handling probably ought to occur even when the queue is full...)
- for (i = 0; i < sBackgroundMusicQueueSize; i++) {
- if (sBackgroundMusicQueue[i].seqId == seqId) {
- if (i == 0) {
+ for (i = 0; i < sBackgroundMusicQueueSize; i++)
+ {
+ if (sBackgroundMusicQueue[i].seqId == seqId)
+ {
+ if (i == 0)
+ {
seq_player_play_sequence(SEQ_PLAYER_LEVEL, seqId, fadeTimer);
- } else if (!gSequencePlayers[SEQ_PLAYER_LEVEL].enabled) {
+ }
+ else if (!gSequencePlayers[SEQ_PLAYER_LEVEL].enabled)
+ {
stop_background_music(sBackgroundMusicQueue[0].seqId);
}
return;
@@ -2323,8 +2623,10 @@ void play_music(u8 player, u16 seqArgs, u16 fadeTimer) {
}
// Find the next sequence slot by priority.
- for (i = 0; i < sBackgroundMusicQueueSize; i++) {
- if (sBackgroundMusicQueue[i].priority <= priority) {
+ for (i = 0; i < sBackgroundMusicQueueSize; i++)
+ {
+ if (sBackgroundMusicQueue[i].priority <= priority)
+ {
foundIndex = i;
i = sBackgroundMusicQueueSize; // break
}
@@ -2332,14 +2634,16 @@ void play_music(u8 player, u16 seqArgs, u16 fadeTimer) {
// If the sequence ends up first in the queue, start it, and make space for
// one more entry in the queue.
- if (foundIndex == 0) {
+ if (foundIndex == 0)
+ {
seq_player_play_sequence(SEQ_PLAYER_LEVEL, seqId, fadeTimer);
sBackgroundMusicQueueSize++;
}
// Move all items up in queue, throwing away the last one if we didn't put
// the new sequence first.
- for (i = sBackgroundMusicQueueSize - 1; i > foundIndex; i--) {
+ for (i = sBackgroundMusicQueueSize - 1; i > foundIndex; i--)
+ {
sBackgroundMusicQueue[i].priority = sBackgroundMusicQueue[i - 1].priority;
sBackgroundMusicQueue[i].seqId = sBackgroundMusicQueue[i - 1].seqId;
}
@@ -2352,11 +2656,13 @@ void play_music(u8 player, u16 seqArgs, u16 fadeTimer) {
/**
* Called from threads: thread5_game_loop
*/
-void stop_background_music(u16 seqId) {
+void stop_background_music(u16 seqId)
+{
u8 foundIndex;
u8 i;
- if (sBackgroundMusicQueueSize == 0) {
+ if (sBackgroundMusicQueueSize == 0)
+ {
return;
}
@@ -2365,15 +2671,21 @@ void stop_background_music(u16 seqId) {
foundIndex = sBackgroundMusicQueueSize;
// Search for the sequence.
- for (i = 0; i < sBackgroundMusicQueueSize; i++) {
- if (sBackgroundMusicQueue[i].seqId == (u8)(seqId & 0xff)) {
+ for (i = 0; i < sBackgroundMusicQueueSize; i++)
+ {
+ if (sBackgroundMusicQueue[i].seqId == (u8)(seqId & 0xff))
+ {
// Remove sequence from queue. If it was first, play the next one,
// or fade out the music.
sBackgroundMusicQueueSize--;
- if (i == 0) {
- if (sBackgroundMusicQueueSize != 0) {
+ if (i == 0)
+ {
+ if (sBackgroundMusicQueueSize != 0)
+ {
seq_player_play_sequence(SEQ_PLAYER_LEVEL, sBackgroundMusicQueue[1].seqId, 0);
- } else {
+ }
+ else
+ {
seq_player_fade_out(SEQ_PLAYER_LEVEL, 20);
}
}
@@ -2383,7 +2695,8 @@ void stop_background_music(u16 seqId) {
}
// Move later slots down.
- for (i = foundIndex; i < sBackgroundMusicQueueSize; i++) {
+ for (i = foundIndex; i < sBackgroundMusicQueueSize; i++)
+ {
sBackgroundMusicQueue[i].priority = sBackgroundMusicQueue[i + 1].priority;
sBackgroundMusicQueue[i].seqId = sBackgroundMusicQueue[i + 1].seqId;
}
@@ -2396,8 +2709,10 @@ void stop_background_music(u16 seqId) {
/**
* Called from threads: thread5_game_loop
*/
-void fadeout_background_music(u16 seqId, u16 fadeOut) {
- if (sBackgroundMusicQueueSize != 0 && sBackgroundMusicQueue[0].seqId == (u8)(seqId & 0xff)) {
+void fadeout_background_music(u16 seqId, u16 fadeOut)
+{
+ if (sBackgroundMusicQueueSize != 0 && sBackgroundMusicQueue[0].seqId == (u8)(seqId & 0xff))
+ {
seq_player_fade_out(SEQ_PLAYER_LEVEL, fadeOut);
}
}
@@ -2405,8 +2720,10 @@ void fadeout_background_music(u16 seqId, u16 fadeOut) {
/**
* Called from threads: thread5_game_loop
*/
-void drop_queued_background_music(void) {
- if (sBackgroundMusicQueueSize != 0) {
+void drop_queued_background_music(void)
+{
+ if (sBackgroundMusicQueueSize != 0)
+ {
sBackgroundMusicQueueSize = 1;
}
}
@@ -2414,8 +2731,10 @@ void drop_queued_background_music(void) {
/**
* Called from threads: thread5_game_loop
*/
-u16 get_current_background_music(void) {
- if (sBackgroundMusicQueueSize != 0) {
+u16 get_current_background_music(void)
+{
+ if (sBackgroundMusicQueueSize != 0)
+ {
return (sBackgroundMusicQueue[0].priority << 8) + sBackgroundMusicQueue[0].seqId;
}
return -1;
@@ -2424,18 +2743,21 @@ u16 get_current_background_music(void) {
/**
* Called from threads: thread4_sound, thread5_game_loop (EU only)
*/
-void func_80320ED8(void) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
- if (D_EU_80300558 != 0) {
+void func_80320ED8(void)
+{
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ if (D_EU_80300558 != 0)
+ {
D_EU_80300558--;
}
if (gSequencePlayers[SEQ_PLAYER_ENV].enabled
|| sBackgroundMusicMaxTargetVolume == TARGET_VOLUME_UNSET || D_EU_80300558 != 0) {
-#else
+ #else
if (gSequencePlayers[SEQ_PLAYER_ENV].enabled
- || sBackgroundMusicMaxTargetVolume == TARGET_VOLUME_UNSET) {
-#endif
+ || sBackgroundMusicMaxTargetVolume == TARGET_VOLUME_UNSET)
+ {
+ #endif
return;
}
@@ -2443,9 +2765,11 @@ void func_80320ED8(void) {
begin_background_music_fade(50);
if (sBackgroundMusicTargetVolume != TARGET_VOLUME_UNSET
- && (D_80332120 == SEQ_EVENT_MERRY_GO_ROUND || D_80332120 == SEQ_EVENT_PIRANHA_PLANT)) {
+ && (D_80332120 == SEQ_EVENT_MERRY_GO_ROUND || D_80332120 == SEQ_EVENT_PIRANHA_PLANT))
+ {
seq_player_play_sequence(SEQ_PLAYER_ENV, D_80332120, 1);
- if (D_80332124 != 0xff) {
+ if (D_80332124 != 0xff)
+ {
seq_player_fade_to_target_volume(SEQ_PLAYER_ENV, 1, D_80332124);
}
}
@@ -2454,24 +2778,30 @@ void func_80320ED8(void) {
/**
* Called from threads: thread5_game_loop
*/
-void play_secondary_music(u8 seqId, u8 bgMusicVolume, u8 volume, u16 fadeTimer) {
+void play_secondary_music(u8 seqId, u8 bgMusicVolume, u8 volume, u16 fadeTimer)
+{
UNUSED u32 dummy;
sUnused80332118 = 0;
- if (sCurrentBackgroundMusicSeqId == 0xff || sCurrentBackgroundMusicSeqId == SEQ_MENU_TITLE_SCREEN) {
+ if (sCurrentBackgroundMusicSeqId == 0xff || sCurrentBackgroundMusicSeqId == SEQ_MENU_TITLE_SCREEN)
+ {
return;
}
- if (sBackgroundMusicTargetVolume == TARGET_VOLUME_UNSET) {
+ if (sBackgroundMusicTargetVolume == TARGET_VOLUME_UNSET)
+ {
sBackgroundMusicTargetVolume = bgMusicVolume + TARGET_VOLUME_IS_PRESENT_FLAG;
begin_background_music_fade(fadeTimer);
seq_player_play_sequence(SEQ_PLAYER_ENV, seqId, fadeTimer >> 1);
- if (volume < 0x80) {
+ if (volume < 0x80)
+ {
seq_player_fade_to_target_volume(SEQ_PLAYER_ENV, fadeTimer, volume);
}
D_80332124 = volume;
D_80332120 = seqId;
- } else if (volume != 0xff) {
+ }
+ else if (volume != 0xff)
+ {
sBackgroundMusicTargetVolume = bgMusicVolume + TARGET_VOLUME_IS_PRESENT_FLAG;
begin_background_music_fade(fadeTimer);
seq_player_fade_to_target_volume(SEQ_PLAYER_ENV, fadeTimer, volume);
@@ -2482,8 +2812,10 @@ void play_secondary_music(u8 seqId, u8 bgMusicVolume, u8 volume, u16 fadeTimer)
/**
* Called from threads: thread5_game_loop
*/
-void func_80321080(u16 fadeTimer) {
- if (sBackgroundMusicTargetVolume != TARGET_VOLUME_UNSET) {
+void func_80321080(u16 fadeTimer)
+{
+ if (sBackgroundMusicTargetVolume != TARGET_VOLUME_UNSET)
+ {
sBackgroundMusicTargetVolume = TARGET_VOLUME_UNSET;
D_80332120 = 0;
D_80332124 = 0;
@@ -2495,31 +2827,37 @@ void func_80321080(u16 fadeTimer) {
/**
* Called from threads: thread3_main, thread5_game_loop
*/
-void func_803210D4(u16 fadeDuration) {
+void func_803210D4(u16 fadeDuration)
+{
u8 i;
- if (sHasStartedFadeOut) {
+ if (sHasStartedFadeOut)
+ {
return;
}
- if (gSequencePlayers[SEQ_PLAYER_LEVEL].enabled == TRUE) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ if (gSequencePlayers[SEQ_PLAYER_LEVEL].enabled == TRUE)
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad74c(0x83000000, fadeDuration);
-#else
+ #else
seq_player_fade_to_zero_volume(SEQ_PLAYER_LEVEL, fadeDuration);
-#endif
+ #endif
}
- if (gSequencePlayers[SEQ_PLAYER_ENV].enabled == TRUE) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ if (gSequencePlayers[SEQ_PLAYER_ENV].enabled == TRUE)
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad74c(0x83010000, fadeDuration);
-#else
+ #else
seq_player_fade_to_zero_volume(SEQ_PLAYER_ENV, fadeDuration);
-#endif
+ #endif
}
- for (i = 0; i < SOUND_BANK_COUNT; i++) {
- if (i != SOUND_BANK_MENU) {
+ for (i = 0; i < SOUND_BANK_COUNT; i++)
+ {
+ if (i != SOUND_BANK_MENU)
+ {
fade_channel_volume_scale(SEQ_PLAYER_SFX, i, 0, fadeDuration / 16);
}
}
@@ -2530,24 +2868,26 @@ void func_803210D4(u16 fadeDuration) {
/**
* Called from threads: thread5_game_loop
*/
-void play_course_clear(void) {
+void play_course_clear(void)
+{
seq_player_play_sequence(SEQ_PLAYER_ENV, SEQ_EVENT_CUTSCENE_COLLECT_STAR, 0);
sBackgroundMusicMaxTargetVolume = TARGET_VOLUME_IS_PRESENT_FLAG | 0;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
D_EU_80300558 = 2;
-#endif
+ #endif
begin_background_music_fade(50);
}
/**
* Called from threads: thread5_game_loop
*/
-void play_peachs_jingle(void) {
+void play_peachs_jingle(void)
+{
seq_player_play_sequence(SEQ_PLAYER_ENV, SEQ_EVENT_PEACH_MESSAGE, 0);
sBackgroundMusicMaxTargetVolume = TARGET_VOLUME_IS_PRESENT_FLAG | 0;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
D_EU_80300558 = 2;
-#endif
+ #endif
begin_background_music_fade(50);
}
@@ -2558,89 +2898,98 @@ void play_peachs_jingle(void) {
*
* Called from threads: thread5_game_loop
*/
-void play_puzzle_jingle(void) {
+void play_puzzle_jingle(void)
+{
seq_player_play_sequence(SEQ_PLAYER_ENV, SEQ_EVENT_SOLVE_PUZZLE, 0);
sBackgroundMusicMaxTargetVolume = TARGET_VOLUME_IS_PRESENT_FLAG | 20;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
D_EU_80300558 = 2;
-#endif
+ #endif
begin_background_music_fade(50);
}
/**
* Called from threads: thread5_game_loop
*/
-void play_star_fanfare(void) {
+void play_star_fanfare(void)
+{
seq_player_play_sequence(SEQ_PLAYER_ENV, SEQ_EVENT_HIGH_SCORE, 0);
sBackgroundMusicMaxTargetVolume = TARGET_VOLUME_IS_PRESENT_FLAG | 20;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
D_EU_80300558 = 2;
-#endif
+ #endif
begin_background_music_fade(50);
}
/**
* Called from threads: thread5_game_loop
*/
-void play_power_star_jingle(u8 arg0) {
- if (!arg0) {
+void play_power_star_jingle(u8 arg0)
+{
+ if (!arg0)
+ {
sBackgroundMusicTargetVolume = 0;
}
seq_player_play_sequence(SEQ_PLAYER_ENV, SEQ_EVENT_CUTSCENE_STAR_SPAWN, 0);
sBackgroundMusicMaxTargetVolume = TARGET_VOLUME_IS_PRESENT_FLAG | 20;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
D_EU_80300558 = 2;
-#endif
+ #endif
begin_background_music_fade(50);
}
/**
* Called from threads: thread5_game_loop
*/
-void play_race_fanfare(void) {
+void play_race_fanfare(void)
+{
seq_player_play_sequence(SEQ_PLAYER_ENV, SEQ_EVENT_RACE, 0);
sBackgroundMusicMaxTargetVolume = TARGET_VOLUME_IS_PRESENT_FLAG | 20;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
D_EU_80300558 = 2;
-#endif
+ #endif
begin_background_music_fade(50);
}
/**
* Called from threads: thread5_game_loop
*/
-void play_toads_jingle(void) {
+void play_toads_jingle(void)
+{
seq_player_play_sequence(SEQ_PLAYER_ENV, SEQ_EVENT_TOAD_MESSAGE, 0);
sBackgroundMusicMaxTargetVolume = TARGET_VOLUME_IS_PRESENT_FLAG | 20;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
D_EU_80300558 = 2;
-#endif
+ #endif
begin_background_music_fade(50);
}
/**
* Called from threads: thread5_game_loop
*/
-void sound_reset(u8 presetId) {
-#ifndef VERSION_JP
- if (presetId >= 8) {
+void sound_reset(u8 presetId)
+{
+ #ifndef VERSION_JP
+ if (presetId >= 8)
+ {
presetId = 0;
sUnused8033323C = 0;
}
-#endif
+ #endif
sGameLoopTicked = 0;
disable_all_sequence_players();
sound_init();
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
func_802ad74c(0xF2000000, 0);
-#endif
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #endif
+ #if defined(VERSION_JP) || defined(VERSION_US)
audio_reset_session(&gAudioSessionPresets[presetId]);
-#else
+ #else
audio_reset_session_eu(presetId);
-#endif
+ #endif
osWritebackDCacheAll();
- if (presetId != 7) {
+ if (presetId != 7)
+ {
preload_sequence(SEQ_EVENT_SOLVE_PUZZLE, PRELOAD_BANKS | PRELOAD_SEQUENCE);
preload_sequence(SEQ_EVENT_PEACH_MESSAGE, PRELOAD_BANKS | PRELOAD_SEQUENCE);
preload_sequence(SEQ_EVENT_CUTSCENE_STAR_SPAWN, PRELOAD_BANKS | PRELOAD_SEQUENCE);
@@ -2654,15 +3003,18 @@ void sound_reset(u8 presetId) {
/**
* Called from threads: thread5_game_loop
*/
-void audio_set_sound_mode(u8 soundMode) {
+void audio_set_sound_mode(u8 soundMode)
+{
D_80332108 = (D_80332108 & 0xf) + (soundMode << 4);
gSoundMode = soundMode;
}
#if defined(VERSION_JP) || defined(VERSION_US)
-void unused_80321460(UNUSED s32 arg0, UNUSED s32 arg1, UNUSED s32 arg2, UNUSED s32 arg3) {
+void unused_80321460(UNUSED s32 arg0, UNUSED s32 arg1, UNUSED s32 arg2, UNUSED s32 arg3)
+{
}
-void unused_80321474(UNUSED s32 arg0) {
+void unused_80321474(UNUSED s32 arg0)
+{
}
#endif
diff --git a/src/decomp/audio/external.h b/src/decomp/audio/external.h
index 00c6d39..bc87d84 100644
--- a/src/decomp/audio/external.h
+++ b/src/decomp/audio/external.h
@@ -24,7 +24,8 @@ extern u32 gAudioRandom;
extern f32 gAudioVolume;
extern u8 gAudioReverb;
-struct Sound {
+struct Sound
+{
s32 soundBits;
f32 *position;
}; // size = 0x8
@@ -35,39 +36,73 @@ extern u8 sSoundRequestCount;
extern u8 gAudioSPTaskYieldBuffer[]; // ucode yield data ptr; only used in JP
struct SPTask *create_next_audio_frame_task(void);
+
void create_next_audio_buffer(s16 *samples, u32 num_samples);
+
void audio_signal_game_loop_tick(void);
+
void update_game_sound(void);
+
void seq_player_fade_out(u8 player, u16 fadeDuration);
+
void fade_volume_scale(u8 player, u8 targetScale, u16 fadeDuration);
+
void seq_player_lower_volume(u8 player, u16 fadeDuration, u8 percentage);
+
void seq_player_unlower_volume(u8 player, u16 fadeDuration);
+
void set_audio_muted(u8 muted);
+
void sound_init(void);
+
void get_currently_playing_sound(u8 bank, u8 *numPlayingSounds, u8 *numSoundsInBank, u8 *soundId);
+
void stop_sound(u32 soundBits, f32 *pos);
-void stop_sounds_from_source(f32 *pos);
+
+void stop_sounds_from_source(f32 * pos);
+
void stop_sounds_in_continuous_banks(void);
+
void sound_banks_disable(u8 player, u16 bankMask);
+
void sound_banks_enable(u8 player, u16 bankMask);
+
void set_sound_moving_speed(u8 bank, u8 speed);
+
void play_dialog_sound(u8 dialogID);
+
void play_music(u8 player, u16 seqArgs, u16 fadeTimer);
+
void stop_background_music(u16 seqId);
+
void fadeout_background_music(u16 arg0, u16 fadeOut);
+
void drop_queued_background_music(void);
+
u16 get_current_background_music(void);
+
void play_secondary_music(u8 seqId, u8 bgMusicVolume, u8 volume, u16 fadeTimer);
+
void func_80321080(u16 fadeTimer);
+
void func_803210D4(u16 fadeOutTime);
+
void play_course_clear(void);
+
void play_peachs_jingle(void);
+
void play_puzzle_jingle(void);
+
void play_star_fanfare(void);
+
void play_power_star_jingle(u8 arg0);
+
void play_race_fanfare(void);
+
void play_toads_jingle(void);
+
void sound_reset(u8 presetId);
+
void audio_set_sound_mode(u8 arg0);
void audio_init(void); // in load.c
diff --git a/src/decomp/audio/heap.c b/src/decomp/audio/heap.c
index c11c24c..9475bd3 100644
--- a/src/decomp/audio/heap.c
+++ b/src/decomp/audio/heap.c
@@ -17,14 +17,16 @@ ALIGNED16 u8 gAudioHeap[DOUBLE_SIZE_ON_64_BIT(0x31200) - 0x4800];
ALIGNED16 u8 gAudioHeap[DOUBLE_SIZE_ON_64_BIT(0x31200)];
#endif
-struct PoolSplit {
+struct PoolSplit
+{
u32 wantSeq;
u32 wantBank;
u32 wantUnused;
u32 wantCustom;
}; // size = 0x10
-struct PoolSplit2 {
+struct PoolSplit2
+{
u32 wantPersistent;
u32 wantTemporary;
}; // size = 0x8
@@ -99,16 +101,20 @@ f64 root_newton_step(f64 x, s32 k, f64 d)
f64 fx;
f64 deriv = deg8;
- if (degree & 1) {
+ if (degree & 1)
+ {
deriv *= x;
}
- if (degree & 2) {
+ if (degree & 2)
+ {
deriv *= deg2;
}
- if (degree & 4) {
+ if (degree & 4)
+ {
deriv *= deg4;
}
- if (degree & 8) {
+ if (degree & 8)
+ {
deriv *= deg8;
}
fx = deriv * x - d;
@@ -122,28 +128,38 @@ f64 root_newton_step(f64 x, s32 k, f64 d)
*
* @return the root, or 1.0 if d is 0
*/
-f64 kth_root(f64 d, s32 k) {
+f64 kth_root(f64 d, s32 k)
+{
f64 root = 1.5;
f64 next;
f64 diff;
s32 i;
- if (d == 0.0) {
+ if (d == 0.0)
+ {
root = 1.0;
- } else {
- for (i = 0; i < 64; i++) {
- if (1) {
+ }
+ else
+ {
+ for (i = 0; i < 64; i++)
+ {
+ if (1)
+ {
}
next = root_newton_step(root, k, d);
diff = next - root;
- if (diff < 0) {
+ if (diff < 0)
+ {
diff = -diff;
}
- if (diff < 1e-07) {
+ if (diff < 1e-07)
+ {
root = next;
break;
- } else {
+ }
+ else
+ {
root = next;
}
}
@@ -152,80 +168,96 @@ f64 kth_root(f64 d, s32 k) {
return root;
}
-void build_vol_rampings_table(s32 UNUSED unused, s32 len) {
+void build_vol_rampings_table(s32 UNUSED unused, s32 len)
+{
s32 i;
s32 step;
s32 d;
s32 k = len / 8;
- for (step = 0, i = 0; i < 0x400; step += 32, i++) {
+ for (step = 0, i = 0; i < 0x400; step += 32, i++)
+ {
d = step;
- if (step == 0) {
+ if (step == 0)
+ {
d = 1;
}
- gLeftVolRampings[0][i] = kth_root( d, k - 1);
+ gLeftVolRampings[0][i] = kth_root(d, k - 1);
gRightVolRampings[0][i] = kth_root(1.0 / d, k - 1) * 65536.0;
- gLeftVolRampings[1][i] = kth_root( d, k);
+ gLeftVolRampings[1][i] = kth_root(d, k);
gRightVolRampings[1][i] = kth_root(1.0 / d, k) * 65536.0;
- gLeftVolRampings[2][i] = kth_root( d, k + 1);
+ gLeftVolRampings[2][i] = kth_root(d, k + 1);
gRightVolRampings[2][i] = kth_root(1.0 / d, k + 1) * 65536.0;
}
}
#endif
-void reset_bank_and_seq_load_status(void) {
+void reset_bank_and_seq_load_status(void)
+{
s32 i;
-#ifdef VERSION_SH
- for (i = 0; i < 64; i++) {
- if (gBankLoadStatus[i] != SOUND_LOAD_STATUS_5) {
+ #ifdef VERSION_SH
+ for (i = 0; i < 64; i++)
+ {
+ if (gBankLoadStatus[i] != SOUND_LOAD_STATUS_5)
+ {
gBankLoadStatus[i] = SOUND_LOAD_STATUS_NOT_LOADED;
}
}
- for (i = 0; i < 64; i++) {
- if (gUnkLoadStatus[i] != SOUND_LOAD_STATUS_5) {
+ for (i = 0; i < 64; i++)
+ {
+ if (gUnkLoadStatus[i] != SOUND_LOAD_STATUS_5)
+ {
gUnkLoadStatus[i] = SOUND_LOAD_STATUS_NOT_LOADED;
}
}
- for (i = 0; i < 256; i++) {
- if (gSeqLoadStatus[i] != SOUND_LOAD_STATUS_5) {
+ for (i = 0; i < 256; i++)
+ {
+ if (gSeqLoadStatus[i] != SOUND_LOAD_STATUS_5)
+ {
gSeqLoadStatus[i] = SOUND_LOAD_STATUS_NOT_LOADED;
}
}
-#else
- for (i = 0; i < 64; i++) {
+ #else
+ for (i = 0; i < 64; i++)
+ {
gBankLoadStatus[i] = SOUND_LOAD_STATUS_NOT_LOADED;
}
- for (i = 0; i < 256; i++) {
+ for (i = 0; i < 256; i++)
+ {
gSeqLoadStatus[i] = SOUND_LOAD_STATUS_NOT_LOADED;
}
-#endif
+ #endif
}
-void discard_bank(s32 bankId) {
+void discard_bank(s32 bankId)
+{
s32 i;
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
struct Note *note = &gNotes[i];
-#if defined(VERSION_EU)
+ #if defined(VERSION_EU)
if (note->noteSubEu.bankId == bankId) {
-#else
- if (note->bankId == bankId) {
-#endif
+ #else
+ if (note->bankId == bankId)
+ {
+ #endif
// (These prints are unclear. Arguments are picked semi-randomly.)
eu_stubbed_printf_1("Warning:Kill Note %x \n", i);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
if (note->unkSH34 == NOTE_PRIORITY_DISABLED && note->priority) {
-#else
- if (note->priority >= NOTE_PRIORITY_MIN) {
-#endif
+ #else
+ if (note->priority >= NOTE_PRIORITY_MIN)
+ {
+ #endif
eu_stubbed_printf_3("Kill Voice %d (ID %d) %d\n", note->waveId,
- bankId, note->priority);
+ bankId, note->priority);
eu_stubbed_printf_0("Warning: Running Sequence's data disappear!\n");
note->parentLayer->enabled = FALSE; // is 0x48, should be 0x44
note->parentLayer->finished = TRUE;
@@ -237,47 +269,59 @@ void discard_bank(s32 bankId) {
}
}
-void discard_sequence(s32 seqId) {
+void discard_sequence(s32 seqId)
+{
s32 i;
- for (i = 0; i < SEQUENCE_PLAYERS; i++) {
- if (gSequencePlayers[i].enabled && gSequencePlayers[i].seqId == seqId) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ for (i = 0; i < SEQUENCE_PLAYERS; i++)
+ {
+ if (gSequencePlayers[i].enabled && gSequencePlayers[i].seqId == seqId)
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
sequence_player_disable(&gSequencePlayers[i]);
-#else
+ #else
sequence_player_disable(gSequencePlayers + i);
-#endif
+ #endif
}
}
}
-void *soundAlloc(struct SoundAllocPool *pool, u32 size) {
+void *soundAlloc(struct SoundAllocPool *pool, u32 size)
+{
u8 *start;
s32 last;
s32 i;
- if ((pool->cur + ALIGN16(size) <= pool->size + pool->start)) {
+ if (pool->cur + ALIGN16(size) <= pool->size + pool->start)
+ {
start = pool->cur;
pool->cur += ALIGN16(size);
last = pool->cur - start - 1;
- for (i = 0; i <= last; i++) {
+ for (i = 0; i <= last; i++)
+ {
start[i] = 0;
}
- } else {
+ }
+ else
+ {
return NULL;
}
return start;
}
#ifdef VERSION_SH
-void *sound_alloc_uninitialized(struct SoundAllocPool *pool, u32 size) {
+void *sound_alloc_uninitialized(struct SoundAllocPool *pool, u32 size)
+{
u8 *start;
u32 alignedSize = ALIGN16(size);
start = pool->cur;
- if (start + alignedSize <= pool->start + pool->size) {
+ if (start + alignedSize <= pool->start + pool->size)
+ {
pool->cur += alignedSize;
- } else {
+ }
+ else
+ {
return NULL;
}
@@ -286,43 +330,49 @@ void *sound_alloc_uninitialized(struct SoundAllocPool *pool, u32 size) {
}
#endif
-void sound_alloc_pool_init(struct SoundAllocPool *pool, void *memAddr, u32 size) {
- pool->cur = pool->start = (u8 *) ALIGN16((uintptr_t) memAddr);
-#ifdef VERSION_SH
- pool->size = size - ((uintptr_t) memAddr & 0xf);
-#else
+void sound_alloc_pool_init(struct SoundAllocPool *pool, void *memAddr, u32 size)
+{
+ pool->cur = pool->start = (u8 *)ALIGN16((uintptr_t) memAddr);
+ #ifdef VERSION_SH
+ pool->size = size - ((uintptr_t)memAddr & 0xf);
+ #else
pool->size = size;
-#endif
+ #endif
pool->numAllocatedEntries = 0;
}
-void persistent_pool_clear(struct PersistentPool *persistent) {
+void persistent_pool_clear(struct PersistentPool *persistent)
+{
persistent->pool.numAllocatedEntries = 0;
persistent->pool.cur = persistent->pool.start;
persistent->numEntries = 0;
}
-void temporary_pool_clear(struct TemporaryPool *temporary) {
+void temporary_pool_clear(struct TemporaryPool *temporary)
+{
temporary->pool.numAllocatedEntries = 0;
temporary->pool.cur = temporary->pool.start;
temporary->nextSide = 0;
temporary->entries[0].ptr = temporary->pool.start;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
temporary->entries[1].ptr = temporary->pool.start + temporary->pool.size;
-#else
+ #else
temporary->entries[1].ptr = temporary->pool.size + temporary->pool.start;
-#endif
+ #endif
temporary->entries[0].id = -1; // should be at 1e not 1c
temporary->entries[1].id = -1;
}
-void unused_803160F8(struct SoundAllocPool *pool) {
+void unused_803160F8(struct SoundAllocPool *pool)
+{
pool->numAllocatedEntries = 0;
pool->cur = pool->start;
}
extern s32 D_SH_80315EE8;
-void sound_init_main_pools(s32 sizeForAudioInitPool) {
+
+void sound_init_main_pools(s32 sizeForAudioInitPool)
+{
sound_alloc_pool_init(&gAudioInitPool, gAudioHeap, sizeForAudioInitPool);
sound_alloc_pool_init(&gAudioSessionPool, gAudioHeap + sizeForAudioInitPool, gAudioHeapSize - sizeForAudioInitPool);
}
@@ -333,35 +383,39 @@ void sound_init_main_pools(s32 sizeForAudioInitPool) {
#define SOUND_ALLOC_FUNC soundAlloc
#endif
-void session_pools_init(struct PoolSplit *a) {
+void session_pools_init(struct PoolSplit *a)
+{
gAudioSessionPool.cur = gAudioSessionPool.start;
sound_alloc_pool_init(&gNotesAndBuffersPool, SOUND_ALLOC_FUNC(&gAudioSessionPool, a->wantSeq), a->wantSeq);
sound_alloc_pool_init(&gSeqAndBankPool, SOUND_ALLOC_FUNC(&gAudioSessionPool, a->wantCustom), a->wantCustom);
}
-void seq_and_bank_pool_init(struct PoolSplit2 *a) {
+void seq_and_bank_pool_init(struct PoolSplit2 *a)
+{
gSeqAndBankPool.cur = gSeqAndBankPool.start;
sound_alloc_pool_init(&gPersistentCommonPool, SOUND_ALLOC_FUNC(&gSeqAndBankPool, a->wantPersistent), a->wantPersistent);
sound_alloc_pool_init(&gTemporaryCommonPool, SOUND_ALLOC_FUNC(&gSeqAndBankPool, a->wantTemporary), a->wantTemporary);
}
-void persistent_pools_init(struct PoolSplit *a) {
+void persistent_pools_init(struct PoolSplit *a)
+{
gPersistentCommonPool.cur = gPersistentCommonPool.start;
sound_alloc_pool_init(&gSeqLoadedPool.persistent.pool, SOUND_ALLOC_FUNC(&gPersistentCommonPool, a->wantSeq), a->wantSeq);
sound_alloc_pool_init(&gBankLoadedPool.persistent.pool, SOUND_ALLOC_FUNC(&gPersistentCommonPool, a->wantBank), a->wantBank);
sound_alloc_pool_init(&gUnusedLoadedPool.persistent.pool, SOUND_ALLOC_FUNC(&gPersistentCommonPool, a->wantUnused),
- a->wantUnused);
+ a->wantUnused);
persistent_pool_clear(&gSeqLoadedPool.persistent);
persistent_pool_clear(&gBankLoadedPool.persistent);
persistent_pool_clear(&gUnusedLoadedPool.persistent);
}
-void temporary_pools_init(struct PoolSplit *a) {
+void temporary_pools_init(struct PoolSplit *a)
+{
gTemporaryCommonPool.cur = gTemporaryCommonPool.start;
sound_alloc_pool_init(&gSeqLoadedPool.temporary.pool, SOUND_ALLOC_FUNC(&gTemporaryCommonPool, a->wantSeq), a->wantSeq);
sound_alloc_pool_init(&gBankLoadedPool.temporary.pool, SOUND_ALLOC_FUNC(&gTemporaryCommonPool, a->wantBank), a->wantBank);
sound_alloc_pool_init(&gUnusedLoadedPool.temporary.pool, SOUND_ALLOC_FUNC(&gTemporaryCommonPool, a->wantUnused),
- a->wantUnused);
+ a->wantUnused);
temporary_pool_clear(&gSeqLoadedPool.temporary);
temporary_pool_clear(&gBankLoadedPool.temporary);
temporary_pool_clear(&gUnusedLoadedPool.temporary);
@@ -369,48 +423,54 @@ void temporary_pools_init(struct PoolSplit *a) {
#undef SOUND_ALLOC_FUNC
#if defined(VERSION_JP) || defined(VERSION_US)
-UNUSED static void unused_803163D4(void) {
+UNUSED static void unused_803163D4(void)
+{
}
#endif
#ifdef VERSION_SH
-void *alloc_bank_or_seq(s32 poolIdx, s32 size, s32 arg3, s32 id) {
+void *alloc_bank_or_seq(s32 poolIdx, s32 size, s32 arg3, s32 id)
+{
+
+
#else
-void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg3, s32 id) {
-#endif
+void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg3, s32 id)
+{
+ #endif
// arg3 = 0, 1 or 2?
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
struct SoundMultiPool *arg0;
-#define isSound poolIdx
-#endif
+ #define isSound poolIdx
+ #endif
struct TemporaryPool *tp;
struct SoundAllocPool *pool;
void *ret;
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #if defined(VERSION_JP) || defined(VERSION_US)
u16 UNUSED _firstVal;
u16 UNUSED _secondVal;
-#else
+ #else
u16 firstVal;
u16 secondVal;
-#endif
+ #endif
u32 nullID = -1;
UNUSED s32 i;
u8 *table;
-#ifndef VERSION_SH
+ #ifndef VERSION_SH
u8 isSound;
-#endif
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #endif
+ #if defined(VERSION_JP) || defined(VERSION_US)
u16 firstVal;
u16 secondVal;
u32 bothDiscardable;
u32 leftDiscardable, rightDiscardable;
u32 leftNotLoaded, rightNotLoaded;
u32 leftAvail, rightAvail;
-#endif
+ #endif
-#ifdef VERSION_SH
- switch (poolIdx) {
+ #ifdef VERSION_SH
+ switch (poolIdx)
+ {
case 0:
arg0 = &gSeqLoadedPool;
table = gSeqLoadStatus;
@@ -426,212 +486,299 @@ void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg
table = gUnkLoadStatus;
break;
}
-#endif
+ #endif
- if (arg3 == 0) {
+ if (arg3 == 0)
+ {
tp = &arg0->temporary;
-#ifndef VERSION_SH
- if (arg0 == &gSeqLoadedPool) {
+ #ifndef VERSION_SH
+ if (arg0 == &gSeqLoadedPool)
+ {
table = gSeqLoadStatus;
isSound = FALSE;
- } else if (arg0 == &gBankLoadedPool) {
+ }
+ else if (arg0 == &gBankLoadedPool)
+ {
table = gBankLoadStatus;
isSound = TRUE;
}
-#endif
+ #endif
-#ifdef VERSION_SH
- if (tp->entries[0].id == (s8)nullID) {
+ #ifdef VERSION_SH
+ if (tp->entries[0].id == (s8)nullID)
+ {
firstVal = SOUND_LOAD_STATUS_NOT_LOADED;
- } else {
+ }
+ else
+ {
firstVal = table[tp->entries[0].id];
}
- if (tp->entries[1].id == (s8)nullID) {
+ if (tp->entries[1].id == (s8)nullID)
+ {
secondVal = SOUND_LOAD_STATUS_NOT_LOADED;
- } else {
+ }
+ else
+ {
secondVal = table[tp->entries[1].id];
}
-#else
- firstVal = (tp->entries[0].id == (s8)nullID ? SOUND_LOAD_STATUS_NOT_LOADED : table[tp->entries[0].id]);
- secondVal = (tp->entries[1].id == (s8)nullID ? SOUND_LOAD_STATUS_NOT_LOADED : table[tp->entries[1].id]);
-#endif
+ #else
+ firstVal = tp->entries[0].id == (s8)nullID ? SOUND_LOAD_STATUS_NOT_LOADED : table[tp->entries[0].id];
+ secondVal = tp->entries[1].id == (s8)nullID ? SOUND_LOAD_STATUS_NOT_LOADED : table[tp->entries[1].id];
+ #endif
-#if defined(VERSION_JP) || defined(VERSION_US)
- leftNotLoaded = (firstVal == SOUND_LOAD_STATUS_NOT_LOADED);
- leftDiscardable = (firstVal == SOUND_LOAD_STATUS_DISCARDABLE);
- leftAvail = (firstVal != SOUND_LOAD_STATUS_IN_PROGRESS);
- rightNotLoaded = (secondVal == SOUND_LOAD_STATUS_NOT_LOADED);
- rightDiscardable = (secondVal == SOUND_LOAD_STATUS_DISCARDABLE);
- rightAvail = (secondVal != SOUND_LOAD_STATUS_IN_PROGRESS);
- bothDiscardable = (leftDiscardable && rightDiscardable);
+ #if defined(VERSION_JP) || defined(VERSION_US)
+ leftNotLoaded = firstVal == SOUND_LOAD_STATUS_NOT_LOADED;
+ leftDiscardable = firstVal == SOUND_LOAD_STATUS_DISCARDABLE;
+ leftAvail = firstVal != SOUND_LOAD_STATUS_IN_PROGRESS;
+ rightNotLoaded = secondVal == SOUND_LOAD_STATUS_NOT_LOADED;
+ rightDiscardable = secondVal == SOUND_LOAD_STATUS_DISCARDABLE;
+ rightAvail = secondVal != SOUND_LOAD_STATUS_IN_PROGRESS;
+ bothDiscardable = leftDiscardable && rightDiscardable;
- if (leftNotLoaded) {
+ if (leftNotLoaded)
+ {
tp->nextSide = 0;
- } else if (rightNotLoaded) {
+ }
+ else if (rightNotLoaded)
+ {
tp->nextSide = 1;
- } else if (bothDiscardable) {
+ }
+ else if (bothDiscardable)
+ {
// Use the opposite side from last time.
- } else if (firstVal == SOUND_LOAD_STATUS_DISCARDABLE) { // ??! (I blame copt)
+ }
+ else if (firstVal == SOUND_LOAD_STATUS_DISCARDABLE)
+ { // ??! (I blame copt)
tp->nextSide = 0;
- } else if (rightDiscardable) {
+ }
+ else if (rightDiscardable)
+ {
tp->nextSide = 1;
- } else if (leftAvail) {
+ }
+ else if (leftAvail)
+ {
tp->nextSide = 0;
- } else if (rightAvail) {
+ }
+ else if (rightAvail)
+ {
tp->nextSide = 1;
- } else {
+ }
+ else
+ {
// Both left and right sides are being loaded into.
return NULL;
}
-#else
-#ifdef VERSION_EU
- if (0) {
+ #else
+ #ifdef VERSION_EU
+ if (0)
+ {
// It's unclear where these string literals go.
eu_stubbed_printf_0("DataHeap Not Allocate \n");
eu_stubbed_printf_1("StayHeap Not Allocate %d\n", 0);
eu_stubbed_printf_1("AutoHeap Not Allocate %d\n", 0);
}
-#endif
+ #endif
-#ifdef VERSION_SH
- if (poolIdx == 1) {
- if (firstVal == SOUND_LOAD_STATUS_4) {
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
- if (gNotes[i].bankId == tp->entries[0].id && gNotes[i].noteSubEu.enabled) {
+ #ifdef VERSION_SH
+ if (poolIdx == 1)
+ {
+ if (firstVal == SOUND_LOAD_STATUS_4)
+ {
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
+ if (gNotes[i].bankId == tp->entries[0].id && gNotes[i].noteSubEu.enabled)
+ {
break;
}
}
- if (i == gMaxSimultaneousNotes) {
- if (gBankLoadStatus[tp->entries[0].id] != SOUND_LOAD_STATUS_5) {
+ if (i == gMaxSimultaneousNotes)
+ {
+ if (gBankLoadStatus[tp->entries[0].id] != SOUND_LOAD_STATUS_5)
+ {
gBankLoadStatus[tp->entries[0].id] = SOUND_LOAD_STATUS_DISCARDABLE;
}
firstVal = SOUND_LOAD_STATUS_DISCARDABLE;
}
}
- if (secondVal == SOUND_LOAD_STATUS_4) {
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
- if (gNotes[i].bankId == tp->entries[1].id && gNotes[i].noteSubEu.enabled) {
+ if (secondVal == SOUND_LOAD_STATUS_4)
+ {
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
+ if (gNotes[i].bankId == tp->entries[1].id && gNotes[i].noteSubEu.enabled)
+ {
break;
}
}
- if (i == gMaxSimultaneousNotes) {
- if (gBankLoadStatus[tp->entries[1].id] != SOUND_LOAD_STATUS_5) {
+ if (i == gMaxSimultaneousNotes)
+ {
+ if (gBankLoadStatus[tp->entries[1].id] != SOUND_LOAD_STATUS_5)
+ {
gBankLoadStatus[tp->entries[1].id] = SOUND_LOAD_STATUS_DISCARDABLE;
}
secondVal = SOUND_LOAD_STATUS_DISCARDABLE;
}
}
}
-#endif
+ #endif
- if (firstVal == SOUND_LOAD_STATUS_NOT_LOADED) {
+ if (firstVal == SOUND_LOAD_STATUS_NOT_LOADED)
+ {
tp->nextSide = 0;
- } else if (secondVal == SOUND_LOAD_STATUS_NOT_LOADED) {
+ }
+ else if (secondVal == SOUND_LOAD_STATUS_NOT_LOADED)
+ {
tp->nextSide = 1;
- } else {
+ }
+ else
+ {
eu_stubbed_printf_0("WARNING: NO FREE AUTOSEQ AREA.\n");
- if ((firstVal == SOUND_LOAD_STATUS_DISCARDABLE) && (secondVal == SOUND_LOAD_STATUS_DISCARDABLE)) {
+ if ((firstVal == SOUND_LOAD_STATUS_DISCARDABLE) && (secondVal == SOUND_LOAD_STATUS_DISCARDABLE))
+ {
// Use the opposite side from last time.
- } else if (firstVal == SOUND_LOAD_STATUS_DISCARDABLE) {
+ }
+ else if (firstVal == SOUND_LOAD_STATUS_DISCARDABLE)
+ {
tp->nextSide = 0;
- } else if (secondVal == SOUND_LOAD_STATUS_DISCARDABLE) {
+ }
+ else if (secondVal == SOUND_LOAD_STATUS_DISCARDABLE)
+ {
tp->nextSide = 1;
- } else {
-#ifdef VERSION_EU
+ }
+ else
+ {
+ #ifdef VERSION_EU
eu_stubbed_printf_0("WARNING: NO STOP AUTO AREA.\n");
eu_stubbed_printf_0(" AND TRY FORCE TO STOP SIDE \n");
- if (firstVal != SOUND_LOAD_STATUS_IN_PROGRESS) {
+ if (firstVal != SOUND_LOAD_STATUS_IN_PROGRESS)
+ {
tp->nextSide = 0;
- } else if (secondVal != SOUND_LOAD_STATUS_IN_PROGRESS) {
+ }
+ else if (secondVal != SOUND_LOAD_STATUS_IN_PROGRESS)
+ {
tp->nextSide = 1;
- } else {
+ }
+ else
+ {
// Both left and right sides are being loaded into.
eu_stubbed_printf_0("TWO SIDES ARE LOADING... ALLOC CANCELED.\n");
return NULL;
}
-#else
- if (poolIdx == 0) {
- if (firstVal == SOUND_LOAD_STATUS_COMPLETE) {
- for (i = 0; i < SEQUENCE_PLAYERS; i++) {
- if (gSequencePlayers[i].enabled && gSequencePlayers[i].seqId == tp->entries[0].id) {
+ #else
+ if (poolIdx == 0)
+ {
+ if (firstVal == SOUND_LOAD_STATUS_COMPLETE)
+ {
+ for (i = 0; i < SEQUENCE_PLAYERS; i++)
+ {
+ if (gSequencePlayers[i].enabled && gSequencePlayers[i].seqId == tp->entries[0].id)
+ {
break;
}
}
- if (i == SEQUENCE_PLAYERS) {
+ if (i == SEQUENCE_PLAYERS)
+ {
tp->nextSide = 0;
goto out;
}
}
- if (secondVal == SOUND_LOAD_STATUS_COMPLETE) {
- for (i = 0; i < SEQUENCE_PLAYERS; i++) {
- if (gSequencePlayers[i].enabled && gSequencePlayers[i].seqId == tp->entries[1].id) {
+ if (secondVal == SOUND_LOAD_STATUS_COMPLETE)
+ {
+ for (i = 0; i < SEQUENCE_PLAYERS; i++)
+ {
+ if (gSequencePlayers[i].enabled && gSequencePlayers[i].seqId == tp->entries[1].id)
+ {
break;
}
}
- if (i == SEQUENCE_PLAYERS) {
- tp->nextSide = 1;
- goto out;
- }
- }
- } else if (poolIdx == 1) {
- if (firstVal == SOUND_LOAD_STATUS_COMPLETE) {
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
- if (gNotes[i].bankId == tp->entries[0].id && gNotes[i].noteSubEu.enabled) {
- break;
- }
- }
- if (i == gMaxSimultaneousNotes) {
- tp->nextSide = 0;
- goto out;
- }
- }
- if (secondVal == SOUND_LOAD_STATUS_COMPLETE) {
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
- if (gNotes[i].bankId == tp->entries[1].id && gNotes[i].noteSubEu.enabled) {
- break;
- }
- }
- if (i == gMaxSimultaneousNotes) {
+ if (i == SEQUENCE_PLAYERS)
+ {
tp->nextSide = 1;
goto out;
}
}
}
- if (tp->nextSide == 0) {
- if (firstVal == SOUND_LOAD_STATUS_IN_PROGRESS) {
- if (secondVal != SOUND_LOAD_STATUS_IN_PROGRESS) {
- tp->nextSide = 1;
- goto out;
+ else if (poolIdx == 1)
+ {
+ if (firstVal == SOUND_LOAD_STATUS_COMPLETE)
+ {
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
+ if (gNotes[i].bankId == tp->entries[0].id && gNotes[i].noteSubEu.enabled)
+ {
+ break;
+ }
}
- } else {
- goto out;
- }
- } else {
- if (secondVal == SOUND_LOAD_STATUS_IN_PROGRESS) {
- if (firstVal != SOUND_LOAD_STATUS_IN_PROGRESS) {
+ if (i == gMaxSimultaneousNotes)
+ {
tp->nextSide = 0;
goto out;
}
- } else {
+ }
+ if (secondVal == SOUND_LOAD_STATUS_COMPLETE)
+ {
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
+ if (gNotes[i].bankId == tp->entries[1].id && gNotes[i].noteSubEu.enabled)
+ {
+ break;
+ }
+ }
+ if (i == gMaxSimultaneousNotes)
+ {
+ tp->nextSide = 1;
+ goto out;
+ }
+ }
+ }
+ if (tp->nextSide == 0)
+ {
+ if (firstVal == SOUND_LOAD_STATUS_IN_PROGRESS)
+ {
+ if (secondVal != SOUND_LOAD_STATUS_IN_PROGRESS)
+ {
+ tp->nextSide = 1;
+ goto out;
+ }
+ }
+ else
+ {
+ goto out;
+ }
+ }
+ else
+ {
+ if (secondVal == SOUND_LOAD_STATUS_IN_PROGRESS)
+ {
+ if (firstVal != SOUND_LOAD_STATUS_IN_PROGRESS)
+ {
+ tp->nextSide = 0;
+ goto out;
+ }
+ }
+ else
+ {
goto out;
}
}
return NULL;
- out:;
-#endif
+ out:;
+ #endif
}
}
-#endif
+ #endif
pool = &arg0->temporary.pool;
- if (tp->entries[tp->nextSide].id != (s8)nullID) {
+ if (tp->entries[tp->nextSide].id != (s8)nullID)
+ {
table[tp->entries[tp->nextSide].id] = SOUND_LOAD_STATUS_NOT_LOADED;
- if (isSound == TRUE) {
+ if (isSound == TRUE)
+ {
discard_bank(tp->entries[tp->nextSide].id);
}
}
- switch (tp->nextSide) {
+ switch (tp->nextSide)
+ {
case 0:
tp->entries[0].ptr = pool->start;
tp->entries[0].id = id;
@@ -639,17 +786,19 @@ void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg
pool->cur = pool->start + size;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
if (tp->entries[1].id != (s32)nullID)
-#endif
- if (tp->entries[1].ptr < pool->cur) {
+ #endif
+ if (tp->entries[1].ptr < pool->cur)
+ {
eu_stubbed_printf_0("WARNING: Before Area Overlaid After.");
// Throw out the entry on the other side if it doesn't fit.
// (possible @bug: what if it's currently being loaded?)
table[tp->entries[1].id] = SOUND_LOAD_STATUS_NOT_LOADED;
- switch (isSound) {
+ switch (isSound)
+ {
case FALSE:
discard_sequence(tp->entries[1].id);
break;
@@ -659,36 +808,38 @@ void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg
}
tp->entries[1].id = (s32)nullID;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
tp->entries[1].ptr = pool->start + pool->size;
-#else
+ #else
tp->entries[1].ptr = pool->size + pool->start;
-#endif
+ #endif
}
ret = tp->entries[0].ptr;
break;
case 1:
-#if defined(VERSION_SH)
- tp->entries[1].ptr = (u8 *) ((uintptr_t) (pool->start + pool->size - size) & ~0x0f);
-#elif defined(VERSION_EU)
+ #if defined(VERSION_SH)
+ tp->entries[1].ptr = (u8 *)((uintptr_t)(pool->start + pool->size - size) & ~0x0f);
+ #elif defined(VERSION_EU)
tp->entries[1].ptr = pool->start + pool->size - size - 0x10;
-#else
+ #else
tp->entries[1].ptr = pool->size + pool->start - size - 0x10;
-#endif
+ #endif
tp->entries[1].id = id;
tp->entries[1].size = size;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
if (tp->entries[0].id != (s32)nullID)
-#endif
- if (tp->entries[1].ptr < pool->cur) {
+ #endif
+ if (tp->entries[1].ptr < pool->cur)
+ {
eu_stubbed_printf_0("WARNING: After Area Overlaid Before.");
table[tp->entries[0].id] = SOUND_LOAD_STATUS_NOT_LOADED;
- switch (isSound) {
+ switch (isSound)
+ {
case FALSE:
discard_sequence(tp->entries[0].id);
break;
@@ -716,37 +867,38 @@ void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg
return ret;
}
-#if defined(VERSION_EU) || defined(VERSION_SH)
-#ifdef VERSION_SH
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ #ifdef VERSION_SH
ret = sound_alloc_uninitialized(&arg0->persistent.pool, size);
-#else
+ #else
ret = soundAlloc(&arg0->persistent.pool, arg1 * size);
-#endif
+ #endif
arg0->persistent.entries[arg0->persistent.numEntries].ptr = ret;
if (ret == NULL)
-#else
+ #else
arg0->persistent.entries[arg0->persistent.numEntries].ptr = soundAlloc(&arg0->persistent.pool, arg1 * size);
if (arg0->persistent.entries[arg0->persistent.numEntries].ptr == NULL)
-#endif
+ #endif
{
- switch (arg3) {
+ switch (arg3)
+ {
case 2:
-#if defined(VERSION_EU)
+ #if defined(VERSION_EU)
eu_stubbed_printf_0("MEMORY:StayHeap OVERFLOW.");
return alloc_bank_or_seq(arg0, arg1, size, 0, id);
-#elif defined(VERSION_SH)
+ #elif defined(VERSION_SH)
return alloc_bank_or_seq(poolIdx, size, 0, id);
-#else
+ #else
// Prevent tail call optimization.
ret = alloc_bank_or_seq(arg0, arg1, size, 0, id);
return ret;
-#endif
+ #endif
case 1:
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
case 0:
-#endif
+ #endif
eu_stubbed_printf_1("MEMORY:StayHeap OVERFLOW (REQ:%d)", arg1 * size);
return NULL;
}
@@ -756,36 +908,42 @@ void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg
// Because the buffer is small enough that more don't fit?
arg0->persistent.entries[arg0->persistent.numEntries].id = id;
arg0->persistent.entries[arg0->persistent.numEntries].size = size;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
return arg0->persistent.entries[arg0->persistent.numEntries++].ptr;
-#else
- arg0->persistent.numEntries++; return arg0->persistent.entries[arg0->persistent.numEntries - 1].ptr;
-#endif
-#ifdef VERSION_SH
-#undef isSound
-#endif
+ #else
+ arg0->persistent.numEntries++;
+ return arg0->persistent.entries[arg0->persistent.numEntries - 1].ptr;
+ #endif
+ #ifdef VERSION_SH
+ #undef isSound
+ #endif
}
#ifdef VERSION_SH
-void *get_bank_or_seq(s32 poolIdx, s32 arg1, s32 id) {
+void *get_bank_or_seq(s32 poolIdx, s32 arg1, s32 id)
+{
void *ret;
ret = unk_pool1_lookup(poolIdx, id);
- if (ret != NULL) {
+ if (ret != NULL)
+ {
return ret;
}
- if (arg1 == 3) {
+ if (arg1 == 3)
+ {
return NULL;
}
return get_bank_or_seq_inner(poolIdx, arg1, id);
}
-void *get_bank_or_seq_inner(s32 poolIdx, s32 arg1, s32 bankId) {
+void *get_bank_or_seq_inner(s32 poolIdx, s32 arg1, s32 bankId)
+{
u32 i;
- struct SoundMultiPool* loadedPool;
- struct TemporaryPool* temporary;
- struct PersistentPool* persistent;
+ struct SoundMultiPool *loadedPool;
+ struct TemporaryPool *temporary;
+ struct PersistentPool *persistent;
- switch (poolIdx) {
+ switch (poolIdx)
+ {
case 0:
loadedPool = &gSeqLoadedPool;
break;
@@ -798,66 +956,86 @@ void *get_bank_or_seq_inner(s32 poolIdx, s32 arg1, s32 bankId) {
}
temporary = &loadedPool->temporary;
- if (arg1 == 0) {
- if (temporary->entries[0].id == bankId) {
+ if (arg1 == 0)
+ {
+ if (temporary->entries[0].id == bankId)
+ {
temporary->nextSide = 1;
return temporary->entries[0].ptr;
- } else if (temporary->entries[1].id == bankId) {
+ }
+ else if (temporary->entries[1].id == bankId)
+ {
temporary->nextSide = 0;
return temporary->entries[1].ptr;
- } else {
+ }
+ else
+ {
return NULL;
}
}
persistent = &loadedPool->persistent;
- for (i = 0; i < persistent->numEntries; i++) {
- if (persistent->entries[i].id == bankId) {
+ for (i = 0; i < persistent->numEntries; i++)
+ {
+ if (persistent->entries[i].id == bankId)
+ {
return persistent->entries[i].ptr;
}
}
- if (arg1 == 2) {
+ if (arg1 == 2)
+ {
return get_bank_or_seq(poolIdx, 0, bankId);
}
return NULL;
}
#endif
#ifndef VERSION_SH
-void *get_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 id) {
+void *get_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 id)
+{
u32 i;
- UNUSED void *ret;
+ UNUSED
+ void *ret;
struct TemporaryPool *temporary = &arg0->temporary;
- if (arg1 == 0) {
+ if (arg1 == 0)
+ {
// Try not to overwrite sound that we have just accessed, by setting nextSide appropriately.
- if (temporary->entries[0].id == id) {
+ if (temporary->entries[0].id == id)
+ {
temporary->nextSide = 1;
return temporary->entries[0].ptr;
- } else if (temporary->entries[1].id == id) {
+ }
+ else if (temporary->entries[1].id == id)
+ {
temporary->nextSide = 0;
return temporary->entries[1].ptr;
}
eu_stubbed_printf_1("Auto Heap Unhit for ID %d\n", id);
return NULL;
- } else {
+ }
+ else
+ {
struct PersistentPool *persistent = &arg0->persistent;
- for (i = 0; i < persistent->numEntries; i++) {
- if (id == persistent->entries[i].id) {
+ for (i = 0; i < persistent->numEntries; i++)
+ {
+ if (id == persistent->entries[i].id)
+ {
eu_stubbed_printf_2("Cache hit %d at stay %d\n", id, i);
return persistent->entries[i].ptr;
}
}
- if (arg1 == 2) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ if (arg1 == 2)
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
return get_bank_or_seq(arg0, 0, id);
-#else
+ #else
// Prevent tail call optimization by using a temporary.
// Either copt or -Wo,-notail.
ret = get_bank_or_seq(arg0, 0, id);
return ret;
-#endif
+ #endif
}
return NULL;
}
@@ -865,107 +1043,128 @@ void *get_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 id) {
#endif
#if defined(VERSION_EU) || defined(VERSION_SH)
-void func_eu_802e27e4_unused(f32 arg0, f32 arg1, u16 *arg2) {
+void func_eu_802e27e4_unused(f32 arg0, f32 arg1, u16 *arg2)
+{
s32 i;
f32 tmp[16];
- tmp[0] = (f32) (arg1 * 262159.0f);
- tmp[8] = (f32) (arg0 * 262159.0f);
- tmp[1] = (f32) ((arg1 * arg0) * 262159.0f);
- tmp[9] = (f32) (((arg0 * arg0) + arg1) * 262159.0f);
+ tmp[0] = (f32)(arg1 * 262159.0f);
+ tmp[8] = (f32)(arg0 * 262159.0f);
+ tmp[1] = (f32)((arg1 * arg0) * 262159.0f);
+ tmp[9] = (f32)(((arg0 * arg0) + arg1) * 262159.0f);
- for (i = 2; i < 8; i++) {
+ for (i = 2; i < 8; i++)
+ {
//! @bug they probably meant to store the value to tmp[i] and tmp[8 + i]
arg2[i] = arg1 * tmp[i - 2] + arg0 * tmp[i - 1];
arg2[8 + i] = arg1 * tmp[6 + i] + arg0 * tmp[7 + i];
}
- for (i = 0; i < 16; i++) {
+ for (i = 0; i < 16; i++)
+ {
arg2[i] = tmp[i];
}
#ifdef VERSION_EU
- for (i = 0; i < 8; i++) {
+for (i =0; i<8; i++) {
eu_stubbed_printf_1("%d ", arg2[i]);
}
- eu_stubbed_printf_0("\n");
+eu_stubbed_printf_0 ("\n");
- for (i = 8; i < 16; i++) {
+ for (i =8; i<16; i++) {
eu_stubbed_printf_1("%d ", arg2[i]);
}
- eu_stubbed_printf_0("\n");
+eu_stubbed_printf_0 ("\n");
#endif
}
#endif
#ifdef VERSION_SH
-void fill_zero_filter(s16 filter[]) {
+void fill_zero_filter(s16 filter[])
+{
s32 i;
- for (i = 0; i < 8; i++) {
+ for (i = 0; i < 8; i++)
+ {
filter[i] = 0;
}
}
extern s16 unk_sh_data_3[15 * 8];
extern s16 unk_sh_data_4[15 * 8];
-void func_sh_802F0DE8(s16 filter[8], s32 arg1) {
+void func_sh_802F0DE8(s16 filter[8], s32 arg1)
+{
s32 i;
s16 *ptr = &unk_sh_data_3[8 * (arg1 - 1)];
- for (i = 0; i < 8; i++) {
+ for (i = 0; i < 8; i++)
+ {
filter[i] = ptr[i];
}
}
-void func_sh_802F0E40(s16 filter[8], s32 arg1) { // Unused
+void func_sh_802F0E40(s16 filter[8], s32 arg1)
+{ // Unused
s32 i;
s16 *ptr = &unk_sh_data_4[8 * (arg1 - 1)];
- for (i = 0; i < 8; i++) {
+ for (i = 0; i < 8; i++)
+ {
filter[i] = ptr[i];
}
}
-void fill_filter(s16 filter[8], s32 arg1, s32 arg2) {
+void fill_filter(s16 filter[8], s32 arg1, s32 arg2)
+{
s32 i;
s16 *ptr;
- if (arg1 != 0) {
+ if (arg1 != 0)
+ {
func_sh_802F0DE8(filter, arg1);
- } else {
+ }
+ else
+ {
fill_zero_filter(filter);
}
- if (arg2 != 0) {
+ if (arg2 != 0)
+ {
ptr = &unk_sh_data_4[8 * (arg2 - 1)];
- for (i = 0; i < 8; i++) {
+ for (i = 0; i < 8; i++)
+ {
filter[i] += ptr[i];
}
}
}
#endif
-void decrease_reverb_gain(void) {
-#if defined(VERSION_EU)
+void decrease_reverb_gain(void)
+{
+ #if defined(VERSION_EU)
s32 i;
- for (i = 0; i < gNumSynthesisReverbs; i++) {
+ for (i = 0; i < gNumSynthesisReverbs; i++)
+ {
gSynthesisReverbs[i].reverbGain -= gSynthesisReverbs[i].reverbGain / 8;
}
-#elif defined(VERSION_JP) || defined(VERSION_US)
+ #elif defined(VERSION_JP) || defined(VERSION_US)
gSynthesisReverb.reverbGain -= gSynthesisReverb.reverbGain / 4;
-#else
+ #else
s32 i, j;
s32 v0 = gAudioBufferParameters.presetUnk4 == 2 ? 2 : 1;
- for (i = 0; i < gNumSynthesisReverbs; i++) {
- for (j = 0; j < v0; j++) {
+ for (i = 0; i < gNumSynthesisReverbs; i++)
+ {
+ for (j = 0; j < v0; j++)
+ {
gSynthesisReverbs[i].reverbGain -= gSynthesisReverbs[i].reverbGain / 3;
}
}
-#endif
+ #endif
}
#if defined(VERSION_SH)
-void clear_curr_ai_buffer(void) {
+void clear_curr_ai_buffer(void)
+{
s32 currIndex = gCurrAiBufferIndex;
s32 i;
gAiBufferLengths[currIndex] = gAudioBufferParameters.minAiBufferLength;
- for (i = 0; i < (s32) (AIBUFFER_LEN / sizeof(s16)); i++) {
+ for (i = 0; i < (s32)(AIBUFFER_LEN / sizeof(s16)); i++)
+ {
gAiBuffers[currIndex][i] = 0;
}
}
@@ -973,27 +1172,30 @@ void clear_curr_ai_buffer(void) {
#if defined(VERSION_EU) || defined(VERSION_SH)
-s32 audio_shut_down_and_reset_step(void) {
+s32 audio_shut_down_and_reset_step(void)
+{
s32 i;
s32 j;
#ifdef VERSION_SH
- s32 num = gAudioBufferParameters.presetUnk4 == 2 ? 2 : 1;
+s32 num = gAudioBufferParameters.presetUnk4 == 2 ? 2 : 1;
#endif
- switch (gAudioResetStatus) {
- case 5:
- for (i = 0; i < SEQUENCE_PLAYERS; i++) {
- sequence_player_disable(&gSequencePlayers[i]);
- }
+switch (gAudioResetStatus)
+{
+case 5:
+ for (i = 0; i < SEQUENCE_PLAYERS; i++)
+ {
+ sequence_player_disable(&gSequencePlayers[i]);
+ }
#ifdef VERSION_SH
- gAudioResetFadeOutFramesLeft = 4 / num;
+gAudioResetFadeOutFramesLeft=4 / num;
#else
- gAudioResetFadeOutFramesLeft = 4;
+gAudioResetFadeOutFramesLeft=4;
#endif
- gAudioResetStatus--;
+gAudioResetStatus--;
break;
case 4:
- if (gAudioResetFadeOutFramesLeft != 0) {
+ if (gAudioResetFadeOutFramesLeft!= 0) {
gAudioResetFadeOutFramesLeft--;
decrease_reverb_gain();
} else {
@@ -1004,21 +1206,21 @@ s32 audio_shut_down_and_reset_step(void) {
}
}
#ifdef VERSION_SH
- gAudioResetFadeOutFramesLeft = 16 / num;
+gAudioResetFadeOutFramesLeft=16 / num;
#else
- gAudioResetFadeOutFramesLeft = 16;
+gAudioResetFadeOutFramesLeft=16;
#endif
- gAudioResetStatus--;
+gAudioResetStatus--;
}
break;
case 3:
- if (gAudioResetFadeOutFramesLeft != 0) {
+ if (gAudioResetFadeOutFramesLeft!= 0) {
gAudioResetFadeOutFramesLeft--;
#ifdef VERSION_SH
- if (1) {
+if (1) {
}
#endif
- decrease_reverb_gain();
+decrease_reverb_gain();
} else {
for (i = 0; i < NUMAIBUFFERS; i++) {
for (j = 0; j < (s32) (AIBUFFER_LEN / sizeof(s16)); j++) {
@@ -1026,94 +1228,104 @@ s32 audio_shut_down_and_reset_step(void) {
}
}
#ifdef VERSION_SH
- gAudioResetFadeOutFramesLeft = 4 / num;
+gAudioResetFadeOutFramesLeft=4 / num;
#else
- gAudioResetFadeOutFramesLeft = 4;
+gAudioResetFadeOutFramesLeft=4;
#endif
- gAudioResetStatus--;
+gAudioResetStatus--;
}
break;
case 2:
#ifdef VERSION_SH
- clear_curr_ai_buffer();
+clear_curr_ai_buffer();
#endif
- if (gAudioResetFadeOutFramesLeft != 0) {
+if (gAudioResetFadeOutFramesLeft!= 0) {
gAudioResetFadeOutFramesLeft--;
} else {
gAudioResetStatus--;
#ifdef VERSION_SH
- func_sh_802f23ec();
+func_sh_802f23ec();
#endif
- }
+}
break;
case 1:
- audio_reset_session();
- gAudioResetStatus = 0;
+audio_reset_session();
+gAudioResetStatus=0;
#ifdef VERSION_SH
- for (i = 0; i < NUMAIBUFFERS; i++) {
+for (i =0; i 4 * 60) {
+ if (frames > 4 * 60)
+ {
// Break after 4 seconds
break;
}
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
if (gNotes[i].enabled)
break;
}
- if (i == gMaxSimultaneousNotes) {
+ if (i == gMaxSimultaneousNotes)
+ {
// All zero, break early
break;
}
@@ -1151,49 +1367,53 @@ void audio_reset_session(void) {
wait_for_audio_frames(3);
remainingDmas = gCurrAudioFrameDmaCount;
- while (remainingDmas > 0) {
- for (i = 0; i < gCurrAudioFrameDmaCount; i++) {
+ while (remainingDmas > 0)
+ {
+ for (i = 0; i < gCurrAudioFrameDmaCount; i++)
+ {
if (osRecvMesg(&gCurrAudioFrameDmaQueue, NULL, OS_MESG_NOBLOCK) == 0)
remainingDmas--;
}
}
gCurrAudioFrameDmaCount = 0;
- for (j = 0; j < NUMAIBUFFERS; j++) {
- for (k = 0; k < (s32) (AIBUFFER_LEN / sizeof(s16)); k++) {
+ for (j = 0; j < NUMAIBUFFERS; j++)
+ {
+ for (k = 0; k < (s32)(AIBUFFER_LEN / sizeof(s16)); k++)
+ {
gAiBuffers[j][k] = 0;
}
}
}
-#endif
+ #endif
gSampleDmaNumListItems = 0;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
gAudioBufferParameters.frequency = preset->frequency;
gAudioBufferParameters.aiFrequency = osAiSetFrequency(gAudioBufferParameters.frequency);
gAudioBufferParameters.samplesPerFrameTarget = ALIGN16(gAudioBufferParameters.frequency / gRefreshRate);
gAudioBufferParameters.minAiBufferLength = gAudioBufferParameters.samplesPerFrameTarget - 0x10;
gAudioBufferParameters.maxAiBufferLength = gAudioBufferParameters.samplesPerFrameTarget + 0x10;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
gAudioBufferParameters.updatesPerFrame = (gAudioBufferParameters.samplesPerFrameTarget + 0x10) / 192 + 1;
gAudioBufferParameters.samplesPerUpdate = (gAudioBufferParameters.samplesPerFrameTarget / gAudioBufferParameters.updatesPerFrame) & -8;
-#else
+ #else
gAudioBufferParameters.updatesPerFrame = (gAudioBufferParameters.samplesPerFrameTarget + 0x10) / 160 + 1;
gAudioBufferParameters.samplesPerUpdate = (gAudioBufferParameters.samplesPerFrameTarget / gAudioBufferParameters.updatesPerFrame) & 0xfff8;
-#endif
+ #endif
gAudioBufferParameters.samplesPerUpdateMax = gAudioBufferParameters.samplesPerUpdate + 8;
gAudioBufferParameters.samplesPerUpdateMin = gAudioBufferParameters.samplesPerUpdate - 8;
gAudioBufferParameters.resampleRate = 32000.0f / FLOAT_CAST(gAudioBufferParameters.frequency);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
gAudioBufferParameters.unkUpdatesPerFrameScaled = (1.0f / 256.0f) / gAudioBufferParameters.updatesPerFrame;
-#else
+ #else
gAudioBufferParameters.unkUpdatesPerFrameScaled = (3.0f / 1280.0f) / gAudioBufferParameters.updatesPerFrame;
-#endif
+ #endif
gAudioBufferParameters.updatesPerFrameInv = 1.0f / gAudioBufferParameters.updatesPerFrame;
gMaxSimultaneousNotes = preset->maxSimultaneousNotes;
gVolume = preset->volume;
- gTempoInternalToExternal = (u32) (gAudioBufferParameters.updatesPerFrame * 2880000.0f / gTatumsPerBeat / D_EU_802298D0);
+ gTempoInternalToExternal = (u32)(gAudioBufferParameters.updatesPerFrame * 2880000.0f / gTatumsPerBeat / D_EU_802298D0);
gAudioBufferParameters.presetUnk4 = preset->unk1;
gAudioBufferParameters.samplesPerFrameTarget *= gAudioBufferParameters.presetUnk4;
@@ -1201,22 +1421,24 @@ void audio_reset_session(void) {
gAudioBufferParameters.minAiBufferLength *= gAudioBufferParameters.presetUnk4;
gAudioBufferParameters.updatesPerFrame *= gAudioBufferParameters.presetUnk4;
-#ifdef VERSION_SH
- if (gAudioBufferParameters.presetUnk4 >= 2) {
+ #ifdef VERSION_SH
+ if (gAudioBufferParameters.presetUnk4 >= 2)
+ {
gAudioBufferParameters.maxAiBufferLength -= 0x10;
}
gMaxAudioCmds = gMaxSimultaneousNotes * 0x14 * gAudioBufferParameters.updatesPerFrame + preset->numReverbs * 0x20 + 0x1E0;
-#else
+ #else
gMaxAudioCmds = gMaxSimultaneousNotes * 0x10 * gAudioBufferParameters.updatesPerFrame + preset->numReverbs * 0x20 + 0x300;
-#endif
-#else
+ #endif
+ #else
reverbWindowSize = preset->reverbWindowSize;
gAiFrequency = osAiSetFrequency(preset->frequency);
gMaxSimultaneousNotes = preset->maxSimultaneousNotes;
gSamplesPerFrameTarget = ALIGN16(gAiFrequency / 60);
gReverbDownsampleRate = preset->reverbDownsampleRate;
- switch (gReverbDownsampleRate) {
+ switch (gReverbDownsampleRate)
+ {
case 1:
sReverbDownsampleRateLog = 0;
break;
@@ -1245,24 +1467,24 @@ void audio_reset_session(void) {
// Compute conversion ratio from the internal unit tatums/tick to the
// external beats/minute (JP) or tatums/minute (US). In practice this is
// 300 on JP and 14360 on US.
-#ifdef VERSION_JP
+ #ifdef VERSION_JP
gTempoInternalToExternal = updatesPerFrame * 3600 / gTatumsPerBeat;
-#else
+ #else
gTempoInternalToExternal = (u32)(updatesPerFrame * 2880000.0f / gTatumsPerBeat / 16.713f);
-#endif
+ #endif
gMaxAudioCmds = gMaxSimultaneousNotes * 20 * updatesPerFrame + 320;
-#endif
+ #endif
-#if defined(VERSION_SH)
+ #if defined(VERSION_SH)
persistentMem = DOUBLE_SIZE_ON_64_BIT(preset->persistentSeqMem + preset->persistentBankMem + preset->unk18 + preset->unkMem28 + 0x10);
temporaryMem = DOUBLE_SIZE_ON_64_BIT(preset->temporarySeqMem + preset->temporaryBankMem + preset->unk24 + preset->unkMem2C + 0x10);
-#elif defined(VERSION_EU)
+ #elif defined(VERSION_EU)
persistentMem = DOUBLE_SIZE_ON_64_BIT(preset->persistentSeqMem + preset->persistentBankMem);
temporaryMem = DOUBLE_SIZE_ON_64_BIT(preset->temporarySeqMem + preset->temporaryBankMem);
-#else
+ #else
persistentMem = DOUBLE_SIZE_ON_64_BIT(preset->persistentBankMem + preset->persistentSeqMem);
temporaryMem = DOUBLE_SIZE_ON_64_BIT(preset->temporaryBankMem + preset->temporarySeqMem);
-#endif
+ #endif
totalMem = persistentMem + temporaryMem;
wantMisc = gAudioSessionPool.size - totalMem - 0x100;
sSessionPoolSplit.wantSeq = wantMisc;
@@ -1273,115 +1495,129 @@ void audio_reset_session(void) {
seq_and_bank_pool_init(&sSeqAndBankPoolSplit);
sPersistentCommonPoolSplit.wantSeq = DOUBLE_SIZE_ON_64_BIT(preset->persistentSeqMem);
sPersistentCommonPoolSplit.wantBank = DOUBLE_SIZE_ON_64_BIT(preset->persistentBankMem);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
sPersistentCommonPoolSplit.wantUnused = preset->unk18;
-#else
+ #else
sPersistentCommonPoolSplit.wantUnused = 0;
-#endif
+ #endif
persistent_pools_init(&sPersistentCommonPoolSplit);
sTemporaryCommonPoolSplit.wantSeq = DOUBLE_SIZE_ON_64_BIT(preset->temporarySeqMem);
sTemporaryCommonPoolSplit.wantBank = DOUBLE_SIZE_ON_64_BIT(preset->temporaryBankMem);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
sTemporaryCommonPoolSplit.wantUnused = preset->unk24;
-#else
+ #else
sTemporaryCommonPoolSplit.wantUnused = 0;
-#endif
+ #endif
temporary_pools_init(&sTemporaryCommonPoolSplit);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
unk_pools_init(preset->unkMem28, preset->unkMem2C);
-#endif
+ #endif
reset_bank_and_seq_load_status();
-#if defined(VERSION_JP) || defined(VERSION_US)
- for (j = 0; j < 2; j++) {
+ #if defined(VERSION_JP) || defined(VERSION_US)
+ for (j = 0; j < 2; j++)
+ {
gAudioCmdBuffers[j] = soundAlloc(&gNotesAndBuffersPool, gMaxAudioCmds * sizeof(u64));
}
-#endif
+ #endif
gNotes = soundAlloc(&gNotesAndBuffersPool, gMaxSimultaneousNotes * sizeof(struct Note));
note_init_all();
init_note_free_list();
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
gNoteSubsEu = soundAlloc(&gNotesAndBuffersPool, (gAudioBufferParameters.updatesPerFrame * gMaxSimultaneousNotes) * sizeof(struct NoteSubEu));
- for (j = 0; j != 2; j++) {
+ for (j = 0; j != 2; j++)
+ {
gAudioCmdBuffers[j] = soundAlloc(&gNotesAndBuffersPool, gMaxAudioCmds * sizeof(u64));
}
- for (j = 0; j < 4; j++) {
+ for (j = 0; j < 4; j++)
+ {
gSynthesisReverbs[j].useReverb = 0;
}
gNumSynthesisReverbs = preset->numReverbs;
- for (j = 0; j < gNumSynthesisReverbs; j++) {
+ for (j = 0; j < gNumSynthesisReverbs; j++)
+ {
reverb = &gSynthesisReverbs[j];
reverbSettings = &preset->reverbSettings[j];
-#ifdef VERSION_SH
- reverb->downsampleRate = reverbSettings->downsampleRate;
- reverb->windowSize = reverbSettings->windowSize * 64;
- reverb->windowSize /= reverb->downsampleRate;
-#else
- reverb->windowSize = reverbSettings->windowSize * 64;
- reverb->downsampleRate = reverbSettings->downsampleRate;
-#endif
- reverb->reverbGain = reverbSettings->gain;
-#ifdef VERSION_SH
- reverb->panRight = reverbSettings->unk4;
- reverb->panLeft = reverbSettings->unk6;
- reverb->unk5 = reverbSettings->unk8;
- reverb->unk08 = reverbSettings->unkA;
-#endif
- reverb->useReverb = 8;
- reverb->ringBuffer.left = soundAlloc(&gNotesAndBuffersPool, reverb->windowSize * 2);
- reverb->ringBuffer.right = soundAlloc(&gNotesAndBuffersPool, reverb->windowSize * 2);
- reverb->nextRingBufferPos = 0;
- reverb->unkC = 0;
- reverb->curFrame = 0;
- reverb->bufSizePerChannel = reverb->windowSize;
- reverb->framesLeftToIgnore = 2;
-#ifdef VERSION_SH
- reverb->resampleFlags = A_INIT;
-#endif
- if (reverb->downsampleRate != 1) {
-#ifndef VERSION_SH
- reverb->resampleFlags = A_INIT;
-#endif
- reverb->resampleRate = 0x8000 / reverb->downsampleRate;
- reverb->resampleStateLeft = soundAlloc(&gNotesAndBuffersPool, 16 * sizeof(s16));
- reverb->resampleStateRight = soundAlloc(&gNotesAndBuffersPool, 16 * sizeof(s16));
- reverb->unk24 = soundAlloc(&gNotesAndBuffersPool, 16 * sizeof(s16));
- reverb->unk28 = soundAlloc(&gNotesAndBuffersPool, 16 * sizeof(s16));
- for (i = 0; i < gAudioBufferParameters.updatesPerFrame; i++) {
- mem = soundAlloc(&gNotesAndBuffersPool, DEFAULT_LEN_2CH);
- reverb->items[0][i].toDownsampleLeft = mem;
- reverb->items[0][i].toDownsampleRight = mem + DEFAULT_LEN_1CH / sizeof(s16);
- mem = soundAlloc(&gNotesAndBuffersPool, DEFAULT_LEN_2CH);
- reverb->items[1][i].toDownsampleLeft = mem;
- reverb->items[1][i].toDownsampleRight = mem + DEFAULT_LEN_1CH / sizeof(s16);
- }
+ #ifdef VERSION_SH
+ reverb->downsampleRate = reverbSettings->downsampleRate;
+ reverb->windowSize = reverbSettings->windowSize * 64;
+ reverb->windowSize /= reverb->downsampleRate;
+ #else
+ reverb->windowSize = reverbSettings->windowSize * 64;
+ reverb->downsampleRate = reverbSettings->downsampleRate;
+ #endif
+ reverb->reverbGain = reverbSettings->gain;
+ #ifdef VERSION_SH
+ reverb->panRight = reverbSettings->unk4;
+ reverb->panLeft = reverbSettings->unk6;
+ reverb->unk5 = reverbSettings->unk8;
+ reverb->unk08 = reverbSettings->unkA;
+ #endif
+ reverb->useReverb = 8;
+ reverb->ringBuffer.left = soundAlloc(&gNotesAndBuffersPool, reverb->windowSize * 2);
+ reverb->ringBuffer.right = soundAlloc(&gNotesAndBuffersPool, reverb->windowSize * 2);
+ reverb->nextRingBufferPos = 0;
+ reverb->unkC = 0;
+ reverb->curFrame = 0;
+ reverb->bufSizePerChannel = reverb->windowSize;
+ reverb->framesLeftToIgnore = 2;
+ #ifdef VERSION_SH
+ reverb->resampleFlags = A_INIT;
+ #endif
+ if (reverb->downsampleRate != 1) {
+ #ifndef VERSION_SH
+ reverb->resampleFlags = A_INIT;
+ #endif
+ reverb->resampleRate = 0x8000 / reverb->downsampleRate;
+ reverb->resampleStateLeft = soundAlloc(&gNotesAndBuffersPool, 16 * sizeof(s16));
+ reverb->resampleStateRight = soundAlloc(&gNotesAndBuffersPool, 16 * sizeof(s16));
+ reverb->unk24 = soundAlloc(&gNotesAndBuffersPool, 16 * sizeof(s16));
+ reverb->unk28 = soundAlloc(&gNotesAndBuffersPool, 16 * sizeof(s16));
+ for (i = 0; i < gAudioBufferParameters.updatesPerFrame; i++)
+ {
+ mem = soundAlloc(&gNotesAndBuffersPool, DEFAULT_LEN_2CH);
+ reverb->items[0][i].toDownsampleLeft = mem;
+ reverb->items[0][i].toDownsampleRight = mem + DEFAULT_LEN_1CH / sizeof(s16);
+ mem = soundAlloc(&gNotesAndBuffersPool, DEFAULT_LEN_2CH);
+ reverb->items[1][i].toDownsampleLeft = mem;
+ reverb->items[1][i].toDownsampleRight = mem + DEFAULT_LEN_1CH / sizeof(s16);
+ }
}
-#ifdef VERSION_SH
- if (reverbSettings->unkC != 0) {
- reverb->unk108 = sound_alloc_uninitialized(&gNotesAndBuffersPool, 16 * sizeof(s16));
- reverb->unk100 = sound_alloc_uninitialized(&gNotesAndBuffersPool, 8 * sizeof(s16));
- func_sh_802F0DE8(reverb->unk100, reverbSettings->unkC);
- } else {
- reverb->unk100 = NULL;
- }
- if (reverbSettings->unkE != 0) {
- reverb->unk10C = sound_alloc_uninitialized(&gNotesAndBuffersPool, 16 * sizeof(s16));
- reverb->unk104 = sound_alloc_uninitialized(&gNotesAndBuffersPool, 8 * sizeof(s16));
- func_sh_802F0DE8(reverb->unk104, reverbSettings->unkE);
- } else {
- reverb->unk104 = NULL;
- }
-#endif
+ #ifdef VERSION_SH
+ if (reverbSettings->unkC != 0)
+ {
+ reverb->unk108 = sound_alloc_uninitialized(&gNotesAndBuffersPool, 16 * sizeof(s16));
+ reverb->unk100 = sound_alloc_uninitialized(&gNotesAndBuffersPool, 8 * sizeof(s16));
+ func_sh_802F0DE8(reverb->unk100, reverbSettings->unkC);
+ }
+ else
+ {
+ reverb->unk100 = NULL;
+ }
+ if (reverbSettings->unkE != 0)
+ {
+ reverb->unk10C = sound_alloc_uninitialized(&gNotesAndBuffersPool, 16 * sizeof(s16));
+ reverb->unk104 = sound_alloc_uninitialized(&gNotesAndBuffersPool, 8 * sizeof(s16));
+ func_sh_802F0DE8(reverb->unk104, reverbSettings->unkE);
+ }
+ else
+ {
+ reverb->unk104 = NULL;
+ }
+ #endif
}
-#else
- if (reverbWindowSize == 0) {
+ #else
+ if (reverbWindowSize == 0)
+ {
gSynthesisReverb.useReverb = 0;
- } else {
+ }
+ else
+ {
gSynthesisReverb.useReverb = 8;
gSynthesisReverb.ringBuffer.left = soundAlloc(&gNotesAndBuffersPool, reverbWindowSize * 2);
gSynthesisReverb.ringBuffer.right = soundAlloc(&gNotesAndBuffersPool, reverbWindowSize * 2);
@@ -1391,14 +1627,16 @@ void audio_reset_session(void) {
gSynthesisReverb.bufSizePerChannel = reverbWindowSize;
gSynthesisReverb.reverbGain = preset->reverbGain;
gSynthesisReverb.framesLeftToIgnore = 2;
- if (gReverbDownsampleRate != 1) {
+ if (gReverbDownsampleRate != 1)
+ {
gSynthesisReverb.resampleFlags = A_INIT;
gSynthesisReverb.resampleRate = 0x8000 / gReverbDownsampleRate;
gSynthesisReverb.resampleStateLeft = soundAlloc(&gNotesAndBuffersPool, 16 * sizeof(s16));
gSynthesisReverb.resampleStateRight = soundAlloc(&gNotesAndBuffersPool, 16 * sizeof(s16));
gSynthesisReverb.unk24 = soundAlloc(&gNotesAndBuffersPool, 16 * sizeof(s16));
gSynthesisReverb.unk28 = soundAlloc(&gNotesAndBuffersPool, 16 * sizeof(s16));
- for (i = 0; i < gAudioUpdatesPerFrame; i++) {
+ for (i = 0; i < gAudioUpdatesPerFrame; i++)
+ {
mem = soundAlloc(&gNotesAndBuffersPool, DEFAULT_LEN_2CH);
gSynthesisReverb.items[0][i].toDownsampleLeft = mem;
gSynthesisReverb.items[0][i].toDownsampleRight = mem + DEFAULT_LEN_1CH / sizeof(s16);
@@ -1408,48 +1646,54 @@ void audio_reset_session(void) {
}
}
}
-#endif
+ #endif
init_sample_dma_buffers(gMaxSimultaneousNotes);
-#if defined(VERSION_EU)
+ #if defined(VERSION_EU)
build_vol_rampings_table(0, gAudioBufferParameters.samplesPerUpdate);
-#endif
+ #endif
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
D_SH_8034F68C = 0;
D_SH_803479B4 = 4096;
-#endif
+ #endif
osWritebackDCacheAll();
-#if defined(VERSION_JP) || defined(VERSION_US)
- if (gAudioLoadLock != AUDIO_LOCK_UNINITIALIZED) {
+ #if defined(VERSION_JP) || defined(VERSION_US)
+ if (gAudioLoadLock != AUDIO_LOCK_UNINITIALIZED)
+ {
gAudioLoadLock = AUDIO_LOCK_NOT_LOADING;
}
-#endif
+ #endif
}
#ifdef VERSION_SH
-void *unk_pool1_lookup(s32 poolIdx, s32 id) {
+void *unk_pool1_lookup(s32 poolIdx, s32 id)
+{
s32 i;
- for (i = 0; i < gUnkPool1.pool.numAllocatedEntries; i++) {
- if (gUnkPool1.entries[i].poolIndex == poolIdx && gUnkPool1.entries[i].id == id) {
+ for (i = 0; i < gUnkPool1.pool.numAllocatedEntries; i++)
+ {
+ if (gUnkPool1.entries[i].poolIndex == poolIdx && gUnkPool1.entries[i].id == id)
+ {
return gUnkPool1.entries[i].ptr;
}
}
return NULL;
}
-void *unk_pool1_alloc(s32 poolIndex, s32 arg1, u32 size) {
+void *unk_pool1_alloc(s32 poolIndex, s32 arg1, u32 size)
+{
void *ret;
s32 pos;
pos = gUnkPool1.pool.numAllocatedEntries;
ret = sound_alloc_uninitialized(&gUnkPool1.pool, size);
gUnkPool1.entries[pos].ptr = ret;
- if (ret == NULL) {
+ if (ret == NULL)
+ {
return NULL;
}
gUnkPool1.entries[pos].poolIndex = poolIndex;
@@ -1457,17 +1701,19 @@ void *unk_pool1_alloc(s32 poolIndex, s32 arg1, u32 size) {
gUnkPool1.entries[pos].size = size;
#ifdef AVOID_UB
- //! @bug UB: missing return. "ret" is in v0 at this point, but doing an
- // explicit return uses an additional register.
- return ret;
+//! @bug UB: missing return. "ret" is in v0 at this point, but doing an
+// explicit return uses an additional register.
+return ret;
#endif
}
-u8 *func_sh_802f1d40(u32 size, s32 bank, u8 *arg2, s8 medium) {
+u8 *func_sh_802f1d40(u32 size, s32 bank, u8 *arg2, s8 medium)
+{
struct UnkEntry *ret;
ret = func_sh_802f1ec4(size);
- if (ret != NULL) {
+ if (ret != NULL)
+ {
ret->bankId = bank;
ret->dstAddr = arg2;
ret->medium = medium;
@@ -1475,11 +1721,13 @@ u8 *func_sh_802f1d40(u32 size, s32 bank, u8 *arg2, s8 medium) {
}
return NULL;
}
-u8 *func_sh_802f1d90(u32 size, s32 bank, u8 *arg2, s8 medium) {
+u8 *func_sh_802f1d90(u32 size, s32 bank, u8 *arg2, s8 medium)
+{
struct UnkEntry *ret;
ret = unk_pool2_alloc(size);
- if (ret != NULL) {
+ if (ret != NULL)
+ {
ret->bankId = bank;
ret->dstAddr = arg2;
ret->medium = medium;
@@ -1487,11 +1735,13 @@ u8 *func_sh_802f1d90(u32 size, s32 bank, u8 *arg2, s8 medium) {
}
return NULL;
}
-u8 *func_sh_802f1de0(u32 size, s32 bank, u8 *arg2, s8 medium) { // duplicated function?
+u8 *func_sh_802f1de0(u32 size, s32 bank, u8 *arg2, s8 medium)
+{ // duplicated function?
struct UnkEntry *ret;
ret = unk_pool2_alloc(size);
- if (ret != NULL) {
+ if (ret != NULL)
+ {
ret->bankId = bank;
ret->dstAddr = arg2;
ret->medium = medium;
@@ -1499,20 +1749,27 @@ u8 *func_sh_802f1de0(u32 size, s32 bank, u8 *arg2, s8 medium) { // duplicated fu
}
return NULL;
}
-void unk_pools_init(u32 size1, u32 size2) {
+void unk_pools_init(u32 size1, u32 size2)
+{
void *mem;
mem = sound_alloc_uninitialized(&gPersistentCommonPool, size1);
- if (mem == NULL) {
+ if (mem == NULL)
+ {
gUnkPool2.pool.size = 0;
- } else {
+ }
+ else
+ {
sound_alloc_pool_init(&gUnkPool2.pool, mem, size1);
}
mem = sound_alloc_uninitialized(&gTemporaryCommonPool, size2);
- if (mem == NULL) {
+ if (mem == NULL)
+ {
gUnkPool3.pool.size = 0;
- } else {
+ }
+ else
+ {
sound_alloc_pool_init(&gUnkPool3.pool, mem, size2);
}
@@ -1520,7 +1777,8 @@ void unk_pools_init(u32 size1, u32 size2) {
gUnkPool3.numEntries = 0;
}
-struct UnkEntry *func_sh_802f1ec4(u32 size) {
+struct UnkEntry *func_sh_802f1ec4(u32 size)
+{
u8 *temp_s2;
u8 *phi_s3;
u8 *memLocation;
@@ -1537,11 +1795,13 @@ struct UnkEntry *func_sh_802f1ec4(u32 size) {
phi_s3 = pool->pool.cur;
memLocation = sound_alloc_uninitialized(&pool->pool, size);
- if (memLocation == NULL) {
+ if (memLocation == NULL)
+ {
cur = pool->pool.cur;
pool->pool.cur = pool->pool.start;
memLocation = sound_alloc_uninitialized(&pool->pool, size);
- if (memLocation == NULL) {
+ if (memLocation == NULL)
+ {
pool->pool.cur = cur;
return NULL;
}
@@ -1550,46 +1810,54 @@ struct UnkEntry *func_sh_802f1ec4(u32 size) {
temp_s2 = pool->pool.cur;
chosenIndex = -1;
- for (i = 0; i < D_SH_8034F68C; i++) {
+ for (i = 0; i < D_SH_8034F68C; i++)
+ {
unkStruct = &D_SH_8034EC88[i];
- if (unkStruct->isFree == FALSE) {
+ if (unkStruct->isFree == FALSE)
+ {
itemStart = unkStruct->ramAddr;
itemEnd = unkStruct->ramAddr + unkStruct->sample->size - 1;
- if (itemEnd < phi_s3 && itemStart < phi_s3) {
+ if (itemEnd < phi_s3 && itemStart < phi_s3)
+ {
continue;
-
}
- if (itemEnd >= temp_s2 && itemStart >= temp_s2) {
+ if (itemEnd >= temp_s2 && itemStart >= temp_s2)
+ {
continue;
-
}
unkStruct->isFree = TRUE;
}
}
- for (i = 0; i < pool->numEntries; i++) {
- if (pool->entries[i].used == FALSE) {
+ for (i = 0; i < pool->numEntries; i++)
+ {
+ if (pool->entries[i].used == FALSE)
+ {
continue;
}
itemStart = pool->entries[i].srcAddr;
itemEnd = itemStart + pool->entries[i].size - 1;
- if (itemEnd < phi_s3 && itemStart < phi_s3) {
+ if (itemEnd < phi_s3 && itemStart < phi_s3)
+ {
continue;
}
- if (itemEnd >= temp_s2 && itemStart >= temp_s2) {
+ if (itemEnd >= temp_s2 && itemStart >= temp_s2)
+ {
continue;
}
func_sh_802f2158(&pool->entries[i]);
- if (chosenIndex == -1) {
+ if (chosenIndex == -1)
+ {
chosenIndex = i;
}
}
- if (chosenIndex == -1) {
+ if (chosenIndex == -1)
+ {
chosenIndex = pool->numEntries++;
}
pool->entries[chosenIndex].used = TRUE;
@@ -1599,7 +1867,8 @@ struct UnkEntry *func_sh_802f1ec4(u32 size) {
return &pool->entries[chosenIndex];
}
-void func_sh_802f2158(struct UnkEntry *entry) {
+void func_sh_802f2158(struct UnkEntry *entry)
+{
s32 idx;
s32 seqCount;
s32 bankId1;
@@ -1610,27 +1879,37 @@ void func_sh_802f2158(struct UnkEntry *entry) {
struct Instrument *inst;
seqCount = gAlCtlHeader->seqCount;
- for (idx = 0; idx < seqCount; idx++) {
+ for (idx = 0; idx < seqCount; idx++)
+ {
bankId1 = gCtlEntries[idx].bankId1;
bankId2 = gCtlEntries[idx].bankId2;
- if ((bankId1 != 0xff && entry->bankId == bankId1) || (bankId2 != 0xff && entry->bankId == bankId2) || entry->bankId == 0) {
- if (get_bank_or_seq(1, 2, idx) != NULL) {
- if (IS_BANK_LOAD_COMPLETE(idx) != FALSE) {
- for (instId = 0; instId < gCtlEntries[idx].numInstruments; instId++) {
+ if ((bankId1 != 0xff && entry->bankId == bankId1) || (bankId2 != 0xff && entry->bankId == bankId2) || entry->bankId == 0)
+ {
+ if (get_bank_or_seq(1, 2, idx) != NULL)
+ {
+ if (IS_BANK_LOAD_COMPLETE(idx) != FALSE)
+ {
+ for (instId = 0; instId < gCtlEntries[idx].numInstruments; instId++)
+ {
inst = get_instrument_inner(idx, instId);
- if (inst != NULL) {
- if (inst->normalRangeLo != 0) {
+ if (inst != NULL)
+ {
+ if (inst->normalRangeLo != 0)
+ {
func_sh_802F2320(entry, inst->lowNotesSound.sample);
}
- if (inst->normalRangeHi != 127) {
+ if (inst->normalRangeHi != 127)
+ {
func_sh_802F2320(entry, inst->highNotesSound.sample);
}
func_sh_802F2320(entry, inst->normalNotesSound.sample);
}
}
- for (drumId = 0; drumId < gCtlEntries[idx].numDrums; drumId++) {
+ for (drumId = 0; drumId < gCtlEntries[idx].numDrums; drumId++)
+ {
drum = get_drum(idx, drumId);
- if (drum != NULL) {
+ if (drum != NULL)
+ {
func_sh_802F2320(entry, drum->sound.sample);
}
}
@@ -1640,20 +1919,24 @@ void func_sh_802f2158(struct UnkEntry *entry) {
}
}
-void func_sh_802F2320(struct UnkEntry *entry, struct AudioBankSample *sample) {
- if (sample != NULL && sample->sampleAddr == entry->srcAddr) {
+void func_sh_802F2320(struct UnkEntry *entry, struct AudioBankSample *sample)
+{
+ if (sample != NULL && sample->sampleAddr == entry->srcAddr)
+ {
sample->sampleAddr = entry->dstAddr;
sample->medium = entry->medium;
}
}
-struct UnkEntry *unk_pool2_alloc(u32 size) {
+struct UnkEntry *unk_pool2_alloc(u32 size)
+{
void *data;
struct UnkEntry *ret;
s32 *numEntries = &gUnkPool2.numEntries;
data = sound_alloc_uninitialized(&gUnkPool2.pool, size);
- if (data == NULL) {
+ if (data == NULL)
+ {
return NULL;
}
ret = &gUnkPool2.entries[*numEntries];
@@ -1664,7 +1947,8 @@ struct UnkEntry *unk_pool2_alloc(u32 size) {
return ret;
}
-void func_sh_802f23ec(void) {
+void func_sh_802f23ec(void)
+{
s32 i;
s32 idx;
s32 seqCount;
@@ -1678,29 +1962,40 @@ void func_sh_802f23ec(void) {
struct UnkEntry *entry; //! @bug: not initialized but nevertheless used
seqCount = gAlCtlHeader->seqCount;
- for (idx = 0; idx < seqCount; idx++) {
+ for (idx = 0; idx < seqCount; idx++)
+ {
bankId1 = gCtlEntries[idx].bankId1;
bankId2 = gCtlEntries[idx].bankId2;
- if ((bankId1 != 0xffu && entry->bankId == bankId1) || (bankId2 != 0xff && entry->bankId == bankId2) || entry->bankId == 0) {
- if (get_bank_or_seq(1, 3, idx) != NULL) {
- if (IS_BANK_LOAD_COMPLETE(idx) != FALSE) {
- for (i = 0; i < gUnkPool2.numEntries; i++) {
+ if ((bankId1 != 0xffu && entry->bankId == bankId1) || (bankId2 != 0xff && entry->bankId == bankId2) || entry->bankId == 0)
+ {
+ if (get_bank_or_seq(1, 3, idx) != NULL)
+ {
+ if (IS_BANK_LOAD_COMPLETE(idx) != FALSE)
+ {
+ for (i = 0; i < gUnkPool2.numEntries; i++)
+ {
entry = &gUnkPool2.entries[i];
- for (instId = 0; instId < gCtlEntries[idx].numInstruments; instId++) {
+ for (instId = 0; instId < gCtlEntries[idx].numInstruments; instId++)
+ {
inst = get_instrument_inner(idx, instId);
- if (inst != NULL) {
- if (inst->normalRangeLo != 0) {
+ if (inst != NULL)
+ {
+ if (inst->normalRangeLo != 0)
+ {
func_sh_802F2320(entry, inst->lowNotesSound.sample);
}
- if (inst->normalRangeHi != 127) {
+ if (inst->normalRangeHi != 127)
+ {
func_sh_802F2320(entry, inst->highNotesSound.sample);
}
func_sh_802F2320(entry, inst->normalNotesSound.sample);
}
}
- for (drumId = 0; drumId < gCtlEntries[idx].numDrums; drumId++) {
+ for (drumId = 0; drumId < gCtlEntries[idx].numDrums; drumId++)
+ {
drum = get_drum(idx, drumId);
- if (drum != NULL) {
+ if (drum != NULL)
+ {
func_sh_802F2320(entry, drum->sound.sample);
}
}
diff --git a/src/decomp/audio/heap.h b/src/decomp/audio/heap.h
index 4bc73bd..0a9783f 100644
--- a/src/decomp/audio/heap.h
+++ b/src/decomp/audio/heap.h
@@ -23,34 +23,41 @@ struct SoundAllocPool
s32 numAllocatedEntries;
}; // size = 0x10
-struct SeqOrBankEntry {
+struct SeqOrBankEntry
+{
u8 *ptr;
u32 size;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
s16 poolIndex;
s16 id;
-#else
+ #else
s32 id; // seqId or bankId
-#endif
+ #endif
}; // size = 0xC
struct PersistentPool
{
- /*0x00*/ u32 numEntries;
- /*0x04*/ struct SoundAllocPool pool;
- /*0x14*/ struct SeqOrBankEntry entries[32];
+ /*0x00*/
+ u32 numEntries;
+ /*0x04*/
+ struct SoundAllocPool pool;
+ /*0x14*/
+ struct SeqOrBankEntry entries[32];
}; // size = 0x194
struct TemporaryPool
{
/*EU, SH*/
- /*0x00, 0x00*/ u32 nextSide;
- /*0x04, */ struct SoundAllocPool pool;
+ /*0x00, 0x00*/
+ u32 nextSide;
+ /*0x04, */
+ struct SoundAllocPool pool;
/*0x04, pool.start */
/*0x08, pool.cur */
/*0x0C, 0x0C pool.size */
/*0x10, 0x10 pool.numAllocatedEntries */
- /*0x14, */ struct SeqOrBankEntry entries[2];
+ /*0x14, */
+ struct SeqOrBankEntry entries[2];
/*0x14, 0x14 entries[0].ptr */
/*0x18, entries[0].size*/
/*0x1C, 0x1E entries[0].id */
@@ -61,9 +68,12 @@ struct TemporaryPool
struct SoundMultiPool
{
- /*0x000*/ struct PersistentPool persistent;
- /*0x194*/ struct TemporaryPool temporary;
- /* */ u32 pad2[4];
+ /*0x000*/
+ struct PersistentPool persistent;
+ /*0x194*/
+ struct TemporaryPool temporary;
+ /* */
+ u32 pad2[4];
}; // size = 0x1D0
struct Unk1Pool
@@ -85,10 +95,14 @@ struct UnkEntry
struct UnkPool
{
- /*0x00*/ struct SoundAllocPool pool;
- /*0x10*/ struct UnkEntry entries[64];
- /*0x510*/ s32 numEntries;
- /*0x514*/ u32 unk514;
+ /*0x00*/
+ struct SoundAllocPool pool;
+ /*0x10*/
+ struct UnkEntry entries[64];
+ /*0x510*/
+ s32 numEntries;
+ /*0x514*/
+ u32 unk514;
};
extern u8 gAudioHeap[];
@@ -115,14 +129,18 @@ extern volatile u8 gAudioResetStatus;
#endif
void *soundAlloc(struct SoundAllocPool *pool, u32 size);
+
void *sound_alloc_uninitialized(struct SoundAllocPool *pool, u32 size);
+
void sound_init_main_pools(s32 sizeForAudioInitPool);
+
void sound_alloc_pool_init(struct SoundAllocPool *pool, void *memAddr, u32 size);
#ifdef VERSION_SH
void *alloc_bank_or_seq(s32 poolIdx, s32 size, s32 arg3, s32 id);
void *get_bank_or_seq(s32 poolIdx, s32 arg1, s32 id);
#else
void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg3, s32 id);
+
void *get_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 id);
#endif
#if defined(VERSION_EU) || defined(VERSION_SH)
diff --git a/src/decomp/audio/internal.h b/src/decomp/audio/internal.h
index a3fc8f5..3c72535 100644
--- a/src/decomp/audio/internal.h
+++ b/src/decomp/audio/internal.h
@@ -104,10 +104,13 @@ struct AudioListItem
// Otherwise, that member is NULL.
struct AudioListItem *prev;
struct AudioListItem *next;
- union {
+
+ union
+ {
void *value; // either Note* or SequenceChannelLayer*
s32 count;
} u;
+
struct NotePool *pool;
}; // size = 0x10
@@ -119,37 +122,49 @@ struct NotePool
struct AudioListItem active;
};
-struct VibratoState {
- /*0x00, 0x00*/ struct SequenceChannel *seqChannel;
- /*0x04, 0x04*/ u32 time;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+struct VibratoState
+{
+ /*0x00, 0x00*/
+ struct SequenceChannel *seqChannel;
+ /*0x04, 0x04*/
+ u32 time;
+ #if defined(VERSION_EU) || defined(VERSION_SH)
/* , 0x08*/ s16 *curve;
/* , 0x0C*/ f32 extent;
/* , 0x10*/ f32 rate;
/* , 0x14*/ u8 active;
-#else
- /*0x08, */ s8 *curve;
- /*0x0C, */ u8 active;
- /*0x0E, */ u16 rate;
- /*0x10, */ u16 extent;
-#endif
- /*0x12, 0x16*/ u16 rateChangeTimer;
- /*0x14, 0x18*/ u16 extentChangeTimer;
- /*0x16, 0x1A*/ u16 delay;
+ #else
+ /*0x08, */
+ s8 *curve;
+ /*0x0C, */
+ u8 active;
+ /*0x0E, */
+ u16 rate;
+ /*0x10, */
+ u16 extent;
+ #endif
+ /*0x12, 0x16*/
+ u16 rateChangeTimer;
+ /*0x14, 0x18*/
+ u16 extentChangeTimer;
+ /*0x16, 0x1A*/
+ u16 delay;
}; // size = 0x18, 0x1C on EU
// Pitch sliding by up to one octave in the positive direction. Negative
// direction is "supported" by setting extent to be negative. The code
// extrapolates exponentially in the wrong direction in that case, but that
// doesn't prevent seqplayer from doing it, AFAICT.
-struct Portamento {
+struct Portamento
+{
u8 mode; // bit 0x80 denotes something; the rest are an index 0-5
f32 cur;
f32 speed;
f32 extent;
}; // size = 0x10
-struct AdsrEnvelope {
+struct AdsrEnvelope
+{
s16 delay;
s16 arg;
}; // size = 0x4
@@ -172,27 +187,27 @@ struct AdpcmBook
struct AudioBankSample
{
-#ifdef VERSION_SH
-#if !IS_BIG_ENDIAN
- u32 size : 24;
-#endif
- /* 0x00 */ u32 codec : 4;
- /* 0x00 */ u32 medium : 2;
- /* 0x00 */ u32 bit1 : 1;
- /* 0x00 */ u32 isPatched : 1;
-#if IS_BIG_ENDIAN
- /* 0x01 */ u32 size : 24;
-#endif
-#else
+ #ifdef VERSION_SH
+ #if !IS_BIG_ENDIAN
+ u32 size: 24;
+ #endif
+ /* 0x00 */ u32 codec: 4;
+ /* 0x00 */ u32 medium: 2;
+ /* 0x00 */ u32 bit1: 1;
+ /* 0x00 */ u32 isPatched: 1;
+ #if IS_BIG_ENDIAN
+ /* 0x01 */ u32 size: 24;
+ #endif
+ #else
u8 unused;
u8 loaded;
-#endif
+ #endif
u8 *sampleAddr;
struct AdpcmLoop *loop;
struct AdpcmBook *book;
-#ifndef VERSION_SH
+ #ifndef VERSION_SH
u32 sampleSize; // never read. either 0 or 1 mod 9, depending on padding
-#endif
+ #endif
};
struct AudioBankSound
@@ -203,14 +218,22 @@ struct AudioBankSound
struct Instrument
{
- /*0x00*/ u8 loaded;
- /*0x01*/ u8 normalRangeLo;
- /*0x02*/ u8 normalRangeHi;
- /*0x03*/ u8 releaseRate;
- /*0x04*/ struct AdsrEnvelope *envelope;
- /*0x08*/ struct AudioBankSound lowNotesSound;
- /*0x10*/ struct AudioBankSound normalNotesSound;
- /*0x18*/ struct AudioBankSound highNotesSound;
+ /*0x00*/
+ u8 loaded;
+ /*0x01*/
+ u8 normalRangeLo;
+ /*0x02*/
+ u8 normalRangeHi;
+ /*0x03*/
+ u8 releaseRate;
+ /*0x04*/
+ struct AdsrEnvelope *envelope;
+ /*0x08*/
+ struct AudioBankSound lowNotesSound;
+ /*0x10*/
+ struct AudioBankSound normalNotesSound;
+ /*0x18*/
+ struct AudioBankSound highNotesSound;
}; // size = 0x20
struct Drum
@@ -230,20 +253,21 @@ struct AudioBank
struct CtlEntry
{
-#ifndef VERSION_SH
+ #ifndef VERSION_SH
u8 unused;
-#endif
+ #endif
u8 numInstruments;
u8 numDrums;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
u8 bankId1;
u8 bankId2;
-#endif
+ #endif
struct Instrument **instruments;
struct Drum **drums;
}; // size = 0xC
-struct M64ScriptState {
+struct M64ScriptState
+{
u8 *pc;
u8 *stack[4];
u8 remLoopIters[4];
@@ -254,135 +278,194 @@ struct M64ScriptState {
struct SequencePlayer
{
/*US/JP, EU, SH */
-#if defined(VERSION_EU) || defined(VERSION_SH)
- /*0x000, 0x000, 0x000*/ u8 enabled : 1;
-#else
- /*0x000, 0x000*/ volatile u8 enabled : 1;
-#endif
- /*0x000, 0x000*/ u8 finished : 1; // never read
- /*0x000, 0x000*/ u8 muted : 1;
- /*0x000, 0x000*/ u8 seqDmaInProgress : 1;
- /*0x000, 0x000*/ u8 bankDmaInProgress : 1;
-#if defined(VERSION_EU) || defined(VERSION_SH)
- /* 0x000*/ u8 recalculateVolume : 1;
-#endif
-#ifdef VERSION_SH
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ /*0x000, 0x000, 0x000*/ u8 enabled: 1;
+ #else
+ /*0x000, 0x000*/
+ volatile u8 enabled: 1;
+ #endif
+ /*0x000, 0x000*/
+ u8 finished: 1; // never read
+ /*0x000, 0x000*/
+ u8 muted: 1;
+ /*0x000, 0x000*/
+ u8 seqDmaInProgress: 1;
+ /*0x000, 0x000*/
+ u8 bankDmaInProgress: 1;
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ /* 0x000*/ u8 recalculateVolume: 1;
+ #endif
+ #ifdef VERSION_SH
/* 0x000*/ u8 unkSh: 1;
-#endif
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #endif
+ #if defined(VERSION_JP) || defined(VERSION_US)
/*0x001 */ s8 seqVariation;
-#endif
- /*0x002, 0x001, 0x001*/ u8 state;
- /*0x003, 0x002*/ u8 noteAllocPolicy;
- /*0x004, 0x003*/ u8 muteBehavior;
- /*0x005, 0x004*/ u8 seqId;
- /*0x006, 0x005*/ u8 defaultBank[1]; // must be an array to get a comparison
+ #endif
+ /*0x002, 0x001, 0x001*/
+ u8 state;
+ /*0x003, 0x002*/
+ u8 noteAllocPolicy;
+ /*0x004, 0x003*/
+ u8 muteBehavior;
+ /*0x005, 0x004*/
+ u8 seqId;
+ /*0x006, 0x005*/
+ u8 defaultBank[1]; // must be an array to get a comparison
// to match; other u8's might also be part of that array
- /*0x007, 0x006*/ u8 loadingBankId;
-#if defined(VERSION_JP) || defined(VERSION_US)
+ /*0x007, 0x006*/
+ u8 loadingBankId;
+ #if defined(VERSION_JP) || defined(VERSION_US)
/*0x008, ?????*/ u8 loadingBankNumInstruments;
/*0x009, ?????*/ u8 loadingBankNumDrums;
-#endif
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #endif
+ #if defined(VERSION_EU) || defined(VERSION_SH)
/* , 0x007, 0x007*/ s8 seqVariationEu[1];
-#endif
- /*0x00A, 0x008*/ u16 tempo; // beats per minute in JP, tatums per minute in US/EU
- /*0x00C, 0x00A*/ u16 tempoAcc;
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #endif
+ /*0x00A, 0x008*/
+ u16 tempo; // beats per minute in JP, tatums per minute in US/EU
+ /*0x00C, 0x00A*/
+ u16 tempoAcc;
+ #if defined(VERSION_JP) || defined(VERSION_US)
/*0x00E, 0x010*/ u16 fadeRemainingFrames;
-#endif
-#ifdef VERSION_SH
+ #endif
+ #ifdef VERSION_SH
/* 0x00C*/ s16 tempoAdd;
-#endif
- /*0x010, 0x00C, 0x00E*/ s16 transposition;
- /*0x012, 0x00E, 0x010*/ u16 delay;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #endif
+ /*0x010, 0x00C, 0x00E*/
+ s16 transposition;
+ /*0x012, 0x00E, 0x010*/
+ u16 delay;
+ #if defined(VERSION_EU) || defined(VERSION_SH)
/*0x00E, 0x010, 0x012*/ u16 fadeRemainingFrames;
/* , 0x012, 0x014*/ u16 fadeTimerUnkEu;
-#endif
- /*0x014, 0x014*/ u8 *seqData; // buffer of some sort
- /*0x018, 0x018, 0x1C*/ f32 fadeVolume; // set to 1.0f
- /*0x01C, 0x01C*/ f32 fadeVelocity; // set to 0.0f
- /*0x020, 0x020, 0x024*/ f32 volume; // set to 0.0f
- /*0x024, 0x024*/ f32 muteVolumeScale; // set to 0.5f
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #endif
+ /*0x014, 0x014*/
+ u8 *seqData; // buffer of some sort
+ /*0x018, 0x018, 0x1C*/
+ f32 fadeVolume; // set to 1.0f
+ /*0x01C, 0x01C*/
+ f32 fadeVelocity; // set to 0.0f
+ /*0x020, 0x020, 0x024*/
+ f32 volume; // set to 0.0f
+ /*0x024, 0x024*/
+ f32 muteVolumeScale; // set to 0.5f
+ #if defined(VERSION_EU) || defined(VERSION_SH)
/* , 0x028, 0x02C*/ f32 fadeVolumeScale;
/* , 0x02C*/ f32 appliedFadeVolume;
-#else
- /* */ u8 pad2[4];
-#endif
- /*0x02C, 0x030, 0x034*/ struct SequenceChannel *channels[CHANNELS_MAX];
- /*0x06C, 0x070*/ struct M64ScriptState scriptState;
- /*0x088, 0x08C*/ u8 *shortNoteVelocityTable;
- /*0x08C, 0x090*/ u8 *shortNoteDurationTable;
- /*0x090, 0x094*/ struct NotePool notePool;
- /*0x0D0, 0x0D4*/ OSMesgQueue seqDmaMesgQueue;
- /*0x0E8, 0x0EC*/ OSMesg seqDmaMesg;
- /*0x0EC, 0x0F0*/ OSIoMesg seqDmaIoMesg;
- /*0x100, 0x108*/ OSMesgQueue bankDmaMesgQueue;
- /*0x118, 0x120*/ OSMesg bankDmaMesg;
- /*0x11C, 0x124*/ OSIoMesg bankDmaIoMesg;
- /*0x130, 0x13C*/ u8 *bankDmaCurrMemAddr;
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #else
+ /* */
+ u8 pad2[4];
+ #endif
+ /*0x02C, 0x030, 0x034*/
+ struct SequenceChannel *channels[CHANNELS_MAX];
+ /*0x06C, 0x070*/
+ struct M64ScriptState scriptState;
+ /*0x088, 0x08C*/
+ u8 *shortNoteVelocityTable;
+ /*0x08C, 0x090*/
+ u8 *shortNoteDurationTable;
+ /*0x090, 0x094*/
+ struct NotePool notePool;
+ /*0x0D0, 0x0D4*/
+ OSMesgQueue seqDmaMesgQueue;
+ /*0x0E8, 0x0EC*/
+ OSMesg seqDmaMesg;
+ /*0x0EC, 0x0F0*/
+ OSIoMesg seqDmaIoMesg;
+ /*0x100, 0x108*/
+ OSMesgQueue bankDmaMesgQueue;
+ /*0x118, 0x120*/
+ OSMesg bankDmaMesg;
+ /*0x11C, 0x124*/
+ OSIoMesg bankDmaIoMesg;
+ /*0x130, 0x13C*/
+ u8 *bankDmaCurrMemAddr;
+ #if defined(VERSION_JP) || defined(VERSION_US)
/*0x134, ?????*/ struct AudioBank *loadingBank;
-#endif
- /*0x138, 0x140*/ uintptr_t bankDmaCurrDevAddr;
- /*0x13C, 0x144*/ ssize_t bankDmaRemaining;
+ #endif
+ /*0x138, 0x140*/
+ uintptr_t bankDmaCurrDevAddr;
+ /*0x13C, 0x144*/
+ ssize_t bankDmaRemaining;
}; // size = 0x140, 0x148 on EU, 0x14C on SH
struct AdsrSettings
{
u8 releaseRate;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
u8 sustain;
-#else
+ #else
u16 sustain; // sustain level, 2^16 = max
-#endif
+ #endif
struct AdsrEnvelope *envelope;
}; // size = 0x8
-struct AdsrState {
- /*0x00, 0x00*/ u8 action;
- /*0x01, 0x01*/ u8 state;
-#if defined(VERSION_JP) || defined(VERSION_US)
+struct AdsrState
+{
+ /*0x00, 0x00*/
+ u8 action;
+ /*0x01, 0x01*/
+ u8 state;
+ #if defined(VERSION_JP) || defined(VERSION_US)
/*0x02, */ s16 initial; // always 0
/*0x04, */ s16 target;
/*0x06, */ s16 current;
-#endif
- /*0x08, 0x02*/ s16 envIndex;
- /*0x0A, 0x04*/ s16 delay;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #endif
+ /*0x08, 0x02*/
+ s16 envIndex;
+ /*0x0A, 0x04*/
+ s16 delay;
+ #if defined(VERSION_EU) || defined(VERSION_SH)
/* , 0x08*/ f32 sustain;
/* , 0x0C*/ f32 velocity;
/* , 0x10*/ f32 fadeOutVel;
/* , 0x14*/ f32 current;
/* , 0x18*/ f32 target;
s32 pad1C;
-#else
- /*0x0C, */ s16 sustain;
- /*0x0E, */ s16 fadeOutVel;
- /*0x10, */ s32 velocity;
- /*0x14, */ s32 currentHiRes;
- /*0x18, */ s16 *volOut;
-#endif
- /*0x1C, 0x20*/ struct AdsrEnvelope *envelope;
+ #else
+ /*0x0C, */
+ s16 sustain;
+ /*0x0E, */
+ s16 fadeOutVel;
+ /*0x10, */
+ s32 velocity;
+ /*0x14, */
+ s32 currentHiRes;
+ /*0x18, */
+ s16 *volOut;
+ #endif
+ /*0x1C, 0x20*/
+ struct AdsrEnvelope *envelope;
}; // size = 0x20, 0x24 in EU
-struct ReverbBitsData {
- /* 0x00 */ u8 bit0 : 1;
- /* 0x00 */ u8 bit1 : 1;
- /* 0x00 */ u8 bit2 : 1;
- /* 0x00 */ u8 usesHeadsetPanEffects : 1;
- /* 0x00 */ u8 stereoHeadsetEffects : 2;
- /* 0x00 */ u8 strongRight : 1;
- /* 0x00 */ u8 strongLeft : 1;
+struct ReverbBitsData
+{
+ /* 0x00 */
+ u8 bit0: 1;
+ /* 0x00 */
+ u8 bit1: 1;
+ /* 0x00 */
+ u8 bit2: 1;
+ /* 0x00 */
+ u8 usesHeadsetPanEffects: 1;
+ /* 0x00 */
+ u8 stereoHeadsetEffects: 2;
+ /* 0x00 */
+ u8 strongRight: 1;
+ /* 0x00 */
+ u8 strongLeft: 1;
};
-union ReverbBits {
- /* 0x00 */ struct ReverbBitsData s;
- /* 0x00 */ u8 asByte;
+union ReverbBits
+{
+ /* 0x00 */
+ struct ReverbBitsData s;
+ /* 0x00 */
+ u8 asByte;
};
-struct ReverbInfo {
+
+struct ReverbInfo
+{
u8 reverbVol;
u8 synthesisVolume; // UQ4.4, although 0 <= x < 1 is rounded up to 1
u8 pan;
@@ -396,23 +479,23 @@ struct ReverbInfo {
struct NoteAttributes
{
u8 reverbVol;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
u8 synthesisVolume; // UQ4.4, although 0 <= x < 1 is rounded up to 1
-#endif
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #endif
+ #if defined(VERSION_EU) || defined(VERSION_SH)
u8 pan;
-#endif
-#ifdef VERSION_SH
+ #endif
+ #ifdef VERSION_SH
union ReverbBits reverbBits;
-#endif
+ #endif
f32 freqScale;
f32 velocity;
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #if defined(VERSION_JP) || defined(VERSION_US)
f32 pan;
-#endif
-#ifdef VERSION_SH
+ #endif
+ #ifdef VERSION_SH
s16 *filter;
-#endif
+ #endif
}; // size = 0x10
// Also known as a SubTrack, according to debug strings.
@@ -420,305 +503,441 @@ struct NoteAttributes
struct SequenceChannel
{
/* U/J, EU, SH */
- /*0x00, 0x00*/ u8 enabled : 1;
- /*0x00, 0x00*/ u8 finished : 1;
- /*0x00, 0x00*/ u8 stopScript : 1;
- /*0x00, 0x00*/ u8 stopSomething2 : 1; // sets SequenceChannelLayer.stopSomething
- /*0x00, 0x00*/ u8 hasInstrument : 1;
- /*0x00, 0x00*/ u8 stereoHeadsetEffects : 1;
- /*0x00, ????*/ u8 largeNotes : 1; // notes specify duration and velocity
- /*0x00, ????*/ u8 unused : 1; // never read, set to 0
-#if defined(VERSION_EU) || defined(VERSION_SH)
- /* , 0x01*/ union {
- struct {
- u8 freqScale : 1;
- u8 volume : 1;
- u8 pan : 1;
+ /*0x00, 0x00*/
+ u8 enabled: 1;
+ /*0x00, 0x00*/
+ u8 finished: 1;
+ /*0x00, 0x00*/
+ u8 stopScript: 1;
+ /*0x00, 0x00*/
+ u8 stopSomething2: 1; // sets SequenceChannelLayer.stopSomething
+ /*0x00, 0x00*/
+ u8 hasInstrument: 1;
+ /*0x00, 0x00*/
+ u8 stereoHeadsetEffects: 1;
+ /*0x00, ????*/
+ u8 largeNotes: 1; // notes specify duration and velocity
+ /*0x00, ????*/
+ u8 unused: 1; // never read, set to 0
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ /* , 0x01*/ union
+ {
+ struct
+ {
+ u8 freqScale: 1;
+ u8 volume: 1;
+ u8 pan: 1;
} as_bitfields;
+
u8 as_u8;
} changes;
-#endif
- /*0x01, 0x02*/ u8 noteAllocPolicy;
- /*0x02, 0x03, 0x03*/ u8 muteBehavior;
- /*0x03, 0x04, 0x04*/ u8 reverbVol; // until EU: Q1.7, after EU: UQ0.8
- /*0x04, ????*/ u8 notePriority; // 0-3
-#ifdef VERSION_SH
- u8 unkSH06; // some priority
-#endif
- /*0x05, 0x06*/ u8 bankId;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #endif
+ /*0x01, 0x02*/
+ u8 noteAllocPolicy;
+ /*0x02, 0x03, 0x03*/
+ u8 muteBehavior;
+ /*0x03, 0x04, 0x04*/
+ u8 reverbVol; // until EU: Q1.7, after EU: UQ0.8
+ /*0x04, ????*/
+ u8 notePriority; // 0-3
+ #ifdef VERSION_SH
+ u8 unkSH06; // some priority
+ #endif
+ /*0x05, 0x06*/
+ u8 bankId;
+ #if defined(VERSION_EU) || defined(VERSION_SH)
/* , 0x07*/ u8 reverbIndex;
/* , 0x08, 0x09*/ u8 bookOffset;
/* , 0x09*/ u8 newPan;
/* , 0x0A*/ u8 panChannelWeight; // proportion of pan that comes from the channel (0..128)
-#else
- /*0x06, */ u8 updatesPerFrameUnused;
-#endif
-#ifdef VERSION_SH
+ #else
+ /*0x06, */
+ u8 updatesPerFrameUnused;
+ #endif
+ #ifdef VERSION_SH
/* 0x0C*/ u8 synthesisVolume; // UQ4.4, although 0 <= x < 1 is rounded up to 1
-#endif
- /*0x08, 0x0C, 0x0E*/ u16 vibratoRateStart; // initially 0x800
- /*0x0A, 0x0E, 0x10*/ u16 vibratoExtentStart;
- /*0x0C, 0x10, 0x12*/ u16 vibratoRateTarget; // initially 0x800
- /*0x0E, 0x12, 0x14*/ u16 vibratoExtentTarget;
- /*0x10, 0x14, 0x16*/ u16 vibratoRateChangeDelay;
- /*0x12, 0x16, 0x18*/ u16 vibratoExtentChangeDelay;
- /*0x14, 0x18, 0x1A*/ u16 vibratoDelay;
- /*0x16, 0x1A, 0x1C*/ u16 delay;
- /*0x18, 0x1C, 0x1E*/ s16 instOrWave; // either 0 (none), instrument index + 1, or
+ #endif
+ /*0x08, 0x0C, 0x0E*/
+ u16 vibratoRateStart; // initially 0x800
+ /*0x0A, 0x0E, 0x10*/
+ u16 vibratoExtentStart;
+ /*0x0C, 0x10, 0x12*/
+ u16 vibratoRateTarget; // initially 0x800
+ /*0x0E, 0x12, 0x14*/
+ u16 vibratoExtentTarget;
+ /*0x10, 0x14, 0x16*/
+ u16 vibratoRateChangeDelay;
+ /*0x12, 0x16, 0x18*/
+ u16 vibratoExtentChangeDelay;
+ /*0x14, 0x18, 0x1A*/
+ u16 vibratoDelay;
+ /*0x16, 0x1A, 0x1C*/
+ u16 delay;
+ /*0x18, 0x1C, 0x1E*/
+ s16 instOrWave; // either 0 (none), instrument index + 1, or
// 0x80..0x83 for sawtooth/triangle/sine/square waves.
- /*0x1A, 0x1E, 0x20*/ s16 transposition;
- /*0x1C, 0x20, 0x24*/ f32 volumeScale;
- /*0x20, 0x24, 0x28*/ f32 volume;
-#if defined(VERSION_JP) || defined(VERSION_US)
+ /*0x1A, 0x1E, 0x20*/
+ s16 transposition;
+ /*0x1C, 0x20, 0x24*/
+ f32 volumeScale;
+ /*0x20, 0x24, 0x28*/
+ f32 volume;
+ #if defined(VERSION_JP) || defined(VERSION_US)
/*0x24, */ f32 pan;
/*0x28, */ f32 panChannelWeight; // proportion of pan that comes from the channel (0..1)
-#else
- /* , 0x28*/ s32 pan;
- /* , 0x2C*/ f32 appliedVolume;
-#endif
- /*0x2C, 0x30*/ f32 freqScale;
- /*0x30, 0x34*/ u8 (*dynTable)[][2];
- /*0x34, ????*/ struct Note *noteUnused; // never read
- /*0x38, ????*/ struct SequenceChannelLayer *layerUnused; // never read
- /*0x3C, 0x40*/ struct Instrument *instrument;
- /*0x40, 0x44*/ struct SequencePlayer *seqPlayer;
- /*0x44, 0x48*/ struct SequenceChannelLayer *layers[LAYERS_MAX];
-#ifndef VERSION_SH
- /*0x54, 0x58 */ s8 soundScriptIO[8]; // bridge between sound script and audio lib. For player 2,
+ #else
+ /* , 0x28*/
+ s32 pan;
+ /* , 0x2C*/
+ f32 appliedVolume;
+ #endif
+ /*0x2C, 0x30*/
+ f32 freqScale;
+ /*0x30, 0x34*/
+ u8 (*dynTable)[][2];
+ /*0x34, ????*/
+ struct Note *noteUnused; // never read
+ /*0x38, ????*/
+ struct SequenceChannelLayer *layerUnused; // never read
+ /*0x3C, 0x40*/
+ struct Instrument *instrument;
+ /*0x40, 0x44*/
+ struct SequencePlayer *seqPlayer;
+ /*0x44, 0x48*/
+ struct SequenceChannelLayer *layers[LAYERS_MAX];
+ #ifndef VERSION_SH
+ /*0x54, 0x58 */
+ s8 soundScriptIO[8]; // bridge between sound script and audio lib. For player 2,
// [0] contains enabled, [4] contains sound ID, [5] contains reverb adjustment
-#endif
- /*0x5C, 0x60*/ struct M64ScriptState scriptState;
- /*0x78, 0x7C*/ struct AdsrSettings adsr;
- /*0x80, 0x84*/ struct NotePool notePool;
-#ifdef VERSION_SH
+ #endif
+ /*0x5C, 0x60*/
+ struct M64ScriptState scriptState;
+ /*0x78, 0x7C*/
+ struct AdsrSettings adsr;
+ /*0x80, 0x84*/
+ struct NotePool notePool;
+ #ifdef VERSION_SH
/* 0xC0*/ s8 soundScriptIO[8]; // bridge between sound script and audio lib. For player 2,
// [0] contains enabled, [4] contains sound ID, [5] contains reverb adjustment
/* 0xC8*/ u16 unkC8;
/* 0xCC*/ s16 *filter;
-#endif
+ #endif
}; // size = 0xC0, 0xC4 in EU, 0xD0 in SH
// Also known as a Track, according to debug strings.
struct SequenceChannelLayer
{
/* U/J, EU, SH */
- /*0x00, 0x00*/ u8 enabled : 1;
- /*0x00, 0x00*/ u8 finished : 1;
- /*0x00, 0x00*/ u8 stopSomething : 1; // ?
- /*0x00, 0x00*/ u8 continuousNotes : 1; // keep the same note for consecutive notes with the same sound
-#if defined(VERSION_EU) || defined(VERSION_SH)
- /* , 0x00*/ u8 unusedEu0b8 : 1;
- /* , 0x00*/ u8 notePropertiesNeedInit : 1;
- /* , 0x00*/ u8 ignoreDrumPan : 1;
-#ifdef VERSION_SH
+ /*0x00, 0x00*/
+ u8 enabled: 1;
+ /*0x00, 0x00*/
+ u8 finished: 1;
+ /*0x00, 0x00*/
+ u8 stopSomething: 1; // ?
+ /*0x00, 0x00*/
+ u8 continuousNotes: 1; // keep the same note for consecutive notes with the same sound
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ /* , 0x00*/ u8 unusedEu0b8: 1;
+ /* , 0x00*/ u8 notePropertiesNeedInit: 1;
+ /* , 0x00*/ u8 ignoreDrumPan: 1;
+ #ifdef VERSION_SH
/* , , 0x01 */ union ReverbBits reverbBits;
-#endif
+ #endif
/* , 0x01, 0x02*/ u8 instOrWave;
-#endif
- /*0x01, 0x02, 0x03*/ u8 status; // 0x03 in SH
- /*0x02, 0x03*/ u8 noteDuration; // set to 0x80
- /*0x03, 0x04*/ u8 portamentoTargetNote;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #endif
+ /*0x01, 0x02, 0x03*/
+ u8 status; // 0x03 in SH
+ /*0x02, 0x03*/
+ u8 noteDuration; // set to 0x80
+ /*0x03, 0x04*/
+ u8 portamentoTargetNote;
+ #if defined(VERSION_EU) || defined(VERSION_SH)
/* , 0x05*/ u8 pan; // 0..128
/* , 0x06, 0x07*/ u8 notePan;
-#endif
- /*0x04, 0x08*/ struct Portamento portamento;
- /*0x14, 0x18*/ struct AdsrSettings adsr;
- /*0x1C, 0x20*/ u16 portamentoTime;
- /*0x1E, 0x22*/ s16 transposition; // #semitones added to play commands
+ #endif
+ /*0x04, 0x08*/
+ struct Portamento portamento;
+ /*0x14, 0x18*/
+ struct AdsrSettings adsr;
+ /*0x1C, 0x20*/
+ u16 portamentoTime;
+ /*0x1E, 0x22*/
+ s16 transposition; // #semitones added to play commands
// (m64 instruction encoding only allows referring to the limited range
// 0..0x3f; this makes 0x40..0x7f accessible as well)
- /*0x20, 0x24, 0x24*/ f32 freqScale;
-#ifdef VERSION_SH
+ /*0x20, 0x24, 0x24*/
+ f32 freqScale;
+ #ifdef VERSION_SH
/* 0x28*/ f32 freqScaleMultiplier;
-#endif
- /*0x24, 0x28, 0x2C*/ f32 velocitySquare;
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #endif
+ /*0x24, 0x28, 0x2C*/
+ f32 velocitySquare;
+ #if defined(VERSION_JP) || defined(VERSION_US)
/*0x28, */ f32 pan; // 0..1
-#endif
- /*0x2C, 0x2C, 0x30*/ f32 noteVelocity;
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #endif
+ /*0x2C, 0x2C, 0x30*/
+ f32 noteVelocity;
+ #if defined(VERSION_JP) || defined(VERSION_US)
/*0x30*/ f32 notePan;
-#endif
- /*0x34, 0x30, 0x34*/ f32 noteFreqScale;
- /*0x38, 0x34*/ s16 shortNoteDefaultPlayPercentage;
- /*0x3A, 0x36*/ s16 playPercentage; // it's not really a percentage...
- /*0x3C, 0x38*/ s16 delay;
- /*0x3E, 0x3A*/ s16 duration;
- /*0x40, 0x3C*/ s16 delayUnused; // set to 'delay', never read
- /*0x44, 0x40, 0x44*/ struct Note *note;
- /*0x48, 0x44*/ struct Instrument *instrument;
- /*0x4C, 0x48*/ struct AudioBankSound *sound;
- /*0x50, 0x4C, 0x50*/ struct SequenceChannel *seqChannel;
- /*0x54, 0x50*/ struct M64ScriptState scriptState;
- /*0x70, 0x6C*/ struct AudioListItem listItem;
-#if defined(VERSION_EU)
+ #endif
+ /*0x34, 0x30, 0x34*/
+ f32 noteFreqScale;
+ /*0x38, 0x34*/
+ s16 shortNoteDefaultPlayPercentage;
+ /*0x3A, 0x36*/
+ s16 playPercentage; // it's not really a percentage...
+ /*0x3C, 0x38*/
+ s16 delay;
+ /*0x3E, 0x3A*/
+ s16 duration;
+ /*0x40, 0x3C*/
+ s16 delayUnused; // set to 'delay', never read
+ /*0x44, 0x40, 0x44*/
+ struct Note *note;
+ /*0x48, 0x44*/
+ struct Instrument *instrument;
+ /*0x4C, 0x48*/
+ struct AudioBankSound *sound;
+ /*0x50, 0x4C, 0x50*/
+ struct SequenceChannel *seqChannel;
+ /*0x54, 0x50*/
+ struct M64ScriptState scriptState;
+ /*0x70, 0x6C*/
+ struct AudioListItem listItem;
+ #if defined(VERSION_EU)
u8 pad2[4];
-#endif
+ #endif
}; // size = 0x80
#if defined(VERSION_EU) || defined(VERSION_SH)
struct NoteSynthesisState
{
- /*0x00*/ u8 restart;
- /*0x01*/ u8 sampleDmaIndex;
- /*0x02*/ u8 prevHeadsetPanRight;
- /*0x03*/ u8 prevHeadsetPanLeft;
+ /*0x00*/
+ u8 restart;
+ /*0x01*/
+ u8 sampleDmaIndex;
+ /*0x02*/
+ u8 prevHeadsetPanRight;
+ /*0x03*/
+ u8 prevHeadsetPanLeft;
#ifdef VERSION_SH
- /* 0x04*/ u8 reverbVol;
- /* 0x05*/ u8 unk5;
+/* 0x04*/ u8 reverbVol;
+/* 0x05*/ u8 unk5;
#endif
- /*0x04, 0x06*/ u16 samplePosFrac;
- /*0x08*/ s32 samplePosInt;
- /*0x0C*/ struct NoteSynthesisBuffers *synthesisBuffers;
- /*0x10*/ s16 curVolLeft; // UQ0.16 (EU Q1.15)
- /*0x12*/ s16 curVolRight; // UQ0.16 (EU Q1.15)
+/*0x04, 0x06*/ u16 samplePosFrac;
+/*0x08*/ s32 samplePosInt;
+/*0x0C*/ struct NoteSynthesisBuffers *synthesisBuffers;
+/*0x10*/ s16 curVolLeft; // UQ0.16 (EU Q1.15)
+/*0x12*/ s16 curVolRight; // UQ0.16 (EU Q1.15)
};
struct NotePlaybackState
{
/* U/J, EU, SH */
- /*0x04, 0x00, 0x00*/ u8 priority;
- /* 0x01, 0x01*/ u8 waveId;
- /* 0x02, 0x02*/ u8 sampleCountIndex;
+ /*0x04, 0x00, 0x00*/
+ u8 priority;
+ /* 0x01, 0x01*/
+ u8 waveId;
+ /* 0x02, 0x02*/
+ u8 sampleCountIndex;
#ifdef VERSION_SH
- /* 0x03*/ u8 bankId;
- /* 0x04*/ u8 unkSH34;
+/* 0x03*/ u8 bankId;
+/* 0x04*/ u8 unkSH34;
#endif
- /*0x08, 0x04, 0x06*/ s16 adsrVolScale;
- /*0x18, 0x08, 0x08*/ f32 portamentoFreqScale;
- /*0x1C, 0x0C, 0x0C*/ f32 vibratoFreqScale;
- /*0x28, 0x10, */ struct SequenceChannelLayer *prevParentLayer;
- /*0x2C, 0x14, 0x14*/ struct SequenceChannelLayer *parentLayer;
- /*0x30, 0x18, 0x18*/ struct SequenceChannelLayer *wantedParentLayer;
- /* , 0x1C, 0x1C*/ struct NoteAttributes attributes;
- /*0x54, 0x28, 0x2C*/ struct AdsrState adsr;
- /*0x74, 0x4C, */ struct Portamento portamento;
- /*0x84, 0x5C, */ struct VibratoState vibratoState;
+/*0x08, 0x04, 0x06*/ s16 adsrVolScale;
+/*0x18, 0x08, 0x08*/ f32 portamentoFreqScale;
+/*0x1C, 0x0C, 0x0C*/ f32 vibratoFreqScale;
+/*0x28, 0x10, */ struct SequenceChannelLayer *prevParentLayer;
+/*0x2C, 0x14, 0x14*/ struct SequenceChannelLayer *parentLayer;
+/*0x30, 0x18, 0x18*/ struct SequenceChannelLayer *wantedParentLayer;
+/* , 0x1C, 0x1C*/ struct NoteAttributes attributes;
+/*0x54, 0x28, 0x2C*/ struct AdsrState adsr;
+/*0x74, 0x4C, */ struct Portamento portamento;
+/*0x84, 0x5C, */ struct VibratoState vibratoState;
};
struct NoteSubEu
{
- /*0x00*/ volatile u8 enabled : 1;
- /*0x00*/ u8 needsInit : 1;
- /*0x00*/ u8 finished : 1;
- /*0x00*/ u8 envMixerNeedsInit : 1;
- /*0x00*/ u8 stereoStrongRight : 1;
- /*0x00*/ u8 stereoStrongLeft : 1;
- /*0x00*/ u8 stereoHeadsetEffects : 1;
- /*0x00*/ u8 usesHeadsetPanEffects : 1;
- /*0x01*/ u8 reverbIndex : 3;
- /*0x01*/ u8 bookOffset : 3;
- /*0x01*/ u8 isSyntheticWave : 1;
- /*0x01*/ u8 hasTwoAdpcmParts : 1;
+ /*0x00*/
+ volatile u8 enabled: 1;
+ /*0x00*/
+ u8 needsInit: 1;
+ /*0x00*/
+ u8 finished: 1;
+ /*0x00*/
+ u8 envMixerNeedsInit: 1;
+ /*0x00*/
+ u8 stereoStrongRight: 1;
+ /*0x00*/
+ u8 stereoStrongLeft: 1;
+ /*0x00*/
+ u8 stereoHeadsetEffects: 1;
+ /*0x00*/
+ u8 usesHeadsetPanEffects: 1;
+ /*0x01*/
+ u8 reverbIndex: 3;
+ /*0x01*/
+ u8 bookOffset: 3;
+ /*0x01*/
+ u8 isSyntheticWave: 1;
+ /*0x01*/
+ u8 hasTwoAdpcmParts: 1;
#ifdef VERSION_EU
- /*0x02*/ u8 bankId;
+/*0x02*/ u8 bankId;
#else
- /*0x02*/ u8 synthesisVolume; // UQ4.4, although 0 <= x < 1 is rounded up to 1
+/*0x02*/ u8 synthesisVolume; // UQ4.4, although 0 <= x < 1 is rounded up to 1
#endif
- /*0x03*/ u8 headsetPanRight;
- /*0x04*/ u8 headsetPanLeft;
- /*0x05*/ u8 reverbVol; // UQ0.7 (EU Q1.7)
- /*0x06*/ u16 targetVolLeft; // UQ0.12 (EU UQ0.10)
- /*0x08*/ u16 targetVolRight; // UQ0.12 (EU UQ0.10)
- /*0x0A*/ u16 resamplingRateFixedPoint; // stored as signed but loaded as u16
- /*0x0C*/ union {
- s16 *samples;
- struct AudioBankSound *audioBankSound;
- } sound;
+/*0x03*/ u8 headsetPanRight;
+/*0x04*/ u8 headsetPanLeft;
+/*0x05*/ u8 reverbVol; // UQ0.7 (EU Q1.7)
+/*0x06*/ u16 targetVolLeft; // UQ0.12 (EU UQ0.10)
+/*0x08*/ u16 targetVolRight; // UQ0.12 (EU UQ0.10)
+/*0x0A*/ u16 resamplingRateFixedPoint; // stored as signed but loaded as u16
+/*0x0C*/ union
+{
+ s16 *samples;
+ struct AudioBankSound *audioBankSound;
+} sound;
#ifdef VERSION_SH
- /*0x10*/ s16 *filter;
+/*0x10*/ s16 *filter;
#endif
};
struct Note
{
/* U/J, EU, SH */
- /*0xA4, 0x00, 0x00*/ struct AudioListItem listItem;
- /* 0x10, 0x10*/ struct NoteSynthesisState synthesisState;
- // The next members are actually part of a struct (NotePlaybackState), but
- // that results in messy US/EU ifdefs. Instead we cast to a struct pointer
- // when needed... This breaks alignment on non-N64 platforms, which we hack
- // around by skipping the padding in that case.
- // TODO: use macros or something instead.
+ /*0xA4, 0x00, 0x00*/
+ struct AudioListItem listItem;
+ /* 0x10, 0x10*/
+ struct NoteSynthesisState synthesisState;
+// The next members are actually part of a struct (NotePlaybackState), but
+// that results in messy US/EU ifdefs. Instead we cast to a struct pointer
+// when needed... This breaks alignment on non-N64 platforms, which we hack
+// around by skipping the padding in that case.
+// TODO: use macros or something instead.
#ifdef TARGET_N64
- u8 pad0[12];
+u8 pad0[12];
#endif
- /*0x04, 0x30, 0x30*/ u8 priority;
- /* 0x31, 0x31*/ u8 waveId;
- /* 0x32, 0x32*/ u8 sampleCountIndex;
+/*0x04, 0x30, 0x30*/ u8 priority;
+/* 0x31, 0x31*/ u8 waveId;
+/* 0x32, 0x32*/ u8 sampleCountIndex;
#ifdef VERSION_SH
- /* 0x33*/ u8 bankId;
- /* 0x34*/ u8 unkSH34;
+/* 0x33*/ u8 bankId;
+/* 0x34*/ u8 unkSH34;
#endif
- /*0x08, 0x34, 0x36*/ s16 adsrVolScale;
- /*0x18, 0x38, */ f32 portamentoFreqScale;
- /*0x1C, 0x3C, */ f32 vibratoFreqScale;
- /*0x28, 0x40, */ struct SequenceChannelLayer *prevParentLayer;
- /*0x2C, 0x44, 0x44*/ struct SequenceChannelLayer *parentLayer;
- /*0x30, 0x48, 0x48*/ struct SequenceChannelLayer *wantedParentLayer;
- /* , 0x4C, 0x4C*/ struct NoteAttributes attributes;
- /*0x54, 0x58, 0x5C*/ struct AdsrState adsr;
- /*0x74, 0x7C*/ struct Portamento portamento;
- /*0x84, 0x8C*/ struct VibratoState vibratoState;
- u8 pad3[8];
- /* , 0xB0, 0xB4*/ struct NoteSubEu noteSubEu;
+/*0x08, 0x34, 0x36*/ s16 adsrVolScale;
+/*0x18, 0x38, */ f32 portamentoFreqScale;
+/*0x1C, 0x3C, */ f32 vibratoFreqScale;
+/*0x28, 0x40, */ struct SequenceChannelLayer *prevParentLayer;
+/*0x2C, 0x44, 0x44*/ struct SequenceChannelLayer *parentLayer;
+/*0x30, 0x48, 0x48*/ struct SequenceChannelLayer *wantedParentLayer;
+/* , 0x4C, 0x4C*/ struct NoteAttributes attributes;
+/*0x54, 0x58, 0x5C*/ struct AdsrState adsr;
+/*0x74, 0x7C*/ struct Portamento portamento;
+/*0x84, 0x8C*/ struct VibratoState vibratoState;
+u8 pad3[8];
+/* , 0xB0, 0xB4*/ struct NoteSubEu noteSubEu;
}; // size = 0xC0, known to be 0xC8 on SH
#else
// volatile Note, needed in synthesis_process_notes
struct vNote
{
/* U/J, EU */
- /*0x00*/ volatile u8 enabled : 1;
+ /*0x00*/
+ volatile u8 enabled: 1;
long long int force_structure_alignment;
}; // size = 0xC0
struct Note
{
/* U/J, EU */
- /*0x00*/ u8 enabled : 1;
- /*0x00*/ u8 needsInit : 1;
- /*0x00*/ u8 restart : 1;
- /*0x00*/ u8 finished : 1;
- /*0x00*/ u8 envMixerNeedsInit : 1;
- /*0x00*/ u8 stereoStrongRight : 1;
- /*0x00*/ u8 stereoStrongLeft : 1;
- /*0x00*/ u8 stereoHeadsetEffects : 1;
- /*0x01*/ u8 usesHeadsetPanEffects;
- /*0x02*/ u8 unk2;
- /*0x03*/ u8 sampleDmaIndex;
- /*0x04, 0x30*/ u8 priority;
- /*0x05*/ u8 sampleCount; // 0, 8, 16, 32 or 64
- /*0x06*/ u8 instOrWave;
- /*0x07*/ u8 bankId; // in NoteSubEu on EU
- /*0x08*/ s16 adsrVolScale;
- /* */ u8 pad1[2];
- /*0x0C, 0xB3*/ u16 headsetPanRight;
- /*0x0E, 0xB4*/ u16 headsetPanLeft;
- /*0x10*/ u16 prevHeadsetPanRight;
- /*0x12*/ u16 prevHeadsetPanLeft;
- /*0x14*/ s32 samplePosInt;
- /*0x18, 0x38*/ f32 portamentoFreqScale;
- /*0x1C, 0x3C*/ f32 vibratoFreqScale;
- /*0x20*/ u16 samplePosFrac;
- /*0x24*/ struct AudioBankSound *sound;
- /*0x28, 0x40*/ struct SequenceChannelLayer *prevParentLayer;
- /*0x2C, 0x44*/ struct SequenceChannelLayer *parentLayer;
- /*0x30, 0x48*/ struct SequenceChannelLayer *wantedParentLayer;
- /*0x34*/ struct NoteSynthesisBuffers *synthesisBuffers;
- /*0x38*/ f32 frequency;
- /*0x3C*/ u16 targetVolLeft; // Q1.15, but will always be non-negative
- /*0x3E*/ u16 targetVolRight; // Q1.15, but will always be non-negative
- /*0x40*/ u8 reverbVol; // Q1.7
- /*0x41*/ u8 unused1; // never read, set to 0x3f
- /*0x44*/ struct NoteAttributes attributes;
- /*0x54, 0x58*/ struct AdsrState adsr;
- /*0x74, 0x7C*/ struct Portamento portamento;
- /*0x84, 0x8C*/ struct VibratoState vibratoState;
- /*0x9C*/ s16 curVolLeft; // Q1.15, but will always be non-negative
- /*0x9E*/ s16 curVolRight; // Q1.15, but will always be non-negative
- /*0xA0*/ s16 reverbVolShifted; // Q1.15
- /*0xA2*/ s16 unused2; // never read, set to 0
- /*0xA4, 0x00*/ struct AudioListItem listItem;
- /* */ u8 pad2[0xc];
+ /*0x00*/
+ u8 enabled: 1;
+ /*0x00*/
+ u8 needsInit: 1;
+ /*0x00*/
+ u8 restart: 1;
+ /*0x00*/
+ u8 finished: 1;
+ /*0x00*/
+ u8 envMixerNeedsInit: 1;
+ /*0x00*/
+ u8 stereoStrongRight: 1;
+ /*0x00*/
+ u8 stereoStrongLeft: 1;
+ /*0x00*/
+ u8 stereoHeadsetEffects: 1;
+ /*0x01*/
+ u8 usesHeadsetPanEffects;
+ /*0x02*/
+ u8 unk2;
+ /*0x03*/
+ u8 sampleDmaIndex;
+ /*0x04, 0x30*/
+ u8 priority;
+ /*0x05*/
+ u8 sampleCount; // 0, 8, 16, 32 or 64
+ /*0x06*/
+ u8 instOrWave;
+ /*0x07*/
+ u8 bankId; // in NoteSubEu on EU
+ /*0x08*/
+ s16 adsrVolScale;
+ /* */
+ u8 pad1[2];
+ /*0x0C, 0xB3*/
+ u16 headsetPanRight;
+ /*0x0E, 0xB4*/
+ u16 headsetPanLeft;
+ /*0x10*/
+ u16 prevHeadsetPanRight;
+ /*0x12*/
+ u16 prevHeadsetPanLeft;
+ /*0x14*/
+ s32 samplePosInt;
+ /*0x18, 0x38*/
+ f32 portamentoFreqScale;
+ /*0x1C, 0x3C*/
+ f32 vibratoFreqScale;
+ /*0x20*/
+ u16 samplePosFrac;
+ /*0x24*/
+ struct AudioBankSound *sound;
+ /*0x28, 0x40*/
+ struct SequenceChannelLayer *prevParentLayer;
+ /*0x2C, 0x44*/
+ struct SequenceChannelLayer *parentLayer;
+ /*0x30, 0x48*/
+ struct SequenceChannelLayer *wantedParentLayer;
+ /*0x34*/
+ struct NoteSynthesisBuffers *synthesisBuffers;
+ /*0x38*/
+ f32 frequency;
+ /*0x3C*/
+ u16 targetVolLeft; // Q1.15, but will always be non-negative
+ /*0x3E*/
+ u16 targetVolRight; // Q1.15, but will always be non-negative
+ /*0x40*/
+ u8 reverbVol; // Q1.7
+ /*0x41*/
+ u8 unused1; // never read, set to 0x3f
+ /*0x44*/
+ struct NoteAttributes attributes;
+ /*0x54, 0x58*/
+ struct AdsrState adsr;
+ /*0x74, 0x7C*/
+ struct Portamento portamento;
+ /*0x84, 0x8C*/
+ struct VibratoState vibratoState;
+ /*0x9C*/
+ s16 curVolLeft; // Q1.15, but will always be non-negative
+ /*0x9E*/
+ s16 curVolRight; // Q1.15, but will always be non-negative
+ /*0xA0*/
+ s16 reverbVolShifted; // Q1.15
+ /*0xA2*/
+ s16 unused2; // never read, set to 0
+ /*0xA4, 0x00*/
+ struct AudioListItem listItem;
+ /* */
+ u8 pad2[0xc];
}; // size = 0xC0
#endif
@@ -726,19 +945,19 @@ struct NoteSynthesisBuffers
{
s16 adpcmdecState[0x10];
s16 finalResampleState[0x10];
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
s16 unk[0x10];
s16 filterBuffer[0x20];
s16 panSamplesBuffer[0x20];
-#else
+ #else
s16 mixEnvelopeState[0x28];
s16 panResampleState[0x10];
s16 panSamplesBuffer[0x20];
s16 dummyResampleState[0x10];
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #if defined(VERSION_JP) || defined(VERSION_US)
s16 samples[0x40];
-#endif
-#endif
+ #endif
+ #endif
};
#ifdef VERSION_EU
@@ -765,99 +984,145 @@ struct ReverbSettingsEU
struct AudioSessionSettingsEU
{
- /* 0x00 */ u32 frequency;
- /* 0x04 */ u8 unk1; // always 1
- /* 0x05 */ u8 maxSimultaneousNotes;
- /* 0x06 */ u8 numReverbs; // always 1
- /* 0x07 */ u8 unk2; // always 0
- /* 0x08 */ struct ReverbSettingsEU *reverbSettings;
- /* 0x0C */ u16 volume;
- /* 0x0E */ u16 unk3; // always 0
- /* 0x10 */ u32 persistentSeqMem;
- /* 0x14 */ u32 persistentBankMem;
-#ifdef VERSION_SH
+ /* 0x00 */
+ u32 frequency;
+ /* 0x04 */
+ u8 unk1; // always 1
+ /* 0x05 */
+ u8 maxSimultaneousNotes;
+ /* 0x06 */
+ u8 numReverbs; // always 1
+ /* 0x07 */
+ u8 unk2; // always 0
+ /* 0x08 */
+ struct ReverbSettingsEU *reverbSettings;
+ /* 0x0C */
+ u16 volume;
+ /* 0x0E */
+ u16 unk3; // always 0
+ /* 0x10 */
+ u32 persistentSeqMem;
+ /* 0x14 */
+ u32 persistentBankMem;
+ #ifdef VERSION_SH
/* 0x18 */ u32 unk18; // always 0
-#endif
- /* 0x18, 0x1C */ u32 temporarySeqMem;
- /* 0x1C, 0x20 */ u32 temporaryBankMem;
-#ifdef VERSION_SH
+ #endif
+ /* 0x18, 0x1C */
+ u32 temporarySeqMem;
+ /* 0x1C, 0x20 */
+ u32 temporaryBankMem;
+ #ifdef VERSION_SH
/* 0x24 */ u32 unk24; // always 0
/* 0x28 */ u32 unkMem28; // always 0
/* 0x2C */ u32 unkMem2C; // always 0
-#endif
+ #endif
}; // 0x30 on shindou
struct AudioSessionSettings
{
- /*0x00*/ u32 frequency;
- /*0x04*/ u8 maxSimultaneousNotes;
- /*0x05*/ u8 reverbDownsampleRate; // always 1
- /*0x06*/ u16 reverbWindowSize;
- /*0x08*/ u16 reverbGain;
- /*0x0A*/ u16 volume;
- /*0x0C*/ u32 persistentSeqMem;
- /*0x10*/ u32 persistentBankMem;
- /*0x14*/ u32 temporarySeqMem;
- /*0x18*/ u32 temporaryBankMem;
+ /*0x00*/
+ u32 frequency;
+ /*0x04*/
+ u8 maxSimultaneousNotes;
+ /*0x05*/
+ u8 reverbDownsampleRate; // always 1
+ /*0x06*/
+ u16 reverbWindowSize;
+ /*0x08*/
+ u16 reverbGain;
+ /*0x0A*/
+ u16 volume;
+ /*0x0C*/
+ u32 persistentSeqMem;
+ /*0x10*/
+ u32 persistentBankMem;
+ /*0x14*/
+ u32 temporarySeqMem;
+ /*0x18*/
+ u32 temporaryBankMem;
}; // size = 0x1C
-struct AudioBufferParametersEU {
- /*0x00*/ s16 presetUnk4; // audio frames per vsync?
- /*0x02*/ u16 frequency;
- /*0x04*/ u16 aiFrequency; // ?16
- /*0x06*/ s16 samplesPerFrameTarget;
- /*0x08*/ s16 maxAiBufferLength;
- /*0x0A*/ s16 minAiBufferLength;
- /*0x0C*/ s16 updatesPerFrame;
- /*0x0E*/ s16 samplesPerUpdate;
- /*0x10*/ s16 samplesPerUpdateMax;
- /*0x12*/ s16 samplesPerUpdateMin;
- /*0x14*/ f32 resampleRate; // contains 32000.0f / frequency
- /*0x18*/ f32 updatesPerFrameInv; // 1.0f / updatesPerFrame
- /*0x1C*/ f32 unkUpdatesPerFrameScaled; // 3.0f / (1280.0f * updatesPerFrame)
+struct AudioBufferParametersEU
+{
+ /*0x00*/
+ s16 presetUnk4; // audio frames per vsync?
+ /*0x02*/
+ u16 frequency;
+ /*0x04*/
+ u16 aiFrequency; // ?16
+ /*0x06*/
+ s16 samplesPerFrameTarget;
+ /*0x08*/
+ s16 maxAiBufferLength;
+ /*0x0A*/
+ s16 minAiBufferLength;
+ /*0x0C*/
+ s16 updatesPerFrame;
+ /*0x0E*/
+ s16 samplesPerUpdate;
+ /*0x10*/
+ s16 samplesPerUpdateMax;
+ /*0x12*/
+ s16 samplesPerUpdateMin;
+ /*0x14*/
+ f32 resampleRate; // contains 32000.0f / frequency
+ /*0x18*/
+ f32 updatesPerFrameInv; // 1.0f / updatesPerFrame
+ /*0x1C*/
+ f32 unkUpdatesPerFrameScaled; // 3.0f / (1280.0f * updatesPerFrame)
};
-struct EuAudioCmd {
- union {
-#if IS_BIG_ENDIAN
- struct {
+struct EuAudioCmd
+{
+ union
+ {
+ #if IS_BIG_ENDIAN
+ struct
+ {
u8 op;
u8 arg1;
u8 arg2;
u8 arg3;
} s;
-#else
- struct {
+ #else
+ struct
+ {
u8 arg3;
u8 arg2;
u8 arg1;
u8 op;
} s;
-#endif
+ #endif
s32 first;
} u;
- union {
+
+ union
+ {
s32 as_s32;
u32 as_u32;
f32 as_f32;
-#if IS_BIG_ENDIAN
+ #if IS_BIG_ENDIAN
u8 as_u8;
s8 as_s8;
-#else
- struct {
+ #else
+ struct
+ {
u8 pad0[3];
u8 as_u8;
};
- struct {
+
+ struct
+ {
u8 pad1[3];
s8 as_s8;
};
-#endif
+ #endif
} u2;
};
#ifdef VERSION_SH
-struct PendingDmaSample {
+struct PendingDmaSample
+{
u8 medium;
u8 bankId;
u8 idx;
@@ -867,13 +1132,18 @@ struct PendingDmaSample {
s32 state;
s32 remaining;
s8 *io;
- /*0x1C*/ struct AudioBankSample sample;
- /*0x2C*/ OSMesgQueue queue;
- /*0x44*/ OSMesg mesgs[1];
- /*0x48*/ OSIoMesg ioMesg;
+ /*0x1C*/
+ struct AudioBankSample sample;
+ /*0x2C*/
+ OSMesgQueue queue;
+ /*0x44*/
+ OSMesg mesgs[1];
+ /*0x48*/
+ OSIoMesg ioMesg;
};
-struct UnkStruct80343D00 {
+struct UnkStruct80343D00
+{
u32 someIndex; // array into one of the two slots below
struct PendingDmaSample arr[2];
};
diff --git a/src/decomp/audio/load.c b/src/decomp/audio/load.c
index ee679f0..1466f79 100644
--- a/src/decomp/audio/load.c
+++ b/src/decomp/audio/load.c
@@ -11,15 +11,23 @@
#define ALIGN16(val) (((val) + 0xF) & ~0xF)
-struct SharedDma {
- /*0x0*/ u8 *buffer; // target, points to pre-allocated buffer
- /*0x4*/ uintptr_t source; // device address
- /*0x8*/ u16 sizeUnused; // set to bufSize, never read
- /*0xA*/ u16 bufSize; // size of buffer
- /*0xC*/ u8 unused2; // set to 0, never read
- /*0xD*/ u8 reuseIndex; // position in sSampleDmaReuseQueue1/2, if ttl == 0
- /*0xE*/ u8 ttl; // duration after which the DMA can be discarded
-}; // size = 0x10
+struct SharedDma
+{
+ /*0x0*/
+ u8 *buffer; // target, points to pre-allocated buffer
+ /*0x4*/
+ uintptr_t source; // device address
+ /*0x8*/
+ u16 sizeUnused; // set to bufSize, never read
+ /*0xA*/
+ u16 bufSize; // size of buffer
+ /*0xC*/
+ u8 unused2; // set to 0, never read
+ /*0xD*/
+ u8 reuseIndex; // position in sSampleDmaReuseQueue1/2, if ttl == 0
+ /*0xE*/
+ u8 ttl; // duration after which the DMA can be discarded
+}; // size = 0x10
// EU only
void port_eu_init(void);
@@ -101,27 +109,28 @@ extern u64 gAudioGlobalsStartMarker;
extern u64 gAudioGlobalsEndMarker;
extern struct seqFile *gSoundDataADSR; // sound_data.ctl
-extern struct seqFile *gSoundDataRaw; // sound_data.tbl
-extern struct seqFile *gMusicData; // sequences.s
-extern u8* gBankSetsData; // bank_sets.s
+extern struct seqFile *gSoundDataRaw; // sound_data.tbl
+extern struct seqFile *gMusicData; // sequences.s
+extern u8 *gBankSetsData; // bank_sets.s
ALSeqFile *get_audio_file_header(s32 arg0);
/**
* Performs an immediate DMA copy
*/
-void audio_dma_copy_immediate(uintptr_t devAddr, void *vAddr, size_t nbytes) {
- DEBUG_PRINT("audio_dma_copy_immediate()");
- DEBUG_PRINT("- dev addr: %x", devAddr);
- DEBUG_PRINT("- vAddr: %x", vAddr);
- DEBUG_PRINT("- # bytes: %d", nbytes);
+void audio_dma_copy_immediate(uintptr_t devAddr, void *vAddr, size_t nbytes)
+{
+ DEBUG_PRINT("audio_dma_copy_immediate()");
+ DEBUG_PRINT("- dev addr: %x", devAddr);
+ DEBUG_PRINT("- vAddr: %x", vAddr);
+ DEBUG_PRINT("- # bytes: %d", nbytes);
eu_stubbed_printf_3("Romcopy %x -> %x ,size %x\n", devAddr, vAddr, nbytes);
- DEBUG_PRINT("- invalidate d cache");
+ DEBUG_PRINT("- invalidate d cache");
osInvalDCache(vAddr, nbytes);
- DEBUG_PRINT("- start dma");
+ DEBUG_PRINT("- start dma");
osPiStartDma(&gAudioDmaIoMesg, OS_MESG_PRI_HIGH, OS_READ, devAddr, vAddr, nbytes,
&gAudioDmaMesgQueue);
- DEBUG_PRINT("- recv message");
+ DEBUG_PRINT("- recv message");
osRecvMesg(&gAudioDmaMesgQueue, NULL, OS_MESG_BLOCK);
eu_stubbed_printf_0("Romcopyend\n");
}
@@ -148,7 +157,8 @@ u8 audioString49[] = "BANK LOAD MISS! FOR %d\n";
/**
* Performs an asynchronus (normal priority) DMA copy
*/
-void audio_dma_copy_async(uintptr_t devAddr, void *vAddr, size_t nbytes, OSMesgQueue *queue, OSIoMesg *mesg) {
+void audio_dma_copy_async(uintptr_t devAddr, void *vAddr, size_t nbytes, OSMesgQueue *queue, OSIoMesg *mesg)
+{
osInvalDCache(vAddr, nbytes);
osPiStartDma(mesg, OS_MESG_PRI_NORMAL, OS_READ, devAddr, vAddr, nbytes, queue);
}
@@ -157,12 +167,13 @@ void audio_dma_copy_async(uintptr_t devAddr, void *vAddr, size_t nbytes, OSMesgQ
* Performs a partial asynchronous (normal priority) DMA copy. This is limited
* to 0x1000 bytes transfer at once.
*/
-void audio_dma_partial_copy_async(uintptr_t *devAddr, u8 **vAddr, ssize_t *remaining, OSMesgQueue *queue, OSIoMesg *mesg) {
-#if defined(VERSION_EU)
+void audio_dma_partial_copy_async(uintptr_t *devAddr, u8 **vAddr, ssize_t *remaining, OSMesgQueue *queue, OSIoMesg *mesg)
+{
+ #if defined(VERSION_EU)
ssize_t transfer = (*remaining >= 0x1000 ? 0x1000 : *remaining);
-#else
- ssize_t transfer = (*remaining < 0x1000 ? *remaining : 0x1000);
-#endif
+ #else
+ ssize_t transfer = *remaining < 0x1000 ? *remaining : 0x1000;
+ #endif
*remaining -= transfer;
osInvalDCache(*vAddr, transfer);
osPiStartDma(mesg, OS_MESG_PRI_NORMAL, OS_READ, *devAddr, *vAddr, transfer, queue);
@@ -170,35 +181,42 @@ void audio_dma_partial_copy_async(uintptr_t *devAddr, u8 **vAddr, ssize_t *remai
*vAddr += transfer;
}
-void decrease_sample_dma_ttls() {
+void decrease_sample_dma_ttls()
+{
u32 i;
- for (i = 0; i < sSampleDmaListSize1; i++) {
-#if defined(VERSION_EU)
+ for (i = 0; i < sSampleDmaListSize1; i++)
+ {
+ #if defined(VERSION_EU)
struct SharedDma *temp = &sSampleDmas[i];
-#else
+ #else
struct SharedDma *temp = sSampleDmas + i;
-#endif
- if (temp->ttl != 0) {
+ #endif
+ if (temp->ttl != 0)
+ {
temp->ttl--;
- if (temp->ttl == 0) {
+ if (temp->ttl == 0)
+ {
temp->reuseIndex = sSampleDmaReuseQueueHead1;
- sSampleDmaReuseQueue1[sSampleDmaReuseQueueHead1++] = (u8) i;
+ sSampleDmaReuseQueue1[sSampleDmaReuseQueueHead1++] = (u8)i;
}
}
}
- for (i = sSampleDmaListSize1; i < gSampleDmaNumListItems; i++) {
-#if defined(VERSION_EU)
+ for (i = sSampleDmaListSize1; i < gSampleDmaNumListItems; i++)
+ {
+ #if defined(VERSION_EU)
struct SharedDma *temp = &sSampleDmas[i];
-#else
+ #else
struct SharedDma *temp = sSampleDmas + i;
-#endif
- if (temp->ttl != 0) {
+ #endif
+ if (temp->ttl != 0)
+ {
temp->ttl--;
- if (temp->ttl == 0) {
+ if (temp->ttl == 0)
+ {
temp->reuseIndex = sSampleDmaReuseQueueHead2;
- sSampleDmaReuseQueue2[sSampleDmaReuseQueueHead2++] = (u8) i;
+ sSampleDmaReuseQueue2[sSampleDmaReuseQueueHead2++] = (u8)i;
}
}
}
@@ -206,7 +224,8 @@ void decrease_sample_dma_ttls() {
sUnused80226B40 = 0;
}
-void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef) {
+void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef)
+{
s32 hasDma = FALSE;
struct SharedDma *dma;
uintptr_t dmaDevAddr;
@@ -216,38 +235,44 @@ void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef) {
ssize_t bufferPos;
UNUSED u32 pad;
- if (arg2 != 0 || *dmaIndexRef >= sSampleDmaListSize1) {
- for (i = sSampleDmaListSize1; i < gSampleDmaNumListItems; i++) {
-#if defined(VERSION_EU)
+ if (arg2 != 0 || *dmaIndexRef >= sSampleDmaListSize1)
+ {
+ for (i = sSampleDmaListSize1; i < gSampleDmaNumListItems; i++)
+ {
+ #if defined(VERSION_EU)
dma = &sSampleDmas[i];
-#else
+ #else
dma = sSampleDmas + i;
-#endif
+ #endif
bufferPos = devAddr - dma->source;
- if (0 <= bufferPos && (size_t) bufferPos <= dma->bufSize - size) {
+ if (0 <= bufferPos && (size_t)bufferPos <= dma->bufSize - size)
+ {
// We already have a DMA request for this memory range.
- if (dma->ttl == 0 && sSampleDmaReuseQueueTail2 != sSampleDmaReuseQueueHead2) {
+ if (dma->ttl == 0 && sSampleDmaReuseQueueTail2 != sSampleDmaReuseQueueHead2)
+ {
// Move the DMA out of the reuse queue, by swapping it with the
// tail, and then incrementing the tail.
- if (dma->reuseIndex != sSampleDmaReuseQueueTail2) {
+ if (dma->reuseIndex != sSampleDmaReuseQueueTail2)
+ {
sSampleDmaReuseQueue2[dma->reuseIndex] =
- sSampleDmaReuseQueue2[sSampleDmaReuseQueueTail2];
+ sSampleDmaReuseQueue2[sSampleDmaReuseQueueTail2];
sSampleDmas[sSampleDmaReuseQueue2[sSampleDmaReuseQueueTail2]].reuseIndex =
- dma->reuseIndex;
+ dma->reuseIndex;
}
sSampleDmaReuseQueueTail2++;
}
dma->ttl = 60;
- *dmaIndexRef = (u8) i;
-#if defined(VERSION_EU)
+ *dmaIndexRef = (u8)i;
+ #if defined(VERSION_EU)
return &dma->buffer[(devAddr - dma->source)];
-#else
- return (devAddr - dma->source) + dma->buffer;
-#endif
+ #else
+ return devAddr - dma->source + dma->buffer;
+ #endif
}
}
- if (sSampleDmaReuseQueueTail2 != sSampleDmaReuseQueueHead2 && arg2 != 0) {
+ if (sSampleDmaReuseQueueTail2 != sSampleDmaReuseQueueHead2 && arg2 != 0)
+ {
// Allocate a DMA from reuse queue 2. This queue can be empty, since
// TTL 60 is pretty large.
dmaIndex = sSampleDmaReuseQueue2[sSampleDmaReuseQueueTail2];
@@ -255,41 +280,48 @@ void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef) {
dma = sSampleDmas + dmaIndex;
hasDma = TRUE;
}
- } else {
-#if defined(VERSION_EU)
+ }
+ else
+ {
+ #if defined(VERSION_EU)
dma = sSampleDmas;
dma += *dmaIndexRef;
-#else
+ #else
dma = sSampleDmas + *dmaIndexRef;
-#endif
+ #endif
bufferPos = devAddr - dma->source;
- if (0 <= bufferPos && (size_t) bufferPos <= dma->bufSize - size) {
+ if (0 <= bufferPos && (size_t)bufferPos <= dma->bufSize - size)
+ {
// We already have DMA for this memory range.
- if (dma->ttl == 0) {
+ if (dma->ttl == 0)
+ {
// Move the DMA out of the reuse queue, by swapping it with the
// tail, and then incrementing the tail.
- if (dma->reuseIndex != sSampleDmaReuseQueueTail1) {
-#if defined(VERSION_EU)
- if (1) {
+ if (dma->reuseIndex != sSampleDmaReuseQueueTail1)
+ {
+ #if defined(VERSION_EU)
+ if (1)
+ {
}
-#endif
+ #endif
sSampleDmaReuseQueue1[dma->reuseIndex] =
- sSampleDmaReuseQueue1[sSampleDmaReuseQueueTail1];
+ sSampleDmaReuseQueue1[sSampleDmaReuseQueueTail1];
sSampleDmas[sSampleDmaReuseQueue1[sSampleDmaReuseQueueTail1]].reuseIndex =
- dma->reuseIndex;
+ dma->reuseIndex;
}
sSampleDmaReuseQueueTail1++;
}
dma->ttl = 2;
-#if defined(VERSION_EU)
+ #if defined(VERSION_EU)
return dma->buffer + (devAddr - dma->source);
-#else
- return (devAddr - dma->source) + dma->buffer;
-#endif
+ #else
+ return devAddr - dma->source + dma->buffer;
+ #endif
}
}
- if (!hasDma) {
+ if (!hasDma)
+ {
// Allocate a DMA from reuse queue 1. This queue will hopefully never
// be empty, since TTL 2 is so small.
dmaIndex = sSampleDmaReuseQueue1[sSampleDmaReuseQueueTail1++];
@@ -302,51 +334,53 @@ void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef) {
dma->ttl = 2;
dma->source = dmaDevAddr;
dma->sizeUnused = transfer;
-#ifdef VERSION_US
+ #ifdef VERSION_US
osInvalDCache(dma->buffer, transfer);
-#endif
-#if defined(VERSION_EU)
+ #endif
+ #if defined(VERSION_EU)
osPiStartDma(&gCurrAudioFrameDmaIoMesgBufs[gCurrAudioFrameDmaCount++], OS_MESG_PRI_NORMAL,
- OS_READ, dmaDevAddr, dma->buffer, transfer, &gCurrAudioFrameDmaQueue);
+ OS_READ, dmaDevAddr, dma->buffer, transfer, &gCurrAudioFrameDmaQueue);
*dmaIndexRef = dmaIndex;
return (devAddr - dmaDevAddr) + dma->buffer;
-#else
+ #else
gCurrAudioFrameDmaCount++;
osPiStartDma(&gCurrAudioFrameDmaIoMesgBufs[gCurrAudioFrameDmaCount - 1], OS_MESG_PRI_NORMAL,
OS_READ, dmaDevAddr, dma->buffer, transfer, &gCurrAudioFrameDmaQueue);
*dmaIndexRef = dmaIndex;
return dma->buffer + (devAddr - dmaDevAddr);
-#endif
+ #endif
}
-void init_sample_dma_buffers(UNUSED s32 arg0) {
+void init_sample_dma_buffers(UNUSED s32 arg0)
+{
s32 i;
-#if defined(VERSION_EU)
-#define j i
-#else
+ #if defined(VERSION_EU)
+ #define j i
+ #else
s32 j;
-#endif
+ #endif
-#if defined(VERSION_EU)
+ #if defined(VERSION_EU)
sDmaBufSize = 0x400;
-#else
+ #else
sDmaBufSize = 144 * 9;
-#endif
+ #endif
-#if defined(VERSION_EU)
+ #if defined(VERSION_EU)
for (i = 0; i < gMaxSimultaneousNotes * 3 * gAudioBufferParameters.presetUnk4; i++)
-#else
+ #else
for (i = 0; i < gMaxSimultaneousNotes * 3; i++)
-#endif
+ #endif
{
sSampleDmas[gSampleDmaNumListItems].buffer = soundAlloc(&gNotesAndBuffersPool, sDmaBufSize);
- if (sSampleDmas[gSampleDmaNumListItems].buffer == NULL) {
-#if defined(VERSION_EU)
+ if (sSampleDmas[gSampleDmaNumListItems].buffer == NULL)
+ {
+ #if defined(VERSION_EU)
break;
-#else
+ #else
goto out1;
-#endif
+ #endif
}
sSampleDmas[gSampleDmaNumListItems].bufSize = sDmaBufSize;
sSampleDmas[gSampleDmaNumListItems].source = 0;
@@ -355,36 +389,40 @@ void init_sample_dma_buffers(UNUSED s32 arg0) {
sSampleDmas[gSampleDmaNumListItems].ttl = 0;
gSampleDmaNumListItems++;
}
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #if defined(VERSION_JP) || defined(VERSION_US)
out1:
-#endif
+ #endif
- for (i = 0; (u32) i < gSampleDmaNumListItems; i++) {
- sSampleDmaReuseQueue1[i] = (u8) i;
- sSampleDmas[i].reuseIndex = (u8) i;
+ for (i = 0; (u32)i < gSampleDmaNumListItems; i++)
+ {
+ sSampleDmaReuseQueue1[i] = (u8)i;
+ sSampleDmas[i].reuseIndex = (u8)i;
}
- for (j = gSampleDmaNumListItems; j < 0x100; j++) {
+ for (j = gSampleDmaNumListItems; j < 0x100; j++)
+ {
sSampleDmaReuseQueue1[j] = 0;
}
sSampleDmaReuseQueueTail1 = 0;
- sSampleDmaReuseQueueHead1 = (u8) gSampleDmaNumListItems;
+ sSampleDmaReuseQueueHead1 = (u8)gSampleDmaNumListItems;
sSampleDmaListSize1 = gSampleDmaNumListItems;
-#if defined(VERSION_EU)
+ #if defined(VERSION_EU)
sDmaBufSize = 0x200;
-#else
+ #else
sDmaBufSize = 160 * 9;
-#endif
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
+ #endif
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
sSampleDmas[gSampleDmaNumListItems].buffer = soundAlloc(&gNotesAndBuffersPool, sDmaBufSize);
- if (sSampleDmas[gSampleDmaNumListItems].buffer == NULL) {
-#if defined(VERSION_EU)
+ if (sSampleDmas[gSampleDmaNumListItems].buffer == NULL)
+ {
+ #if defined(VERSION_EU)
break;
-#else
+ #else
goto out2;
-#endif
+ #endif
}
sSampleDmas[gSampleDmaNumListItems].bufSize = sDmaBufSize;
sSampleDmas[gSampleDmaNumListItems].source = 0;
@@ -393,66 +431,75 @@ out1:
sSampleDmas[gSampleDmaNumListItems].ttl = 0;
gSampleDmaNumListItems++;
}
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #if defined(VERSION_JP) || defined(VERSION_US)
out2:
-#endif
+ #endif
- for (i = sSampleDmaListSize1; (u32) i < gSampleDmaNumListItems; i++) {
- sSampleDmaReuseQueue2[i - sSampleDmaListSize1] = (u8) i;
+ for (i = sSampleDmaListSize1; (u32)i < gSampleDmaNumListItems; i++)
+ {
+ sSampleDmaReuseQueue2[i - sSampleDmaListSize1] = (u8)i;
sSampleDmas[i].reuseIndex = (u8)(i - sSampleDmaListSize1);
}
// This probably meant to touch the range size1..size2 as well... but it
// doesn't matter, since these values are never read anyway.
- for (j = gSampleDmaNumListItems; j < 0x100; j++) {
+ for (j = gSampleDmaNumListItems; j < 0x100; j++)
+ {
sSampleDmaReuseQueue2[j] = sSampleDmaListSize1;
}
sSampleDmaReuseQueueTail2 = 0;
sSampleDmaReuseQueueHead2 = gSampleDmaNumListItems - sSampleDmaListSize1;
-#if defined(VERSION_EU)
-#undef j
-#endif
+ #if defined(VERSION_EU)
+ #undef j
+ #endif
}
#if defined(VERSION_JP) || defined(VERSION_US)
// This function gets optimized out on US due to being static and never called
UNUSED static
#endif
-void patch_sound(UNUSED struct AudioBankSound *sound, UNUSED u8 *memBase, UNUSED u8 *offsetBase) {
+void patch_sound(UNUSED struct AudioBankSound *sound, UNUSED u8 *memBase, UNUSED u8 *offsetBase)
+{
struct AudioBankSample *sample;
void *patched;
UNUSED u8 *mem; // unused on US
-#define PATCH(x, base) (patched = (void *)((uintptr_t) (x) + (uintptr_t) base))
+ #define PATCH(x, base) (patched = (void *)((uintptr_t) (x) + (uintptr_t) base))
- if (sound->sample != NULL) {
+ if (sound->sample != NULL)
+ {
sample = sound->sample = PATCH(sound->sample, memBase);
- if (sample->loaded == 0) {
+ if (sample->loaded == 0)
+ {
sample->sampleAddr = PATCH(sample->sampleAddr, offsetBase);
sample->loop = PATCH(sample->loop, memBase);
sample->book = PATCH(sample->book, memBase);
sample->loaded = 1;
}
-#if defined(VERSION_EU)
- else if (sample->loaded == 0x80) {
+ #if defined(VERSION_EU)
+ else if (sample->loaded == 0x80)
+ {
PATCH(sample->sampleAddr, offsetBase);
mem = soundAlloc(&gNotesAndBuffersPool, sample->sampleSize);
- if (mem == NULL) {
+ if (mem == NULL)
+ {
sample->sampleAddr = patched;
sample->loaded = 1;
- } else {
- audio_dma_copy_immediate((uintptr_t) patched, mem, sample->sampleSize);
+ }
+ else
+ {
+ audio_dma_copy_immediate((uintptr_t)patched, mem, sample->sampleSize);
sample->loaded = 0x81;
sample->sampleAddr = mem;
}
sample->loop = PATCH(sample->loop, memBase);
sample->book = PATCH(sample->book, memBase);
}
-#endif
+ #endif
}
-#undef PATCH
+ #undef PATCH
}
#ifdef VERSION_EU
@@ -484,7 +531,8 @@ void patch_sound(UNUSED struct AudioBankSound *sound, UNUSED u8 *memBase, UNUSED
#endif
// on US/JP this inlines patch_sound, using some -sopt compiler flag
-void patch_audio_bank(struct AudioBank *mem, u8 *offset, u32 numInstruments, u32 numDrums) {
+void patch_audio_bank(struct AudioBank *mem, u8 *offset, u32 numInstruments, u32 numDrums)
+{
struct Instrument *instrument;
struct Instrument **itInstrs;
struct Instrument **end;
@@ -493,75 +541,88 @@ void patch_audio_bank(struct AudioBank *mem, u8 *offset, u32 numInstruments, u32
void *patched;
struct Drum *drum;
struct Drum **drums;
-#if defined(VERSION_EU)
+ #if defined(VERSION_EU)
u32 numDrums2;
-#endif
+ #endif
-#define BASE_OFFSET_REAL(x, base) (void *)((uintptr_t) (x) + (uintptr_t) base)
-#define PATCH(x, base) (patched = BASE_OFFSET_REAL(x, base))
-#define PATCH_MEM(x) x = PATCH(x, mem)
+ #define BASE_OFFSET_REAL(x, base) (void *)((uintptr_t) (x) + (uintptr_t) base)
+ #define PATCH(x, base) (patched = BASE_OFFSET_REAL(x, base))
+ #define PATCH_MEM(x) x = PATCH(x, mem)
-#if defined(VERSION_JP) || defined(VERSION_US)
-#define BASE_OFFSET(x, base) BASE_OFFSET_REAL(x, base)
-#else
-#define BASE_OFFSET(x, base) BASE_OFFSET_REAL(base, x)
-#endif
+ #if defined(VERSION_JP) || defined(VERSION_US)
+ #define BASE_OFFSET(x, base) BASE_OFFSET_REAL(x, base)
+ #else
+ #define BASE_OFFSET(x, base) BASE_OFFSET_REAL(base, x)
+ #endif
drums = mem->drums;
-#if defined(VERSION_JP) || defined(VERSION_US)
- if (drums != NULL && numDrums > 0) {
- mem->drums = (void *)((uintptr_t) drums + (uintptr_t) mem);
+ #if defined(VERSION_JP) || defined(VERSION_US)
+ if (drums != NULL && numDrums > 0)
+ {
+ mem->drums = (void *)((uintptr_t)drums + (uintptr_t)mem);
if (numDrums > 0) //! unneeded when -sopt is enabled
- for (i = 0; i < numDrums; i++) {
-#else
- numDrums2 = numDrums;
- if (drums != NULL && numDrums2 > 0) {
- mem->drums = PATCH(drums, mem);
- for (i = 0; i < numDrums2; i++) {
-#endif
- patched = mem->drums[i];
- if (patched != NULL) {
- drum = PATCH(patched, mem);
- mem->drums[i] = drum;
- if (drum->loaded == 0) {
-#if defined(VERSION_JP) || defined(VERSION_US)
- //! copt replaces drum with 'patched' for these two lines
- PATCH_SOUND(&(*(struct Drum *)patched).sound, mem, offset);
- patched = (*(struct Drum *)patched).envelope;
-#else
- patch_sound(&drum->sound, (u8 *) mem, offset);
- patched = drum->envelope;
-#endif
- drum->envelope = BASE_OFFSET(mem, patched);
- drum->loaded = 1;
- }
+ for (i = 0; i < numDrums; i++)
+ {
+ #else
+ numDrums2 = numDrums;
+ if (drums != NULL && numDrums2 > 0)
+ {
+ mem->drums = PATCH(drums, mem);
+ for (i = 0; i < numDrums2; i++)
+ {
+
+ #endif
+ patched = mem->drums[i];
+ if (patched != NULL)
+ {
+ drum = PATCH(patched, mem);
+ mem->drums[i] = drum;
+ if (drum->loaded == 0)
+ {
+ #if defined(VERSION_JP) || defined(VERSION_US)
+ //! copt replaces drum with 'patched' for these two lines
+ PATCH_SOUND(&(*(struct Drum *)patched).sound, mem, offset);
+ patched = (*(struct Drum *)patched).envelope;
+ #else
+ patch_sound(&drum->sound, (u8 *)mem, offset);
+ patched = drum->envelope;
+ #endif
+ drum->envelope = BASE_OFFSET(mem, patched);
+ drum->loaded = 1;
+ }
+ }
}
- }
}
//! Doesn't affect EU, but required for US/JP
temp = &*mem;
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #if defined(VERSION_JP) || defined(VERSION_US)
if (numInstruments >= 1)
-#endif
- if (numInstruments > 0) {
- //! Doesn't affect EU, but required for US/JP
- struct Instrument **tempInst;
- itInstrs = temp->instruments;
- tempInst = temp->instruments;
- end = numInstruments + tempInst;
+ #endif
+ if (numInstruments > 0)
+ {
+ //! Doesn't affect EU, but required for US/JP
+ struct Instrument **tempInst;
+ itInstrs = temp->instruments;
+ tempInst = temp->instruments;
+ end = numInstruments + tempInst;
-#if defined(VERSION_JP) || defined(VERSION_US)
-l2:
-#else
- do {
-#endif
- if (*itInstrs != NULL) {
+ #if defined(VERSION_JP) || defined(VERSION_US)
+ l2:
+ #else
+ do
+ {
+
+
+ #endif
+ if (*itInstrs != NULL)
+ {
*itInstrs = BASE_OFFSET(*itInstrs, mem);
instrument = *itInstrs;
- if (instrument->loaded == 0) {
+ if (instrument->loaded == 0)
+ {
PATCH_SOUND(&instrument->lowNotesSound, (u8 *) mem, offset);
PATCH_SOUND(&instrument->normalNotesSound, (u8 *) mem, offset);
PATCH_SOUND(&instrument->highNotesSound, (u8 *) mem, offset);
@@ -571,68 +632,73 @@ l2:
}
}
itInstrs++;
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #if defined(VERSION_JP) || defined(VERSION_US)
//! goto generated by copt, required to match US/JP
- if (end != itInstrs) {
+ if (end != itInstrs)
+ {
goto l2;
}
-#else
- } while (end != itInstrs);
-#endif
- }
-#undef PATCH_MEM
-#undef PATCH
-#undef BASE_OFFSET_REAL
-#undef BASE_OFFSET
-#undef PATCH_SOUND
+ #else
+ }
+ while (end != itInstrs);
+ #endif
+ }
+ #undef PATCH_MEM
+ #undef PATCH
+ #undef BASE_OFFSET_REAL
+ #undef BASE_OFFSET
+ #undef PATCH_SOUND
}
-struct AudioBank *bank_load_immediate(s32 bankId, s32 arg1) {
- DEBUG_PRINT("bank_load_immediate()");
-
+struct AudioBank *bank_load_immediate(s32 bankId, s32 arg1)
+{
+ DEBUG_PRINT("bank_load_immediate()");
+
UNUSED u32 pad1[4];
u32 buf[4];
u32 numInstruments, numDrums;
struct AudioBank *ret;
u8 *ctlData;
s32 alloc;
-
+
// (This is broken if the length is 1 (mod 16), but that never happens --
// it's always divisible by 4.)
- DEBUG_PRINT("- getting alloc");
+ DEBUG_PRINT("- getting alloc");
alloc = gAlCtlHeader->seqArray[bankId].len + 0xf;
- DEBUG_PRINT("- aligning");
+ DEBUG_PRINT("- aligning");
alloc = ALIGN16(alloc);
alloc -= 0x10;
- DEBUG_PRINT("- getting ctl data for bank %d", bankId);
+ DEBUG_PRINT("- getting ctl data for bank %d", bankId);
ctlData = gAlCtlHeader->seqArray[bankId].offset;
- DEBUG_PRINT("- alloc bank or seq");
+ DEBUG_PRINT("- alloc bank or seq");
ret = alloc_bank_or_seq(&gBankLoadedPool, 1, alloc, arg1, bankId);
- if (ret == NULL) {
+ if (ret == NULL)
+ {
return NULL;
}
-
- DEBUG_PRINT("- copying dma immediate 1");
- DEBUG_PRINT("- ctlData: %x", ctlData);
- audio_dma_copy_immediate((uintptr_t) ctlData, buf, 0x10);
- DEBUG_PRINT("- getting nums");
+
+ DEBUG_PRINT("- copying dma immediate 1");
+ DEBUG_PRINT("- ctlData: %x", ctlData);
+ audio_dma_copy_immediate((uintptr_t)ctlData, buf, 0x10);
+ DEBUG_PRINT("- getting nums");
numInstruments = buf[0];
numDrums = buf[1];
- DEBUG_PRINT("- copying dma immediate 2");
+ DEBUG_PRINT("- copying dma immediate 2");
audio_dma_copy_immediate((uintptr_t)(ctlData + 0x10), ret, alloc);
- DEBUG_PRINT("- patching bank");
+ DEBUG_PRINT("- patching bank");
patch_audio_bank(ret, gAlTbl->seqArray[bankId].offset, numInstruments, numDrums);
- DEBUG_PRINT("- setting ctl entries");
- gCtlEntries[bankId].numInstruments = (u8) numInstruments;
- gCtlEntries[bankId].numDrums = (u8) numDrums;
+ DEBUG_PRINT("- setting ctl entries");
+ gCtlEntries[bankId].numInstruments = (u8)numInstruments;
+ gCtlEntries[bankId].numDrums = (u8)numDrums;
gCtlEntries[bankId].instruments = ret->instruments;
gCtlEntries[bankId].drums = ret->drums;
- DEBUG_PRINT("- setting load status");
+ DEBUG_PRINT("- setting load status");
gBankLoadStatus[bankId] = SOUND_LOAD_STATUS_COMPLETE;
return ret;
}
-struct AudioBank *bank_load_async(s32 bankId, s32 arg1, struct SequencePlayer *seqPlayer) {
+struct AudioBank *bank_load_async(s32 bankId, s32 arg1, struct SequencePlayer *seqPlayer)
+{
u32 numInstruments, numDrums;
UNUSED u32 pad1[2];
u32 buf[4];
@@ -641,45 +707,47 @@ struct AudioBank *bank_load_async(s32 bankId, s32 arg1, struct SequencePlayer *s
struct AudioBank *ret;
u8 *ctlData;
OSMesgQueue *mesgQueue;
-#if defined(VERSION_EU)
+ #if defined(VERSION_EU)
UNUSED u32 pad3;
-#endif
+ #endif
alloc = gAlCtlHeader->seqArray[bankId].len + 0xf;
alloc = ALIGN16(alloc);
alloc -= 0x10;
ctlData = gAlCtlHeader->seqArray[bankId].offset;
ret = alloc_bank_or_seq(&gBankLoadedPool, 1, alloc, arg1, bankId);
- if (ret == NULL) {
+ if (ret == NULL)
+ {
return NULL;
}
-
- audio_dma_copy_immediate((uintptr_t) ctlData, buf, 0x10);
+
+ audio_dma_copy_immediate((uintptr_t)ctlData, buf, 0x10);
numInstruments = buf[0];
numDrums = buf[1];
- seqPlayer->loadingBankId = (u8) bankId;
-#if defined(VERSION_EU)
+ seqPlayer->loadingBankId = (u8)bankId;
+ #if defined(VERSION_EU)
gCtlEntries[bankId].numInstruments = numInstruments;
gCtlEntries[bankId].numDrums = numDrums;
gCtlEntries[bankId].instruments = ret->instruments;
gCtlEntries[bankId].drums = 0;
- seqPlayer->bankDmaCurrMemAddr = (u8 *) ret;
+ seqPlayer->bankDmaCurrMemAddr = (u8 *)ret;
seqPlayer->bankDmaCurrDevAddr = (uintptr_t)(ctlData + 0x10);
seqPlayer->bankDmaRemaining = alloc;
- if (1) {
+ if (1)
+ {
}
-#else
+ #else
seqPlayer->loadingBankNumInstruments = numInstruments;
seqPlayer->loadingBankNumDrums = numDrums;
- seqPlayer->bankDmaCurrMemAddr = (u8 *) ret;
+ seqPlayer->bankDmaCurrMemAddr = (u8 *)ret;
seqPlayer->loadingBank = ret;
seqPlayer->bankDmaCurrDevAddr = (uintptr_t)(ctlData + 0x10);
seqPlayer->bankDmaRemaining = alloc;
-#endif
+ #endif
mesgQueue = &seqPlayer->bankDmaMesgQueue;
osCreateMesgQueue(mesgQueue, &seqPlayer->bankDmaMesg, 1);
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #if defined(VERSION_JP) || defined(VERSION_US)
seqPlayer->bankDmaMesg = NULL;
-#endif
+ #endif
seqPlayer->bankDmaInProgress = TRUE;
audio_dma_partial_copy_async(&seqPlayer->bankDmaCurrDevAddr, &seqPlayer->bankDmaCurrMemAddr,
&seqPlayer->bankDmaRemaining, mesgQueue, &seqPlayer->bankDmaIoMesg);
@@ -687,62 +755,71 @@ struct AudioBank *bank_load_async(s32 bankId, s32 arg1, struct SequencePlayer *s
return ret;
}
-void *sequence_dma_immediate(s32 seqId, s32 arg1) {
+void *sequence_dma_immediate(s32 seqId, s32 arg1)
+{
s32 seqLength;
void *ptr;
u8 *seqData;
-
+
seqLength = gSeqFileHeader->seqArray[seqId].len + 0xf;
seqLength = ALIGN16(seqLength);
seqData = gSeqFileHeader->seqArray[seqId].offset;
ptr = alloc_bank_or_seq(&gSeqLoadedPool, 1, seqLength, arg1, seqId);
- if (ptr == NULL) {
+ if (ptr == NULL)
+ {
return NULL;
}
- audio_dma_copy_immediate((uintptr_t) seqData, ptr, seqLength);
+ audio_dma_copy_immediate((uintptr_t)seqData, ptr, seqLength);
gSeqLoadStatus[seqId] = SOUND_LOAD_STATUS_COMPLETE;
return ptr;
}
-void *sequence_dma_async(s32 seqId, s32 arg1, struct SequencePlayer *seqPlayer) {
+void *sequence_dma_async(s32 seqId, s32 arg1, struct SequencePlayer *seqPlayer)
+{
s32 seqLength;
void *ptr;
u8 *seqData;
OSMesgQueue *mesgQueue;
-
+
eu_stubbed_printf_1("Seq %d Loading Start\n", seqId);
seqLength = gSeqFileHeader->seqArray[seqId].len + 0xf;
seqLength = ALIGN16(seqLength);
seqData = gSeqFileHeader->seqArray[seqId].offset;
ptr = alloc_bank_or_seq(&gSeqLoadedPool, 1, seqLength, arg1, seqId);
- if (ptr == NULL) {
+ if (ptr == NULL)
+ {
eu_stubbed_printf_0("Heap Overflow Error\n");
return NULL;
}
- if (seqLength <= 0x40) {
+ if (seqLength <= 0x40)
+ {
// Immediately load short sequenece
- audio_dma_copy_immediate((uintptr_t) seqData, ptr, seqLength);
- if (1) {
+ audio_dma_copy_immediate((uintptr_t)seqData, ptr, seqLength);
+ if (1)
+ {
}
gSeqLoadStatus[seqId] = SOUND_LOAD_STATUS_COMPLETE;
- } else {
- audio_dma_copy_immediate((uintptr_t) seqData, ptr, 0x40);
+ }
+ else
+ {
+ audio_dma_copy_immediate((uintptr_t)seqData, ptr, 0x40);
mesgQueue = &seqPlayer->seqDmaMesgQueue;
osCreateMesgQueue(mesgQueue, &seqPlayer->seqDmaMesg, 1);
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #if defined(VERSION_JP) || defined(VERSION_US)
seqPlayer->seqDmaMesg = NULL;
-#endif
+ #endif
seqPlayer->seqDmaInProgress = TRUE;
- audio_dma_copy_async((uintptr_t)(seqData + 0x40), (u8 *) ptr + 0x40, seqLength - 0x40, mesgQueue,
+ audio_dma_copy_async((uintptr_t)(seqData + 0x40), (u8 *)ptr + 0x40, seqLength - 0x40, mesgQueue,
&seqPlayer->seqDmaIoMesg);
gSeqLoadStatus[seqId] = SOUND_LOAD_STATUS_IN_PROGRESS;
}
return ptr;
}
-u8 get_missing_bank(u32 seqId, s32 *nonNullCount, s32 *nullCount) {
+u8 get_missing_bank(u32 seqId, s32 *nonNullCount, s32 *nullCount)
+{
void *temp;
u32 bankId;
u16 offset;
@@ -751,31 +828,39 @@ u8 get_missing_bank(u32 seqId, s32 *nonNullCount, s32 *nullCount) {
*nullCount = 0;
*nonNullCount = 0;
-#if defined(VERSION_EU)
- offset = ((u16 *) gAlBankSets)[seqId];
- for (i = gAlBankSets[offset++], ret = 0; i != 0; i--) {
+ #if defined(VERSION_EU)
+ offset = ((u16 *)gAlBankSets)[seqId];
+ for (i = gAlBankSets[offset++], ret = 0; i != 0; i--)
+ {
bankId = gAlBankSets[offset++];
-#else
- offset = ((u16 *) gAlBankSets)[seqId] + 1;
- for (i = gAlBankSets[offset - 1], ret = 0; i != 0; i--) {
+ #else
+ offset = ((u16 *)gAlBankSets)[seqId] + 1;
+ for (i = gAlBankSets[offset - 1], ret = 0; i != 0; i--)
+ {
offset++;
bankId = gAlBankSets[offset - 1];
-#endif
+ #endif
- if (IS_BANK_LOAD_COMPLETE(bankId) == TRUE) {
-#if defined(VERSION_EU)
+ if (IS_BANK_LOAD_COMPLETE(bankId) == TRUE)
+ {
+ #if defined(VERSION_EU)
temp = get_bank_or_seq(&gBankLoadedPool, 2, bankId);
-#else
+ #else
temp = get_bank_or_seq(&gBankLoadedPool, 2, gAlBankSets[offset - 1]);
-#endif
- } else {
+ #endif
+ }
+ else
+ {
temp = NULL;
}
- if (temp == NULL) {
+ if (temp == NULL)
+ {
(*nullCount)++;
ret = bankId;
- } else {
+ }
+ else
+ {
(*nonNullCount)++;
}
}
@@ -783,41 +868,48 @@ u8 get_missing_bank(u32 seqId, s32 *nonNullCount, s32 *nullCount) {
return ret;
}
-struct AudioBank *load_banks_immediate(s32 seqId, u8 *outDefaultBank) {
- DEBUG_PRINT("load_banks_immediate()");
+struct AudioBank *load_banks_immediate(s32 seqId, u8 *outDefaultBank)
+{
+ DEBUG_PRINT("load_banks_immediate()");
void *ret;
u32 bankId;
u16 offset;
u8 i;
- DEBUG_PRINT("- getting offset");
- offset = ((u16 *) gAlBankSets)[seqId];
-#ifdef VERSION_EU
- for (i = gAlBankSets[offset++]; i != 0; i--) {
+ DEBUG_PRINT("- getting offset");
+ offset = ((u16 *)gAlBankSets)[seqId];
+ #ifdef VERSION_EU
+ for (i = gAlBankSets[offset++]; i != 0; i--)
+ {
bankId = gAlBankSets[offset++];
-#else
+ #else
offset++;
- DEBUG_PRINT("- looping through bank sets");
- for (i = gAlBankSets[offset - 1]; i != 0; i--) {
+ DEBUG_PRINT("- looping through bank sets");
+ for (i = gAlBankSets[offset - 1]; i != 0; i--)
+ {
offset++;
- DEBUG_PRINT("- getting bank id");
+ DEBUG_PRINT("- getting bank id");
bankId = gAlBankSets[offset - 1];
-#endif
+ #endif
- DEBUG_PRINT("- checking if bank load is complete");
- if (IS_BANK_LOAD_COMPLETE(bankId) == TRUE) {
-#ifdef VERSION_EU
+ DEBUG_PRINT("- checking if bank load is complete");
+ if (IS_BANK_LOAD_COMPLETE(bankId) == TRUE)
+ {
+ #ifdef VERSION_EU
ret = get_bank_or_seq(&gBankLoadedPool, 2, bankId);
-#else
- DEBUG_PRINT("- getting bank or seq");
+ #else
+ DEBUG_PRINT("- getting bank or seq");
ret = get_bank_or_seq(&gBankLoadedPool, 2, gAlBankSets[offset - 1]);
-#endif
- } else {
+ #endif
+ }
+ else
+ {
ret = NULL;
}
- if (ret == NULL) {
- DEBUG_PRINT("- bank load immediate");
+ if (ret == NULL)
+ {
+ DEBUG_PRINT("- bank load immediate");
ret = bank_load_immediate(bankId, 2);
}
}
@@ -825,33 +917,41 @@ struct AudioBank *load_banks_immediate(s32 seqId, u8 *outDefaultBank) {
return ret;
}
-void preload_sequence(u32 seqId, u8 preloadMask) {
- DEBUG_PRINT("preload_sequence()");
+void preload_sequence(u32 seqId, u8 preloadMask)
+{
+ DEBUG_PRINT("preload_sequence()");
void *sequenceData;
u8 temp;
- if (seqId >= gSequenceCount) {
+ if (seqId >= gSequenceCount)
+ {
return;
}
gAudioLoadLock = AUDIO_LOCK_LOADING;
- if (preloadMask & PRELOAD_BANKS) {
- DEBUG_PRINT("- load banks immediate");
+ if (preloadMask & PRELOAD_BANKS)
+ {
+ DEBUG_PRINT("- load banks immediate");
load_banks_immediate(seqId, &temp);
}
- if (preloadMask & PRELOAD_SEQUENCE) {
+ if (preloadMask & PRELOAD_SEQUENCE)
+ {
// @bug should be IS_SEQ_LOAD_COMPLETE
- DEBUG_PRINT("- checking if bank load immediate");
- if (IS_BANK_LOAD_COMPLETE(seqId) == TRUE) {
+ DEBUG_PRINT("- checking if bank load immediate");
+ if (IS_BANK_LOAD_COMPLETE(seqId) == TRUE)
+ {
eu_stubbed_printf_1("SEQ %d ALREADY CACHED\n", seqId);
- DEBUG_PRINT("- getting bank or seq");
+ DEBUG_PRINT("- getting bank or seq");
sequenceData = get_bank_or_seq(&gSeqLoadedPool, 2, seqId);
- } else {
+ }
+ else
+ {
sequenceData = NULL;
}
- DEBUG_PRINT("- checking dma immediate");
- if (sequenceData == NULL && sequence_dma_immediate(seqId, 2) == NULL) {
+ DEBUG_PRINT("- checking dma immediate");
+ if (sequenceData == NULL && sequence_dma_immediate(seqId, 2) == NULL)
+ {
gAudioLoadLock = AUDIO_LOCK_NOT_LOADING;
return;
}
@@ -862,46 +962,59 @@ void preload_sequence(u32 seqId, u8 preloadMask) {
void load_sequence_internal(u32 player, u32 seqId, s32 loadAsync);
-void load_sequence(u32 player, u32 seqId, s32 loadAsync) {
- if (!loadAsync) {
+void load_sequence(u32 player, u32 seqId, s32 loadAsync)
+{
+ if (!loadAsync)
+ {
gAudioLoadLock = AUDIO_LOCK_LOADING;
}
load_sequence_internal(player, seqId, loadAsync);
- if (!loadAsync) {
+ if (!loadAsync)
+ {
gAudioLoadLock = AUDIO_LOCK_NOT_LOADING;
}
}
-void load_sequence_internal(u32 player, u32 seqId, s32 loadAsync) {
+void load_sequence_internal(u32 player, u32 seqId, s32 loadAsync)
+{
void *sequenceData;
struct SequencePlayer *seqPlayer = &gSequencePlayers[player];
UNUSED u32 padding[2];
- if (seqId >= gSequenceCount) {
+ if (seqId >= gSequenceCount)
+ {
return;
}
sequence_player_disable(seqPlayer);
- if (loadAsync) {
+ if (loadAsync)
+ {
s32 numMissingBanks = 0;
s32 dummy = 0;
s32 bankId = get_missing_bank(seqId, &dummy, &numMissingBanks);
- if (numMissingBanks == 1) {
+ if (numMissingBanks == 1)
+ {
eu_stubbed_printf_0("Ok,one bank slow load Start \n");
- if (bank_load_async(bankId, 2, seqPlayer) == NULL) {
+ if (bank_load_async(bankId, 2, seqPlayer) == NULL)
+ {
return;
}
// @bug This should set the last bank (i.e. the first in the JSON)
// as default, not the missing one. This code path never gets
// taken, though -- all sequence loading is synchronous.
seqPlayer->defaultBank[0] = bankId;
- } else {
+ }
+ else
+ {
eu_stubbed_printf_1("Sorry,too many %d bank is none.fast load Start \n", numMissingBanks);
- if (load_banks_immediate(seqId, &seqPlayer->defaultBank[0]) == NULL) {
+ if (load_banks_immediate(seqId, &seqPlayer->defaultBank[0]) == NULL)
+ {
return;
}
}
- } else if (load_banks_immediate(seqId, &seqPlayer->defaultBank[0]) == NULL) {
+ }
+ else if (load_banks_immediate(seqId, &seqPlayer->defaultBank[0]) == NULL)
+ {
return;
}
@@ -910,19 +1023,25 @@ void load_sequence_internal(u32 player, u32 seqId, s32 loadAsync) {
seqPlayer->seqId = seqId;
sequenceData = get_bank_or_seq(&gSeqLoadedPool, 2, seqId);
- if (sequenceData == NULL) {
- if (seqPlayer->seqDmaInProgress) {
+ if (sequenceData == NULL)
+ {
+ if (seqPlayer->seqDmaInProgress)
+ {
eu_stubbed_printf_0("Error:Before Sequence-SlowDma remain.\n");
eu_stubbed_printf_0(" Cancel Seq Start.\n");
return;
}
- if (loadAsync) {
+ if (loadAsync)
+ {
sequenceData = sequence_dma_async(seqId, 2, seqPlayer);
- } else {
+ }
+ else
+ {
sequenceData = sequence_dma_immediate(seqId, 2);
}
- if (sequenceData == NULL) {
+ if (sequenceData == NULL)
+ {
return;
}
}
@@ -937,8 +1056,9 @@ void load_sequence_internal(u32 player, u32 seqId, s32 loadAsync) {
}
// (void) must be omitted from parameters to fix stack with -framepointer
-void audio_init() {
- DEBUG_PRINT("audio_init()");
+void audio_init()
+{
+ DEBUG_PRINT("audio_init()");
UNUSED s8 pad[32];
u8 buf[0x10];
s32 i, j, UNUSED k;
@@ -951,23 +1071,26 @@ void audio_init() {
gAudioLoadLock = AUDIO_LOCK_UNINITIALIZED;
- DEBUG_PRINT("- setting values in unused");
+ DEBUG_PRINT("- setting values in unused");
lim1 = gUnusedCount80333EE8;
- for (i = 0; i < lim1; i++) {
+ for (i = 0; i < lim1; i++)
+ {
gUnused80226E58[i] = 0;
gUnused80226E98[i] = 0;
}
- DEBUG_PRINT("- clearing audio heap");
+ DEBUG_PRINT("- clearing audio heap");
lim2 = gAudioHeapSize;
- for (i = 0; i <= lim2 / 8 - 1; i++) {
- ((u64 *) gAudioHeap)[i] = 0;
+ for (i = 0; i <= lim2 / 8 - 1; i++)
+ {
+ ((u64 *)gAudioHeap)[i] = 0;
}
eu_stubbed_printf_1("AudioHeap is %x\n", gAudioHeapSize);
- for (i = 0; i < NUMAIBUFFERS; i++) {
+ for (i = 0; i < NUMAIBUFFERS; i++)
+ {
gAiBufferLengths[i] = 0xa0;
}
@@ -986,10 +1109,12 @@ void audio_init() {
sound_init_main_pools(gAudioInitPoolSize);
- for (i = 0; i < NUMAIBUFFERS; i++) {
+ for (i = 0; i < NUMAIBUFFERS; i++)
+ {
gAiBuffers[i] = soundAlloc(&gAudioInitPool, AIBUFFER_LEN);
- for (j = 0; j < (s32) (AIBUFFER_LEN / sizeof(s16)); j++) {
+ for (j = 0; j < (s32)(AIBUFFER_LEN / sizeof(s16)); j++)
+ {
gAiBuffers[i][j] = 0;
}
}
@@ -1002,55 +1127,55 @@ void audio_init() {
eu_stubbed_printf_0("Main Heap Initialize.\n");
// Load headers for sounds and sequences
- gSeqFileHeader = (ALSeqFile *) buf;
+ gSeqFileHeader = (ALSeqFile *)buf;
data = gMusicData;
- audio_dma_copy_immediate((uintptr_t) data, gSeqFileHeader, 0x10);
+ audio_dma_copy_immediate((uintptr_t)data, gSeqFileHeader, 0x10);
gSequenceCount = gSeqFileHeader->seqCount;
size = ALIGN16(gSequenceCount * sizeof(ALSeqData) + 4);
gSeqFileHeader = soundAlloc(&gAudioInitPool, size);
- audio_dma_copy_immediate((uintptr_t) data, gSeqFileHeader, size);
+ audio_dma_copy_immediate((uintptr_t)data, gSeqFileHeader, size);
alSeqFileNew(gSeqFileHeader, data);
// Load header for CTL (instrument metadata)
- DEBUG_PRINT("- loading ctl header");
- gAlCtlHeader = (ALSeqFile *) buf;
+ DEBUG_PRINT("- loading ctl header");
+ gAlCtlHeader = (ALSeqFile *)buf;
data = gSoundDataADSR;
- DEBUG_PRINT("- copying dma immediate");
- audio_dma_copy_immediate((uintptr_t) data, gAlCtlHeader, 0x10);
+ DEBUG_PRINT("- copying dma immediate");
+ audio_dma_copy_immediate((uintptr_t)data, gAlCtlHeader, 0x10);
size = gAlCtlHeader->seqCount * sizeof(ALSeqData) + 4;
- DEBUG_PRINT("- seq count: %d", gAlCtlHeader->seqCount);
- DEBUG_PRINT("- size after read: %d", size);
+ DEBUG_PRINT("- seq count: %d", gAlCtlHeader->seqCount);
+ DEBUG_PRINT("- size after read: %d", size);
size = ALIGN16(size);
- DEBUG_PRINT("- size after align: %d", size);
+ DEBUG_PRINT("- size after align: %d", size);
gCtlEntries = soundAlloc(&gAudioInitPool, gAlCtlHeader->seqCount * sizeof(struct CtlEntry));
gAlCtlHeader = soundAlloc(&gAudioInitPool, size);
- DEBUG_PRINT("@ copying data from sound data adsr to ctl header");
- DEBUG_PRINT("- data: %x", data);
- DEBUG_PRINT("- ctl header: %x", gAlCtlHeader);
- DEBUG_PRINT("- size: %d", size);
- audio_dma_copy_immediate((uintptr_t) data, gAlCtlHeader, size);
- DEBUG_PRINT("- creating new seq file for ctl");
+ DEBUG_PRINT("@ copying data from sound data adsr to ctl header");
+ DEBUG_PRINT("- data: %x", data);
+ DEBUG_PRINT("- ctl header: %x", gAlCtlHeader);
+ DEBUG_PRINT("- size: %d", size);
+ audio_dma_copy_immediate((uintptr_t)data, gAlCtlHeader, size);
+ DEBUG_PRINT("- creating new seq file for ctl");
alSeqFileNew(gAlCtlHeader, data);
// Load header for TBL (raw sound data)
- DEBUG_PRINT("- loading tbl");
- gAlTbl = (ALSeqFile *) buf;
- DEBUG_PRINT("- copying dma");
- audio_dma_copy_immediate((uintptr_t) data, gAlTbl, 0x10);
- DEBUG_PRINT("- tbl seq count: %d", gAlTbl->seqCount);
+ DEBUG_PRINT("- loading tbl");
+ gAlTbl = (ALSeqFile *)buf;
+ DEBUG_PRINT("- copying dma");
+ audio_dma_copy_immediate((uintptr_t)data, gAlTbl, 0x10);
+ DEBUG_PRINT("- tbl seq count: %d", gAlTbl->seqCount);
size = gAlTbl->seqCount * sizeof(ALSeqData) + 4;
- DEBUG_PRINT("- size: %d", size);
+ DEBUG_PRINT("- size: %d", size);
size = ALIGN16(size);
- DEBUG_PRINT("- size after align: %d", size);
+ DEBUG_PRINT("- size after align: %d", size);
gAlTbl = soundAlloc(&gAudioInitPool, size);
- DEBUG_PRINT("- tbl alloc at %x", gAlTbl);
- DEBUG_PRINT("- gSoundDataRaw at %x", gSoundDataRaw);
- audio_dma_copy_immediate((uintptr_t) gSoundDataRaw, gAlTbl, size);
+ DEBUG_PRINT("- tbl alloc at %x", gAlTbl);
+ DEBUG_PRINT("- gSoundDataRaw at %x", gSoundDataRaw);
+ audio_dma_copy_immediate((uintptr_t)gSoundDataRaw, gAlTbl, size);
alSeqFileNew(gAlTbl, (u8 *)gSoundDataRaw);
// Load bank sets for each sequence
gAlBankSets = soundAlloc(&gAudioInitPool, 0x100);
- audio_dma_copy_immediate((uintptr_t) gBankSetsData, gAlBankSets, 0x100);
+ audio_dma_copy_immediate((uintptr_t)gBankSetsData, gAlBankSets, 0x100);
init_sequence_players();
gAudioLoadLock = AUDIO_LOCK_NOT_LOADING;
diff --git a/src/decomp/audio/load.h b/src/decomp/audio/load.h
index 86f8fa8..beaa05f 100644
--- a/src/decomp/audio/load.h
+++ b/src/decomp/audio/load.h
@@ -56,7 +56,8 @@ extern s8 gSoundMode;
#ifdef VERSION_SH
extern OSMesgQueue gUnkQueue1;
-struct UnkStructSH8034EC88 {
+struct UnkStructSH8034EC88
+{
u8 *endAndMediumIdentification;
struct AudioBankSample *sample;
u8 *ramAddr;
@@ -64,7 +65,8 @@ struct UnkStructSH8034EC88 {
s32 isFree;
};
-struct PatchStruct {
+struct PatchStruct
+{
s32 bankId1;
s32 bankId2;
void *baseAddr1;
@@ -78,7 +80,8 @@ extern struct UnkStructSH8034EC88 D_SH_8034EC88[0x80];
struct AudioBank *bank_load_immediate(s32 bankId, s32 arg1);
-void audio_dma_partial_copy_async(uintptr_t *devAddr, u8 **vAddr, ssize_t *remaining, OSMesgQueue *queue, OSIoMesg *mesg);
+void audio_dma_partial_copy_async(uintptr_t * devAddr, u8 * *vAddr, ssize_t * remaining, OSMesgQueue * queue, OSIoMesg * mesg);
+
void decrease_sample_dma_ttls(void);
#ifdef VERSION_SH
void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef, s32 medium);
@@ -105,7 +108,7 @@ struct AudioBankSample *func_sh_802f4978(s32 bankId, s32 idx);
s32 func_sh_802f47c8(s32 bankId, u8 idx, s8 *io);
void *func_sh_802f3f08(s32 poolIdx, s32 arg1, s32 arg2, s32 arg3, OSMesgQueue *retQueue);
void func_sh_802f41e4(s32 audioResetStatus);
-BAD_RETURN(s32) func_sh_802f3368(s32 bankId);
+BAD_RETURN (s32) func_sh_802f3368(s32 bankId);
void *func_sh_802f3764(s32 arg0, s32 idx, s32 *arg2);
s32 func_sh_802f3024(s32 bankId, s32 instId, s32 arg2);
void func_sh_802f30f4(s32 arg0, s32 arg1, s32 arg2, OSMesgQueue *arg3);
diff --git a/src/decomp/audio/load_dat.c b/src/decomp/audio/load_dat.c
index 9c99214..71cf170 100644
--- a/src/decomp/audio/load_dat.c
+++ b/src/decomp/audio/load_dat.c
@@ -7,5 +7,5 @@ struct seqFile *gSoundDataRaw;
struct seqFile *gMusicData;
#ifndef VERSION_SH
-unsigned char* gBankSetsData;
+unsigned char *gBankSetsData;
#endif
\ No newline at end of file
diff --git a/src/decomp/audio/load_sh.c b/src/decomp/audio/load_sh.c
index c57e722..8716872 100644
--- a/src/decomp/audio/load_sh.c
+++ b/src/decomp/audio/load_sh.c
@@ -9,15 +9,23 @@
#define ALIGN16(val) (((val) + 0xF) & ~0xF)
-struct SharedDma {
- /*0x0*/ u8 *buffer; // target, points to pre-allocated buffer
- /*0x4*/ uintptr_t source; // device address
- /*0x8*/ u16 sizeUnused; // set to bufSize, never read
- /*0xA*/ u16 bufSize; // size of buffer
- /*0xC*/ u8 unused2; // set to 0, never read
- /*0xD*/ u8 reuseIndex; // position in sSampleDmaReuseQueue1/2, if ttl == 0
- /*0xE*/ u8 ttl; // duration after which the DMA can be discarded
-}; // size = 0x10
+struct SharedDma
+{
+ /*0x0*/
+ u8 *buffer; // target, points to pre-allocated buffer
+ /*0x4*/
+ uintptr_t source; // device address
+ /*0x8*/
+ u16 sizeUnused; // set to bufSize, never read
+ /*0xA*/
+ u16 bufSize; // size of buffer
+ /*0xC*/
+ u8 unused2; // set to 0, never read
+ /*0xD*/
+ u8 reuseIndex; // position in sSampleDmaReuseQueue1/2, if ttl == 0
+ /*0xE*/
+ u8 ttl; // duration after which the DMA can be discarded
+}; // size = 0x10
void port_eu_init(void);
void patch_sound(struct AudioBankSound *sound, struct AudioBank *memBase, struct PatchStruct *patchInfo);
@@ -40,7 +48,8 @@ struct UnkStructSH8034EC88 D_SH_8034EC88[0x80];
s32 D_SH_8034F688; // index into D_SH_8034EA88
s32 D_SH_8034F68C; // index or size for D_SH_8034EC88
-struct PendingDmaAudioBank {
+struct PendingDmaAudioBank
+{
s8 inProgress;
s8 timer;
s8 medium;
@@ -106,8 +115,8 @@ extern u64 gAudioGlobalsStartMarker;
extern u64 gAudioGlobalsEndMarker;
extern u8 gSoundDataADSR[]; // ctl
-extern u8 gSoundDataRaw[]; // tbl
-extern u8 gMusicData[]; // sequences
+extern u8 gSoundDataRaw[]; // tbl
+extern u8 gMusicData[]; // sequences
ALSeqFile *get_audio_file_header(s32 arg0);
@@ -115,18 +124,20 @@ void *func_sh_802f3688(s32 bankId);
void *get_bank_or_seq_wrapper(s32 arg0, s32 arg1);
void func_sh_802f3d78(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3);
void func_sh_802f3c38(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 medium);
-s32 func_sh_802f3dd0(OSIoMesg *m, s32 pri, s32 direction, uintptr_t devAddr,
- void *dramAddr, s32 size, OSMesgQueue *retQueue, s32 medium, UNUSED const char *reason);
+s32 func_sh_802f3dd0(
+ OSIoMesg *m, s32 pri, s32 direction, uintptr_t devAddr,
+ void *dramAddr, s32 size, OSMesgQueue *retQueue, s32 medium, UNUSED const char *reason);
void func_sh_802f4a4c(s32 audioResetStatus);
void func_sh_802f4bd8(struct PendingDmaSample *arg0, s32 len);
void func_sh_802f4c5c(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3);
-struct PendingDmaAudioBank *func_sh_802f4cb4(uintptr_t devAddr, void *vAddr, s32 size,
- s32 medium, s32 numChunks, OSMesgQueue *retQueue, s32 encodedInfo);
+struct PendingDmaAudioBank *func_sh_802f4cb4(
+ uintptr_t devAddr, void *vAddr, s32 size,
+ s32 medium, s32 numChunks, OSMesgQueue *retQueue, s32 encodedInfo);
void func_sh_802f4dcc(s32 audioResetStatus);
void func_sh_802f4e50(struct PendingDmaAudioBank *audioBank, s32 audioResetStatus);
void func_sh_802f50ec(struct PendingDmaAudioBank *arg0, size_t len);
void func_sh_802f517c(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3);
-BAD_RETURN(s32) func_sh_802f5310(s32 bankId, struct AudioBank *mem, struct PatchStruct *patchInfo, s32 arg3);
+BAD_RETURN (s32) func_sh_802f5310(s32 bankId, struct AudioBank *mem, struct PatchStruct *patchInfo, s32 arg3);
s32 func_sh_802f573c(s32 audioResetStatus);
void *func_sh_802f3564(s32 seqId);
s32 func_sh_802f3ec4(s32 arg0, uintptr_t *arg1);
@@ -134,27 +145,34 @@ void func_sh_802f3ed4(UNUSED s32 arg0, UNUSED s32 arg1, UNUSED void *vAddr, UNUS
s32 canonicalize_index(s32 poolIdx, s32 idx);
-void decrease_sample_dma_ttls() {
+void decrease_sample_dma_ttls()
+{
u32 i;
- for (i = 0; i < sSampleDmaListSize1; i++) {
+ for (i = 0; i < sSampleDmaListSize1; i++)
+ {
struct SharedDma *temp = &sSampleDmas[i];
- if (temp->ttl != 0) {
+ if (temp->ttl != 0)
+ {
temp->ttl--;
- if (temp->ttl == 0) {
+ if (temp->ttl == 0)
+ {
temp->reuseIndex = sSampleDmaReuseQueueHead1;
- sSampleDmaReuseQueue1[sSampleDmaReuseQueueHead1++] = (u8) i;
+ sSampleDmaReuseQueue1[sSampleDmaReuseQueueHead1++] = (u8)i;
}
}
}
- for (i = sSampleDmaListSize1; i < gSampleDmaNumListItems; i++) {
+ for (i = sSampleDmaListSize1; i < gSampleDmaNumListItems; i++)
+ {
struct SharedDma *temp = &sSampleDmas[i];
- if (temp->ttl != 0) {
+ if (temp->ttl != 0)
+ {
temp->ttl--;
- if (temp->ttl == 0) {
+ if (temp->ttl == 0)
+ {
temp->reuseIndex = sSampleDmaReuseQueueHead2;
- sSampleDmaReuseQueue2[sSampleDmaReuseQueueHead2++] = (u8) i;
+ sSampleDmaReuseQueue2[sSampleDmaReuseQueueHead2++] = (u8)i;
}
}
}
@@ -163,7 +181,8 @@ void decrease_sample_dma_ttls() {
}
extern char shindouDebugPrint62[]; // "SUPERDMA"
-void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef, s32 medium) {
+void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef, s32 medium)
+{
UNUSED s32 sp60;
struct SharedDma *dma;
s32 hasDma = FALSE;
@@ -174,30 +193,36 @@ void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef, s3
ssize_t bufferPos;
u32 i;
- if (arg2 != 0 || *dmaIndexRef >= sSampleDmaListSize1) {
- for (i = sSampleDmaListSize1; i < gSampleDmaNumListItems; i++) {
+ if (arg2 != 0 || *dmaIndexRef >= sSampleDmaListSize1)
+ {
+ for (i = sSampleDmaListSize1; i < gSampleDmaNumListItems; i++)
+ {
dma = &sSampleDmas[i];
bufferPos = devAddr - dma->source;
- if (0 <= bufferPos && (size_t) bufferPos <= dma->bufSize - size) {
+ if (0 <= bufferPos && (size_t)bufferPos <= dma->bufSize - size)
+ {
// We already have a DMA request for this memory range.
- if (dma->ttl == 0 && sSampleDmaReuseQueueTail2 != sSampleDmaReuseQueueHead2) {
+ if (dma->ttl == 0 && sSampleDmaReuseQueueTail2 != sSampleDmaReuseQueueHead2)
+ {
// Move the DMA out of the reuse queue, by swapping it with the
// tail, and then incrementing the tail.
- if (dma->reuseIndex != sSampleDmaReuseQueueTail2) {
+ if (dma->reuseIndex != sSampleDmaReuseQueueTail2)
+ {
sSampleDmaReuseQueue2[dma->reuseIndex] =
- sSampleDmaReuseQueue2[sSampleDmaReuseQueueTail2];
+ sSampleDmaReuseQueue2[sSampleDmaReuseQueueTail2];
sSampleDmas[sSampleDmaReuseQueue2[sSampleDmaReuseQueueTail2]].reuseIndex =
- dma->reuseIndex;
+ dma->reuseIndex;
}
sSampleDmaReuseQueueTail2++;
}
dma->ttl = 60;
- *dmaIndexRef = (u8) i;
+ *dmaIndexRef = (u8)i;
return &dma->buffer[(devAddr - dma->source)];
}
}
- if (sSampleDmaReuseQueueTail2 != sSampleDmaReuseQueueHead2 && arg2 != 0) {
+ if (sSampleDmaReuseQueueTail2 != sSampleDmaReuseQueueHead2 && arg2 != 0)
+ {
// Allocate a DMA from reuse queue 2. This queue can be empty, since
// TTL 60 is pretty large.
dmaIndex = sSampleDmaReuseQueue2[sSampleDmaReuseQueueTail2];
@@ -205,19 +230,24 @@ void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef, s3
dma = sSampleDmas + dmaIndex;
hasDma = TRUE;
}
- } else {
+ }
+ else
+ {
dma = sSampleDmas + *dmaIndexRef;
bufferPos = devAddr - dma->source;
- if (0 <= bufferPos && (size_t) bufferPos <= dma->bufSize - size) {
+ if (0 <= bufferPos && (size_t)bufferPos <= dma->bufSize - size)
+ {
// We already have DMA for this memory range.
- if (dma->ttl == 0) {
+ if (dma->ttl == 0)
+ {
// Move the DMA out of the reuse queue, by swapping it with the
// tail, and then incrementing the tail.
- if (dma->reuseIndex != sSampleDmaReuseQueueTail1) {
+ if (dma->reuseIndex != sSampleDmaReuseQueueTail1)
+ {
sSampleDmaReuseQueue1[dma->reuseIndex] =
- sSampleDmaReuseQueue1[sSampleDmaReuseQueueTail1];
+ sSampleDmaReuseQueue1[sSampleDmaReuseQueueTail1];
sSampleDmas[sSampleDmaReuseQueue1[sSampleDmaReuseQueueTail1]].reuseIndex =
- dma->reuseIndex;
+ dma->reuseIndex;
}
sSampleDmaReuseQueueTail1++;
}
@@ -226,8 +256,11 @@ void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef, s3
}
}
- if (!hasDma) {
- if (1) {}
+ if (!hasDma)
+ {
+ if (1)
+ {
+ }
// Allocate a DMA from reuse queue 1. This queue will hopefully never
// be empty, since TTL 2 is so small.
dmaIndex = sSampleDmaReuseQueue1[sSampleDmaReuseQueueTail1++];
@@ -241,21 +274,23 @@ void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef, s3
dma->source = dmaDevAddr;
dma->sizeUnused = transfer;
func_sh_802f3dd0(&gCurrAudioFrameDmaIoMesgBufs[gCurrAudioFrameDmaCount++], OS_MESG_PRI_NORMAL, OS_READ,
- dmaDevAddr, dma->buffer, transfer, &gCurrAudioFrameDmaQueue, medium, shindouDebugPrint62);
+ dmaDevAddr, dma->buffer, transfer, &gCurrAudioFrameDmaQueue, medium, shindouDebugPrint62);
*dmaIndexRef = dmaIndex;
return (devAddr - dmaDevAddr) + dma->buffer;
}
-void init_sample_dma_buffers(UNUSED s32 arg0) {
+void init_sample_dma_buffers(UNUSED s32 arg0)
+{
s32 i;
sDmaBufSize = 0x2D0;
sSampleDmas = sound_alloc_uninitialized(&gNotesAndBuffersPool,
- gMaxSimultaneousNotes * 4 * sizeof(struct SharedDma) * gAudioBufferParameters.presetUnk4);
+ gMaxSimultaneousNotes * 4 * sizeof(struct SharedDma) * gAudioBufferParameters.presetUnk4);
for (i = 0; i < gMaxSimultaneousNotes * 3 * gAudioBufferParameters.presetUnk4; i++)
{
- if ((sSampleDmas[gSampleDmaNumListItems].buffer = sound_alloc_uninitialized(&gNotesAndBuffersPool, sDmaBufSize)) == NULL) {
+ if ((sSampleDmas[gSampleDmaNumListItems].buffer = sound_alloc_uninitialized(&gNotesAndBuffersPool, sDmaBufSize)) == NULL)
+ {
break;
}
sSampleDmas[gSampleDmaNumListItems].bufSize = sDmaBufSize;
@@ -266,22 +301,26 @@ void init_sample_dma_buffers(UNUSED s32 arg0) {
gSampleDmaNumListItems++;
}
- for (i = 0; (u32) i < gSampleDmaNumListItems; i++) {
- sSampleDmaReuseQueue1[i] = (u8) i;
- sSampleDmas[i].reuseIndex = (u8) i;
+ for (i = 0; (u32)i < gSampleDmaNumListItems; i++)
+ {
+ sSampleDmaReuseQueue1[i] = (u8)i;
+ sSampleDmas[i].reuseIndex = (u8)i;
}
- for (i = gSampleDmaNumListItems; i < 0x100; i++) {
+ for (i = gSampleDmaNumListItems; i < 0x100; i++)
+ {
sSampleDmaReuseQueue1[i] = 0;
}
sSampleDmaReuseQueueTail1 = 0;
- sSampleDmaReuseQueueHead1 = (u8) gSampleDmaNumListItems;
+ sSampleDmaReuseQueueHead1 = (u8)gSampleDmaNumListItems;
sSampleDmaListSize1 = gSampleDmaNumListItems;
sDmaBufSize = 0x2D0;
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
- if ((sSampleDmas[gSampleDmaNumListItems].buffer = sound_alloc_uninitialized(&gNotesAndBuffersPool, sDmaBufSize)) == NULL) {
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
+ if ((sSampleDmas[gSampleDmaNumListItems].buffer = sound_alloc_uninitialized(&gNotesAndBuffersPool, sDmaBufSize)) == NULL)
+ {
break;
}
sSampleDmas[gSampleDmaNumListItems].bufSize = sDmaBufSize;
@@ -292,14 +331,16 @@ void init_sample_dma_buffers(UNUSED s32 arg0) {
gSampleDmaNumListItems++;
}
- for (i = sSampleDmaListSize1; (u32) i < gSampleDmaNumListItems; i++) {
- sSampleDmaReuseQueue2[i - sSampleDmaListSize1] = (u8) i;
+ for (i = sSampleDmaListSize1; (u32)i < gSampleDmaNumListItems; i++)
+ {
+ sSampleDmaReuseQueue2[i - sSampleDmaListSize1] = (u8)i;
sSampleDmas[i].reuseIndex = (u8)(i - sSampleDmaListSize1);
}
// This probably meant to touch the range size1..size2 as well... but it
// doesn't matter, since these values are never read anyway.
- for (i = gSampleDmaNumListItems; i < 0x100; i++) {
+ for (i = gSampleDmaNumListItems; i < 0x100; i++)
+ {
sSampleDmaReuseQueue2[i] = sSampleDmaListSize1;
}
@@ -307,19 +348,23 @@ void init_sample_dma_buffers(UNUSED s32 arg0) {
sSampleDmaReuseQueueHead2 = gSampleDmaNumListItems - sSampleDmaListSize1;
}
-void patch_seq_file(ALSeqFile *seqFile, u8 *data, u16 arg2) {
+void patch_seq_file(ALSeqFile *seqFile, u8 *data, u16 arg2)
+{
s32 i;
seqFile->unk2 = arg2;
seqFile->data = data;
- for (i = 0; i < seqFile->seqCount; i++) {
- if (seqFile->seqArray[i].len != 0 && seqFile->seqArray[i].medium == 2) {
+ for (i = 0; i < seqFile->seqCount; i++)
+ {
+ if (seqFile->seqArray[i].len != 0 && seqFile->seqArray[i].medium == 2)
+ {
seqFile->seqArray[i].offset += (uintptr_t)data;
}
}
}
-struct AudioBank *load_banks_immediate(s32 seqId, s32 *outDefaultBank) {
+struct AudioBank *load_banks_immediate(s32 seqId, s32 *outDefaultBank)
+{
u8 bank;
s32 offset;
s32 i;
@@ -327,7 +372,8 @@ struct AudioBank *load_banks_immediate(s32 seqId, s32 *outDefaultBank) {
offset = ((u16 *)gAlBankSets)[canonicalize_index(0, seqId)];
bank = 0xFF;
- for (i = gAlBankSets[offset++]; i > 0; i--) {
+ for (i = gAlBankSets[offset++]; i > 0; i--)
+ {
bank = gAlBankSets[offset++];
ret = func_sh_802f3688(bank);
}
@@ -335,140 +381,171 @@ struct AudioBank *load_banks_immediate(s32 seqId, s32 *outDefaultBank) {
return ret;
}
-void preload_sequence(u32 seqId, s32 preloadMask) {
+void preload_sequence(u32 seqId, s32 preloadMask)
+{
UNUSED s32 pad;
s32 temp;
seqId = canonicalize_index(0, seqId);
- if (preloadMask & PRELOAD_BANKS) {
+ if (preloadMask & PRELOAD_BANKS)
+ {
load_banks_immediate(seqId, &temp);
}
- if (preloadMask & PRELOAD_SEQUENCE) {
+ if (preloadMask & PRELOAD_SEQUENCE)
+ {
func_sh_802f3564(seqId);
}
}
-s32 func_sh_802f2f38(struct AudioBankSample *sample, s32 bankId) {
+s32 func_sh_802f2f38(struct AudioBankSample *sample, s32 bankId)
+{
u8 *sp24;
- if (sample->isPatched == TRUE && sample->medium != 0) {
+ if (sample->isPatched == TRUE && sample->medium != 0)
+ {
sp24 = func_sh_802f1d90(sample->size, bankId, sample->sampleAddr, sample->medium);
- if (sp24 == NULL) {
+ if (sp24 == NULL)
+ {
return -1;
}
- if (sample->medium == 1) {
- func_sh_802f3d78((uintptr_t) sample->sampleAddr, sp24, sample->size, gAlTbl->unk2);
- } else {
- func_sh_802f3c38((uintptr_t) sample->sampleAddr, sp24, sample->size, sample->medium);
+ if (sample->medium == 1)
+ {
+ func_sh_802f3d78((uintptr_t)sample->sampleAddr, sp24, sample->size, gAlTbl->unk2);
+ }
+ else
+ {
+ func_sh_802f3c38((uintptr_t)sample->sampleAddr, sp24, sample->size, sample->medium);
}
sample->medium = 0;
sample->sampleAddr = sp24;
}
#ifdef AVOID_UB
- return 0;
+return 0;
#endif
}
-s32 func_sh_802f3024(s32 bankId, s32 instId, s32 arg2) {
+s32 func_sh_802f3024(s32 bankId, s32 instId, s32 arg2)
+{
struct Instrument *instr;
struct Drum *drum;
- if (instId < 0x7F) {
+ if (instId < 0x7F)
+ {
instr = get_instrument_inner(bankId, instId);
- if (instr == NULL) {
+ if (instr == NULL)
+ {
return -1;
}
- if (instr->normalRangeLo != 0) {
+ if (instr->normalRangeLo != 0)
+ {
func_sh_802f2f38(instr->lowNotesSound.sample, bankId);
}
func_sh_802f2f38(instr->normalNotesSound.sample, bankId);
- if (instr->normalRangeHi != 0x7F) {
+ if (instr->normalRangeHi != 0x7F)
+ {
func_sh_802f2f38(instr->highNotesSound.sample, bankId);
}
//! @bug missing return
- } else if (instId == 0x7F) {
+ }
+ else if (instId == 0x7F)
+ {
drum = get_drum(bankId, arg2);
- if (drum == NULL) {
+ if (drum == NULL)
+ {
return -1;
}
func_sh_802f2f38(drum->sound.sample, bankId);
return 0;
}
#ifdef AVOID_UB
- return 0;
+return 0;
#endif
}
-void func_sh_802f30f4(s32 arg0, s32 arg1, s32 arg2, OSMesgQueue *arg3) {
- if (func_802f3f08(2, canonicalize_index(2, arg0), arg1, arg2, arg3) == 0) {
+void func_sh_802f30f4(s32 arg0, s32 arg1, s32 arg2, OSMesgQueue *arg3)
+{
+ if (func_802f3f08(2, canonicalize_index(2, arg0), arg1, arg2, arg3) == 0)
+ {
osSendMesg(arg3, 0, 0);
}
}
-void func_sh_802f3158(s32 seqId, s32 numChunks, s32 arg2, OSMesgQueue *retQueue) {
+void func_sh_802f3158(s32 seqId, s32 numChunks, s32 arg2, OSMesgQueue *retQueue)
+{
s32 val;
s32 v;
- val = ((u16 *) gAlBankSets)[canonicalize_index(0, seqId)];
+ val = ((u16 *)gAlBankSets)[canonicalize_index(0, seqId)];
v = gAlBankSets[val++];
- while (v > 0) {
+ while (v > 0)
+ {
func_802f3f08(1, canonicalize_index(1, gAlBankSets[val++]), numChunks, arg2, retQueue);
v--;
}
}
-u8 *func_sh_802f3220(u32 seqId, u32 *a1) {
+u8 *func_sh_802f3220(u32 seqId, u32 *a1)
+{
s32 val;
- val = ((u16 *) gAlBankSets)[canonicalize_index(0, seqId)];
+ val = ((u16 *)gAlBankSets)[canonicalize_index(0, seqId)];
*a1 = gAlBankSets[val++];
- if (*a1 == 0) {
+ if (*a1 == 0)
+ {
return NULL;
}
return &gAlBankSets[val];
}
-void func_sh_802f3288(s32 idx) {
+void func_sh_802f3288(s32 idx)
+{
s32 bankId;
s32 s2;
- idx = ((u16*)gAlBankSets)[canonicalize_index(0, idx)];
+ idx = ((u16 *)gAlBankSets)[canonicalize_index(0, idx)];
s2 = gAlBankSets[idx++];
- while (s2 > 0) {
+ while (s2 > 0)
+ {
s2--;
bankId = canonicalize_index(1, gAlBankSets[idx++]);
- if (unk_pool1_lookup(1, bankId) == NULL) {
+ if (unk_pool1_lookup(1, bankId) == NULL)
+ {
func_sh_802f3368(bankId);
- if (gBankLoadStatus[bankId] != SOUND_LOAD_STATUS_5) {
+ if (gBankLoadStatus[bankId] != SOUND_LOAD_STATUS_5)
+ {
gBankLoadStatus[bankId] = SOUND_LOAD_STATUS_NOT_LOADED;
}
continue;
}
-
}
}
-BAD_RETURN(s32) func_sh_802f3368(s32 bankId) {
+BAD_RETURN (s32) func_sh_802f3368(s32 bankId)
+{
struct SoundMultiPool *pool = &gBankLoadedPool;
struct TemporaryPool *temporary = &pool->temporary;
struct PersistentPool *persistent;
u32 i;
- if (temporary->entries[0].id == bankId) {
+ if (temporary->entries[0].id == bankId)
+ {
temporary->entries[0].id = -1;
- } else if (temporary->entries[1].id == bankId) {
+ }
+ else if (temporary->entries[1].id == bankId)
+ {
temporary->entries[1].id = -1;
}
persistent = &pool->persistent;
- for (i = 0; i < persistent->numEntries; i++) {
- if (persistent->entries[i].id == bankId) {
+ for (i = 0; i < persistent->numEntries; i++)
+ {
+ if (persistent->entries[i].id == bankId)
+ {
persistent->entries[i].id = -1;
}
-
}
discard_bank(bankId);
@@ -476,11 +553,13 @@ BAD_RETURN(s32) func_sh_802f3368(s32 bankId) {
void load_sequence_internal(s32 player, s32 seqId, s32 loadAsync);
-void load_sequence(u32 player, u32 seqId, s32 loadAsync) {
+void load_sequence(u32 player, u32 seqId, s32 loadAsync)
+{
load_sequence_internal(player, seqId, loadAsync);
}
-void load_sequence_internal(s32 player, s32 seqId, UNUSED s32 loadAsync) {
+void load_sequence_internal(s32 player, s32 seqId, UNUSED s32 loadAsync)
+{
struct SequencePlayer *seqPlayer;
u8 *sequenceData;
u32 s0;
@@ -493,11 +572,12 @@ void load_sequence_internal(s32 player, s32 seqId, UNUSED s32 loadAsync) {
seqId = canonicalize_index(0, seqId);
sequence_player_disable(seqPlayer);
- s0 = ((u16 *) gAlBankSets)[seqId];
+ s0 = ((u16 *)gAlBankSets)[seqId];
count = gAlBankSets[s0++];
bank = 0xff;
- while (count > 0) {
+ while (count > 0)
+ {
bank = gAlBankSets[s0++];
func_sh_802f3688(bank);
count--;
@@ -514,11 +594,13 @@ void load_sequence_internal(s32 player, s32 seqId, UNUSED s32 loadAsync) {
seqPlayer->delay = 0;
seqPlayer->finished = 0;
- for (i = 0; i < 0x10; i++) {
+ for (i = 0; i < 0x10; i++)
+ {
}
}
-void *func_sh_802f3564(s32 seqId) {
+void *func_sh_802f3564(s32 seqId)
+{
s32 seqId2 = canonicalize_index(0, seqId);
s32 temp;
return func_sh_802f3764(0, seqId2, &temp);
@@ -526,7 +608,8 @@ void *func_sh_802f3564(s32 seqId) {
extern u8 gUnkLoadStatus[0x40];
-void *func_sh_802f3598(s32 idx, s32 *medium) {
+void *func_sh_802f3598(s32 idx, s32 *medium)
+{
void *ret;
ALSeqFile *f;
s32 temp;
@@ -535,8 +618,10 @@ void *func_sh_802f3598(s32 idx, s32 *medium) {
f = get_audio_file_header(2);
idx = canonicalize_index(2, idx);
ret = get_bank_or_seq_wrapper(2, idx);
- if (ret != NULL) {
- if (gUnkLoadStatus[idx] != SOUND_LOAD_STATUS_5) {
+ if (ret != NULL)
+ {
+ if (gUnkLoadStatus[idx] != SOUND_LOAD_STATUS_5)
+ {
gUnkLoadStatus[idx] = SOUND_LOAD_STATUS_COMPLETE;
}
@@ -545,12 +630,16 @@ void *func_sh_802f3598(s32 idx, s32 *medium) {
}
temp = f->seqArray[idx].magic;
- if (temp == 4) {
+ if (temp == 4)
+ {
*medium = f->seqArray[idx].medium;
return f->seqArray[idx].offset;
- } else {
+ }
+ else
+ {
ret = func_sh_802f3764(2, idx, &sp28);
- if (ret != 0) {
+ if (ret != 0)
+ {
*medium = 0;
return ret;
}
@@ -558,10 +647,10 @@ void *func_sh_802f3598(s32 idx, s32 *medium) {
*medium = f->seqArray[idx].medium;
}
return f->seqArray[idx].offset;
-
}
-void *func_sh_802f3688(s32 bankId) {
+void *func_sh_802f3688(s32 bankId)
+{
void *ret;
s32 bankId1;
s32 bankId2;
@@ -575,30 +664,39 @@ void *func_sh_802f3688(s32 bankId) {
patchInfo.bankId1 = bankId1;
patchInfo.bankId2 = bankId2;
- if (patchInfo.bankId1 != 0xFF) {
+ if (patchInfo.bankId1 != 0xFF)
+ {
patchInfo.baseAddr1 = func_sh_802f3598(patchInfo.bankId1, &patchInfo.medium1);
- } else {
+ }
+ else
+ {
patchInfo.baseAddr1 = NULL;
}
- if (bankId2 != 0xFF) {
+ if (bankId2 != 0xFF)
+ {
patchInfo.baseAddr2 = func_sh_802f3598(bankId2, &patchInfo.medium2);
- } else {
+ }
+ else
+ {
patchInfo.baseAddr2 = NULL;
}
- if ((ret = func_sh_802f3764(1, bankId, &sp38)) == NULL) {
+ if ((ret = func_sh_802f3764(1, bankId, &sp38)) == NULL)
+ {
return NULL;
}
- if (sp38 == 1) {
+ if (sp38 == 1)
+ {
func_sh_802f5310(bankId, ret, &patchInfo, 0);
}
return ret;
}
-void *func_sh_802f3764(s32 poolIdx, s32 idx, s32 *arg2) {
+void *func_sh_802f3764(s32 poolIdx, s32 idx, s32 *arg2)
+{
s32 size;
ALSeqFile *f;
void *vAddr;
@@ -609,10 +707,13 @@ void *func_sh_802f3764(s32 poolIdx, s32 idx, s32 *arg2) {
s32 sp18;
vAddr = get_bank_or_seq_wrapper(poolIdx, idx);
- if (vAddr != NULL) {
+ if (vAddr != NULL)
+ {
*arg2 = 0;
loadStatus = SOUND_LOAD_STATUS_COMPLETE;
- } else {
+ }
+ else
+ {
f = get_audio_file_header(poolIdx);
size = f->seqArray[idx].len;
size = ALIGN16(size);
@@ -625,19 +726,22 @@ void *func_sh_802f3764(s32 poolIdx, s32 idx, s32 *arg2) {
{
case 0:
vAddr = unk_pool1_alloc(poolIdx, idx, size);
- if (vAddr == NULL) {
+ if (vAddr == NULL)
+ {
return vAddr;
}
break;
case 1:
vAddr = alloc_bank_or_seq(poolIdx, size, 1, idx);
- if (vAddr == NULL) {
+ if (vAddr == NULL)
+ {
return vAddr;
}
break;
case 2:
vAddr = alloc_bank_or_seq(poolIdx, size, 0, idx);
- if (vAddr == NULL) {
+ if (vAddr == NULL)
+ {
return vAddr;
}
break;
@@ -645,20 +749,25 @@ void *func_sh_802f3764(s32 poolIdx, s32 idx, s32 *arg2) {
case 3:
case 4:
vAddr = alloc_bank_or_seq(poolIdx, size, 2, idx);
- if (vAddr == NULL) {
+ if (vAddr == NULL)
+ {
return vAddr;
}
break;
}
*arg2 = 1;
- if (medium == 1) {
- func_sh_802f3d78((uintptr_t) devAddr, vAddr, size, f->unk2);
- } else {
- func_sh_802f3c38((uintptr_t) devAddr, vAddr, size, medium);
+ if (medium == 1)
+ {
+ func_sh_802f3d78((uintptr_t)devAddr, vAddr, size, f->unk2);
+ }
+ else
+ {
+ func_sh_802f3c38((uintptr_t)devAddr, vAddr, size, medium);
}
- switch (sp18) {
+ switch (sp18)
+ {
case 0:
loadStatus = SOUND_LOAD_STATUS_5;
break;
@@ -669,21 +778,25 @@ void *func_sh_802f3764(s32 poolIdx, s32 idx, s32 *arg2) {
}
}
- switch (poolIdx) {
+ switch (poolIdx)
+ {
case 0:
- if (gSeqLoadStatus[idx] != SOUND_LOAD_STATUS_5) {
+ if (gSeqLoadStatus[idx] != SOUND_LOAD_STATUS_5)
+ {
gSeqLoadStatus[idx] = loadStatus;
}
break;
case 1:
- if (gBankLoadStatus[idx] != SOUND_LOAD_STATUS_5) {
+ if (gBankLoadStatus[idx] != SOUND_LOAD_STATUS_5)
+ {
gBankLoadStatus[idx] = loadStatus;
}
break;
case 2:
- if (gUnkLoadStatus[idx] != SOUND_LOAD_STATUS_5) {
+ if (gUnkLoadStatus[idx] != SOUND_LOAD_STATUS_5)
+ {
gUnkLoadStatus[idx] = loadStatus;
}
break;
@@ -692,33 +805,41 @@ void *func_sh_802f3764(s32 poolIdx, s32 idx, s32 *arg2) {
return vAddr;
}
-s32 canonicalize_index(s32 poolIdx, s32 idx) {
+s32 canonicalize_index(s32 poolIdx, s32 idx)
+{
ALSeqFile *f;
f = get_audio_file_header(poolIdx);
- if (f->seqArray[idx].len == 0) {
- idx = (s32) (uintptr_t) f->seqArray[idx].offset;
+ if (f->seqArray[idx].len == 0)
+ {
+ idx = (s32)(uintptr_t)
+ f->seqArray[idx].offset;
}
return idx;
}
-void *get_bank_or_seq_wrapper(s32 poolIdx, s32 id) {
+void *get_bank_or_seq_wrapper(s32 poolIdx, s32 id)
+{
void *ret;
ret = unk_pool1_lookup(poolIdx, id);
- if (ret != NULL) {
+ if (ret != NULL)
+ {
return ret;
}
ret = get_bank_or_seq(poolIdx, 2, id);
- if (ret != 0) {
+ if (ret != 0)
+ {
return ret;
}
return NULL;
}
-ALSeqFile *get_audio_file_header(s32 poolIdx) {
+ALSeqFile *get_audio_file_header(s32 poolIdx)
+{
ALSeqFile *ret;
- switch (poolIdx) {
+ switch (poolIdx)
+ {
default:
ret = NULL;
break;
@@ -735,7 +856,8 @@ ALSeqFile *get_audio_file_header(s32 poolIdx) {
return ret;
}
-void patch_audio_bank(s32 bankId, struct AudioBank *mem, struct PatchStruct *patchInfo) {
+void patch_audio_bank(s32 bankId, struct AudioBank *mem, struct PatchStruct *patchInfo)
+{
struct Instrument *instrument;
void **itInstrs;
struct Instrument **end;
@@ -745,50 +867,61 @@ void patch_audio_bank(s32 bankId, struct AudioBank *mem, struct PatchStruct *pat
s32 numDrums;
s32 numInstruments;
-#define BASE_OFFSET(x, base) (void *)((uintptr_t) (x) + (uintptr_t) base)
-#define PATCH(x, base) (patched = BASE_OFFSET(x, base))
-#define PATCH_MEM(x) x = PATCH(x, mem)
+ #define BASE_OFFSET(x, base) (void *)((uintptr_t) (x) + (uintptr_t) base)
+ #define PATCH(x, base) (patched = BASE_OFFSET(x, base))
+ #define PATCH_MEM(x) x = PATCH(x, mem)
numDrums = gCtlEntries[bankId].numDrums;
numInstruments = gCtlEntries[bankId].numInstruments;
- itInstrs = (void **) mem->drums;
- if (mem->drums) {
+ itInstrs = (void **)mem->drums;
+ if (mem->drums)
+ {
}
- if (itInstrs != NULL && numDrums != 0) {
- if (1) {
+ if (itInstrs != NULL && numDrums != 0)
+ {
+ if (1)
+ {
mem->drums = PATCH(itInstrs, mem);
}
- for (i = 0; i < numDrums; i++) {
+ for (i = 0; i < numDrums; i++)
+ {
patched = mem->drums[i];
- if (patched != NULL) {
+ if (patched != NULL)
+ {
drum = PATCH(patched, mem);
mem->drums[i] = drum;
- if (drum->loaded == 0) {
+ if (drum->loaded == 0)
+ {
patch_sound(&drum->sound, mem, patchInfo);
patched = drum->envelope;
drum->envelope = BASE_OFFSET(patched, mem);
drum->loaded = 1;
}
-
}
}
}
- if (numInstruments > 0) {
- itInstrs = (void **) mem->instruments;
- end = numInstruments + (struct Instrument **) itInstrs;
+ if (numInstruments > 0)
+ {
+ itInstrs = (void **)mem->instruments;
+ end = numInstruments + (struct Instrument **)itInstrs;
- do {
- if (*itInstrs != NULL) {
+ do
+ {
+ if (*itInstrs != NULL)
+ {
*itInstrs = BASE_OFFSET(*itInstrs, mem);
instrument = *itInstrs;
- if (instrument->loaded == 0) {
- if (instrument->normalRangeLo != 0) {
+ if (instrument->loaded == 0)
+ {
+ if (instrument->normalRangeLo != 0)
+ {
patch_sound(&instrument->lowNotesSound, mem, patchInfo);
}
patch_sound(&instrument->normalNotesSound, mem, patchInfo);
- if (instrument->normalRangeHi != 0x7F) {
+ if (instrument->normalRangeHi != 0x7F)
+ {
patch_sound(&instrument->highNotesSound, mem, patchInfo);
}
patched = instrument->envelope;
@@ -797,43 +930,48 @@ void patch_audio_bank(s32 bankId, struct AudioBank *mem, struct PatchStruct *pat
instrument->loaded = 1;
}
}
- itInstrs = (void **) ((struct Instrument **) itInstrs) + 1;
- } while ((struct Instrument **) itInstrs != ((void) 0, end)); //! This is definitely fake
+ itInstrs = (void **)((struct Instrument **)itInstrs) + 1;
+ }
+ while ((struct Instrument **)itInstrs != ((void)0, end)); //! This is definitely fake
}
gCtlEntries[bankId].drums = mem->drums;
gCtlEntries[bankId].instruments = mem->instruments;
-#undef PATCH_MEM
-#undef PATCH
-#undef BASE_OFFSET
+ #undef PATCH_MEM
+ #undef PATCH
+ #undef BASE_OFFSET
}
extern char shindouDebugPrint81[]; // "FastCopy"
extern char shindouDebugPrint82[]; // "FastCopy"
-void func_sh_802f3c38(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 medium) {
+void func_sh_802f3c38(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 medium)
+{
nbytes = ALIGN16(nbytes);
osInvalDCache(vAddr, nbytes);
-again:
- if (gAudioLoadLockSH != 0) {
+again: if (gAudioLoadLockSH != 0)
+ {
goto again;
}
- if (nbytes >= 0x400U) {
+ if (nbytes >= 0x400U)
+ {
func_sh_802f3dd0(&gAudioDmaIoMesg, 1, 0, devAddr, vAddr, 0x400, &gAudioDmaMesgQueue, medium, shindouDebugPrint81);
osRecvMesg(&gAudioDmaMesgQueue, NULL, 1);
nbytes = nbytes - 0x400;
devAddr = devAddr + 0x400;
- vAddr = (u8*)vAddr + 0x400;
+ vAddr = (u8 *)vAddr + 0x400;
goto again;
}
- if (nbytes != 0) {
+ if (nbytes != 0)
+ {
func_sh_802f3dd0(&gAudioDmaIoMesg, 1, 0, devAddr, vAddr, nbytes, &gAudioDmaMesgQueue, medium, shindouDebugPrint82);
osRecvMesg(&gAudioDmaMesgQueue, NULL, 1);
}
}
-void func_sh_802f3d78(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3) {
+void func_sh_802f3d78(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3)
+{
uintptr_t sp1C;
sp1C = devAddr;
@@ -841,12 +979,15 @@ void func_sh_802f3d78(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3) {
func_sh_802f3ed4(func_sh_802f3ec4(arg3, &sp1C), sp1C, vAddr, nbytes);
}
-s32 func_sh_802f3dd0(OSIoMesg *m, s32 pri, s32 direction, uintptr_t devAddr, void *dramAddr, s32 size, OSMesgQueue *retQueue, s32 medium, UNUSED const char *reason) {
+s32 func_sh_802f3dd0(OSIoMesg *m, s32 pri, s32 direction, uintptr_t devAddr, void *dramAddr, s32 size, OSMesgQueue *retQueue, s32 medium, UNUSED const char *reason)
+{
OSPiHandle *handle;
- if (gAudioLoadLockSH >= 0x11U) {
+ if (gAudioLoadLockSH >= 0x11U)
+ {
return -1;
}
- switch (medium) {
+ switch (medium)
+ {
case 2:
handle = osCartRomInit();
break;
@@ -856,7 +997,8 @@ s32 func_sh_802f3dd0(OSIoMesg *m, s32 pri, s32 direction, uintptr_t devAddr, voi
default:
return 0;
}
- if ((size & 0xf) != 0) {
+ if ((size & 0xf) != 0)
+ {
size = ALIGN16(size);
}
m->hdr.pri = pri;
@@ -869,19 +1011,23 @@ s32 func_sh_802f3dd0(OSIoMesg *m, s32 pri, s32 direction, uintptr_t devAddr, voi
return 0;
}
-s32 func_sh_802f3ec4(UNUSED s32 arg0, UNUSED uintptr_t *arg1) {
+s32 func_sh_802f3ec4(UNUSED s32 arg0, UNUSED uintptr_t *arg1)
+{
return 0;
}
-void func_sh_802f3ed4(UNUSED s32 arg0, UNUSED s32 arg1, UNUSED void *vAddr, UNUSED size_t nbytes) {
+void func_sh_802f3ed4(UNUSED s32 arg0, UNUSED s32 arg1, UNUSED void *vAddr, UNUSED size_t nbytes)
+{
}
-void *func_sh_802f3ee8(s32 poolIdx, s32 idx) {
+void *func_sh_802f3ee8(s32 poolIdx, s32 idx)
+{
s32 temp;
return func_sh_802f3764(poolIdx, idx, &temp);
}
-void *func_802f3f08(s32 poolIdx, s32 idx, s32 numChunks, s32 arg3, OSMesgQueue *retQueue) {
+void *func_802f3f08(s32 poolIdx, s32 idx, s32 numChunks, s32 arg3, OSMesgQueue *retQueue)
+{
s32 size;
ALSeqFile *f;
void *vAddr;
@@ -890,54 +1036,64 @@ void *func_802f3f08(s32 poolIdx, s32 idx, s32 numChunks, s32 arg3, OSMesgQueue *
uintptr_t devAddr;
s32 loadStatus;
- switch (poolIdx) {
+ switch (poolIdx)
+ {
case 0:
- if (gSeqLoadStatus[idx] == SOUND_LOAD_STATUS_IN_PROGRESS) {
+ if (gSeqLoadStatus[idx] == SOUND_LOAD_STATUS_IN_PROGRESS)
+ {
return 0;
}
break;
case 1:
- if (gBankLoadStatus[idx] == SOUND_LOAD_STATUS_IN_PROGRESS) {
+ if (gBankLoadStatus[idx] == SOUND_LOAD_STATUS_IN_PROGRESS)
+ {
return 0;
}
break;
case 2:
- if (gUnkLoadStatus[idx] == SOUND_LOAD_STATUS_IN_PROGRESS) {
+ if (gUnkLoadStatus[idx] == SOUND_LOAD_STATUS_IN_PROGRESS)
+ {
return 0;
}
break;
-
}
vAddr = get_bank_or_seq_wrapper(poolIdx, idx);
- if (vAddr != NULL) {
+ if (vAddr != NULL)
+ {
loadStatus = 2;
- osSendMesg(retQueue, (OSMesg) (arg3 << 0x18), 0);
- } else {
+ osSendMesg(retQueue, (OSMesg)(arg3 << 0x18), 0);
+ }
+ else
+ {
f = get_audio_file_header(poolIdx);
size = f->seqArray[idx].len;
size = ALIGN16(size);
medium = f->seqArray[idx].medium;
sp18 = f->seqArray[idx].magic;
- devAddr = (uintptr_t) f->seqArray[idx].offset;
+ devAddr = (uintptr_t)f->seqArray[idx].offset;
loadStatus = 2;
- switch (sp18) {
+ switch (sp18)
+ {
case 0:
vAddr = unk_pool1_alloc(poolIdx, idx, size);
- if (vAddr == NULL) {
+ if (vAddr == NULL)
+ {
return vAddr;
}
loadStatus = SOUND_LOAD_STATUS_5;
break;
case 1:
vAddr = alloc_bank_or_seq(poolIdx, size, 1, idx);
- if (vAddr == NULL) {
+ if (vAddr == NULL)
+ {
return vAddr;
}
break;
case 2:
vAddr = alloc_bank_or_seq(poolIdx, size, 0, idx);
- if (vAddr == NULL) {
+ if (vAddr == NULL)
+ {
return vAddr;
}
break;
@@ -945,7 +1101,8 @@ void *func_802f3f08(s32 poolIdx, s32 idx, s32 numChunks, s32 arg3, OSMesgQueue *
case 4:
case 3:
vAddr = alloc_bank_or_seq(poolIdx, size, 2, idx);
- if (vAddr == NULL) {
+ if (vAddr == NULL)
+ {
return vAddr;
}
break;
@@ -955,21 +1112,25 @@ void *func_802f3f08(s32 poolIdx, s32 idx, s32 numChunks, s32 arg3, OSMesgQueue *
loadStatus = SOUND_LOAD_STATUS_IN_PROGRESS;
}
- switch (poolIdx) {
+ switch (poolIdx)
+ {
case 0:
- if (gSeqLoadStatus[idx] != SOUND_LOAD_STATUS_5) {
+ if (gSeqLoadStatus[idx] != SOUND_LOAD_STATUS_5)
+ {
gSeqLoadStatus[idx] = loadStatus;
}
break;
case 1:
- if (gBankLoadStatus[idx] != SOUND_LOAD_STATUS_5) {
+ if (gBankLoadStatus[idx] != SOUND_LOAD_STATUS_5)
+ {
gBankLoadStatus[idx] = loadStatus;
}
break;
case 2:
- if (gUnkLoadStatus[idx] != SOUND_LOAD_STATUS_5) {
+ if (gUnkLoadStatus[idx] != SOUND_LOAD_STATUS_5)
+ {
gUnkLoadStatus[idx] = loadStatus;
}
break;
@@ -978,7 +1139,8 @@ void *func_802f3f08(s32 poolIdx, s32 idx, s32 numChunks, s32 arg3, OSMesgQueue *
return vAddr;
}
-void func_sh_802f41e4(s32 audioResetStatus) {
+void func_sh_802f41e4(s32 audioResetStatus)
+{
func_sh_802f4a4c(audioResetStatus);
func_sh_802f573c(audioResetStatus);
func_sh_802f4dcc(audioResetStatus);
@@ -986,24 +1148,25 @@ void func_sh_802f41e4(s32 audioResetStatus) {
#if defined(VERSION_SH)
u8 gShindouSoundBanksHeader[] = {
-#include "sound/ctl_header.inc.c"
+ #include "sound/ctl_header.inc.c"
};
u8 gBankSetsData[] = {
-#include "sound/bank_sets.inc.c"
+ #include "sound/bank_sets.inc.c"
};
u8 gShindouSampleBanksHeader[] = {
-#include "sound/tbl_header.inc.c"
+ #include "sound/tbl_header.inc.c"
};
u8 gShindouSequencesHeader[] = {
-#include "sound/sequences_header.inc.c"
+ #include "sound/sequences_header.inc.c"
};
#endif
// (void) must be omitted from parameters
-void audio_init() {
+void audio_init()
+{
UNUSED s8 pad[0x34];
s32 i, j, k;
s32 lim;
@@ -1014,55 +1177,56 @@ void audio_init() {
gAudioLoadLockSH = 0;
- for (i = 0; i < gAudioHeapSize / 8; i++) {
- ((u64 *) gAudioHeap)[i] = 0;
+ for (i = 0; i < gAudioHeapSize / 8; i++)
+ {
+ ((u64 *)gAudioHeap)[i] = 0;
}
#ifdef TARGET_N64
- // It seems boot.s doesn't clear the .bss area for audio, so do it here.
- lim = ((uintptr_t) &gAudioGlobalsEndMarker - (uintptr_t) &gAudioGlobalsStartMarker) / 8;
- ptr64 = &gAudioGlobalsStartMarker;
- for (k = lim; k >= 0; k--) {
+// It seems boot.s doesn't clear the .bss area for audio, so do it here.
+lim= ((uintptr_t)&gAudioGlobalsEndMarker- (uintptr_t) &gAudioGlobalsStartMarker) / 8;
+ptr64=&gAudioGlobalsStartMarker;
+ for (k = lim; k>= 0; k--) {
*ptr64++ = 0;
}
#endif
- D_EU_802298D0 = 16.713f;
- gRefreshRate = 60;
- port_eu_init();
+D_EU_802298D0=16.713f;
+gRefreshRate=60;
+port_eu_init();
#ifdef TARGET_N64
- eu_stubbed_printf_3("Clear Workarea %x -%x size %x \n",
- (uintptr_t) &gAudioGlobalsStartMarker,
+eu_stubbed_printf_3 ("Clear Workarea %x -%x size %x \n",
+(uintptr_t) &gAudioGlobalsStartMarker,
(uintptr_t) &gAudioGlobalsEndMarker,
- (uintptr_t) &gAudioGlobalsEndMarker - (uintptr_t) &gAudioGlobalsStartMarker
+ (uintptr_t) &gAudioGlobalsEndMarker- (uintptr_t) &gAudioGlobalsStartMarker
);
#endif
- eu_stubbed_printf_1("AudioHeap is %x\n", gAudioHeapSize);
+eu_stubbed_printf_1 ("AudioHeap is %x\n", gAudioHeapSize);
- for (i = 0; i < NUMAIBUFFERS; i++) {
+ for (i =0; iseqCount;
- patch_seq_file(gSeqFileHeader, gMusicData, D_SH_80315EF4);
- patch_seq_file(gAlCtlHeader, gSoundDataADSR, D_SH_80315EF8);
- patch_seq_file(gAlTbl, gSoundDataRaw, D_SH_80315EFC);
- seqCount = gAlCtlHeader->seqCount;
- gCtlEntries = sound_alloc_uninitialized(&gAudioInitPool, seqCount * sizeof(struct CtlEntry));
- for (i = 0; i < seqCount; i++) {
+// Load headers for sounds and sequences
+gSeqFileHeader= (ALSeqFile *) gShindouSequencesHeader;
+gAlCtlHeader= (ALSeqFile *) gShindouSoundBanksHeader;
+gAlTbl= (ALSeqFile *) gShindouSampleBanksHeader;
+gAlBankSets= gBankSetsData;
+gSequenceCount= (s16) gSeqFileHeader->seqCount;
+patch_seq_file(gSeqFileHeader, gMusicData, D_SH_80315EF4);
+patch_seq_file(gAlCtlHeader, gSoundDataADSR, D_SH_80315EF8);
+patch_seq_file(gAlTbl, gSoundDataRaw, D_SH_80315EFC);
+seqCount= gAlCtlHeader->seqCount;
+gCtlEntries= sound_alloc_uninitialized(&gAudioInitPool, seqCount *sizeof(struct CtlEntry));
+ for (i =0; iseqArray[i].ctl.as_s16.bankAndFf >> 8) & 0xff);
gCtlEntries[i].bankId2 = (u8) (gAlCtlHeader->seqArray[i].ctl.as_s16.bankAndFf & 0xff);
gCtlEntries[i].numInstruments = (u8) ((gAlCtlHeader->seqArray[i].ctl.as_s16.numInstrumentsAndDrums >> 8) & 0xff);
gCtlEntries[i].numDrums = (u8) (gAlCtlHeader->seqArray[i].ctl.as_s16.numInstrumentsAndDrums & 0xff);
}
- data = sound_alloc_uninitialized(&gAudioInitPool, D_SH_80315EF0);
- if (data == NULL) {
+data= sound_alloc_uninitialized(&gAudioInitPool, D_SH_80315EF0);
+ if (data== NULL) {
D_SH_80315EF0 = 0;
}
- sound_alloc_pool_init(&gUnkPool1.pool, data, D_SH_80315EF0);
- init_sequence_players();
+sound_alloc_pool_init (&gUnkPool1.pool, data, D_SH_80315EF0);
+init_sequence_players();
}
-s32 func_sh_802f47c8(s32 bankId, u8 idx, s8 *io) {
+s32 func_sh_802f47c8(s32 bankId, u8 idx, s8 *io)
+{
struct AudioBankSample *sample = func_sh_802f4978(bankId, idx);
struct PendingDmaSample *temp;
- if (sample == NULL) {
+ if (sample == NULL)
+ {
*io = 0;
return -1;
}
- if (sample->medium == 0) {
+ if (sample->medium == 0)
+ {
*io = 2;
return 0;
}
temp = &D_SH_80343D00.arr[D_SH_80343D00.someIndex];
- if (temp->state == 3) {
+ if (temp->state == 3)
+ {
temp->state = 0;
}
temp->sample = *sample;
temp->io = io;
temp->vAddr = func_sh_802f1d40(sample->size, bankId, sample->sampleAddr, sample->medium);
- if (temp->vAddr == NULL) {
- if (sample->medium == 1 || sample->codec == CODEC_SKIP) {
+ if (temp->vAddr == NULL)
+ {
+ if (sample->medium == 1 || sample->codec == CODEC_SKIP)
+ {
*io = 0;
return -1;
- } else {
+ }
+ else
+ {
*io = 3;
return -1;
}
}
temp->state = 1;
temp->remaining = ALIGN16(sample->size);
- temp->resultSampleAddr = (u8 *) temp->vAddr;
- temp->devAddr = (uintptr_t) sample->sampleAddr;
+ temp->resultSampleAddr = (u8 *)temp->vAddr;
+ temp->devAddr = (uintptr_t)sample->sampleAddr;
temp->medium = sample->medium;
temp->bankId = bankId;
temp->idx = idx;
@@ -1142,20 +1314,26 @@ s32 func_sh_802f47c8(s32 bankId, u8 idx, s8 *io) {
return 0;
}
-struct AudioBankSample *func_sh_802f4978(s32 bankId, s32 idx) {
+struct AudioBankSample *func_sh_802f4978(s32 bankId, s32 idx)
+{
struct Drum *drum;
struct Instrument *inst;
struct AudioBankSample *ret;
- if (idx < 128) {
+ if (idx < 128)
+ {
inst = get_instrument_inner(bankId, idx);
- if (inst == 0) {
+ if (inst == 0)
+ {
return NULL;
}
ret = inst->normalNotesSound.sample;
- } else {
+ }
+ else
+ {
drum = get_drum(bankId, idx - 128);
- if (drum == 0) {
+ if (drum == 0)
+ {
return NULL;
}
ret = drum->sound.sample;
@@ -1163,19 +1341,23 @@ struct AudioBankSample *func_sh_802f4978(s32 bankId, s32 idx) {
return ret;
}
-void stub_sh_802f49dc(void) {
+void stub_sh_802f49dc(void)
+{
}
-void func_sh_802f49e4(struct PendingDmaSample *arg0) {
+void func_sh_802f49e4(struct PendingDmaSample *arg0)
+{
struct AudioBankSample *sample = func_sh_802f4978(arg0->bankId, arg0->idx);
- if (sample != NULL) {
+ if (sample != NULL)
+ {
arg0->sample = *sample;
sample->sampleAddr = arg0->resultSampleAddr;
sample->medium = 0;
}
}
-void func_sh_802f4a4c(s32 audioResetStatus) {
+void func_sh_802f4a4c(s32 audioResetStatus)
+{
ALSeqFile *alTbl;
struct PendingDmaSample *entry;
@@ -1183,37 +1365,51 @@ void func_sh_802f4a4c(s32 audioResetStatus) {
alTbl = gAlTbl;
- for (i = 0; i < 2; i++) {
+ for (i = 0; i < 2; i++)
+ {
entry = &D_SH_80343D00.arr[i];
- switch (entry->state) {
+ switch (entry->state)
+ {
case 2:
osRecvMesg(&entry->queue, NULL, 1);
- if (audioResetStatus != 0) {
+ if (audioResetStatus != 0)
+ {
entry->state = 3;
break;
}
- // fallthrough
+ // fallthrough
case 1:
entry->state = 2;
- if (entry->remaining == 0) {
+ if (entry->remaining == 0)
+ {
func_sh_802f49e4(entry);
entry->state = 3;
*entry->io = 1;
- } else if (entry->remaining < 0x1000) {
- if (entry->medium == 1) {
+ }
+ else if (entry->remaining < 0x1000)
+ {
+ if (entry->medium == 1)
+ {
func_sh_802f4c5c(entry->devAddr, entry->vAddr, entry->remaining, alTbl->unk2);
- } else {
+ }
+ else
+ {
func_sh_802f4bd8(entry, entry->remaining);
}
entry->remaining = 0;
- } else {
- if (entry->medium == 1) {
+ }
+ else
+ {
+ if (entry->medium == 1)
+ {
func_sh_802f4c5c(entry->devAddr, entry->vAddr, 0x1000, alTbl->unk2);
- } else {
+ }
+ else
+ {
func_sh_802f4bd8(entry, 0x1000);
}
- entry->remaining = (s32) (entry->remaining - 0x1000);
- entry->vAddr = (u8 *) entry->vAddr + 0x1000;
+ entry->remaining = (s32)(entry->remaining - 0x1000);
+ entry->vAddr = (u8 *)entry->vAddr + 0x1000;
entry->devAddr = entry->devAddr + 0x1000;
}
break;
@@ -1222,13 +1418,15 @@ void func_sh_802f4a4c(s32 audioResetStatus) {
}
extern char shindouDebugPrint102[]; // "SLOWCOPY"
-void func_sh_802f4bd8(struct PendingDmaSample *arg0, s32 len) { // len must be signed
+void func_sh_802f4bd8(struct PendingDmaSample *arg0, s32 len)
+{ // len must be signed
osInvalDCache(arg0->vAddr, len);
osCreateMesgQueue(&arg0->queue, arg0->mesgs, 1);
func_sh_802f3dd0(&arg0->ioMesg, 0, 0, arg0->devAddr, arg0->vAddr, len, &arg0->queue, arg0->medium, shindouDebugPrint102);
}
-void func_sh_802f4c5c(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3) {
+void func_sh_802f4c5c(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3)
+{
uintptr_t sp1C;
sp1C = devAddr;
@@ -1236,17 +1434,21 @@ void func_sh_802f4c5c(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3) {
func_sh_802f3ed4(func_sh_802f3ec4(arg3, &sp1C), sp1C, vAddr, nbytes);
}
-struct PendingDmaAudioBank *func_sh_802f4cb4(uintptr_t devAddr, void *vAddr, s32 size, s32 medium, s32 numChunks, OSMesgQueue *retQueue, s32 encodedInfo) {
+struct PendingDmaAudioBank *func_sh_802f4cb4(uintptr_t devAddr, void *vAddr, s32 size, s32 medium, s32 numChunks, OSMesgQueue *retQueue, s32 encodedInfo)
+{
struct PendingDmaAudioBank *item;
s32 i;
- for (i = 0; i < ARRAY_COUNT(sPendingDmaAudioBanks); i++) {
- if (sPendingDmaAudioBanks[i].inProgress == 0) {
+ for (i = 0; i < ARRAY_COUNT(sPendingDmaAudioBanks); i++)
+ {
+ if (sPendingDmaAudioBanks[i].inProgress == 0)
+ {
item = &sPendingDmaAudioBanks[i];
break;
}
}
- if (i == ARRAY_COUNT(sPendingDmaAudioBanks)) {
+ if (i == ARRAY_COUNT(sPendingDmaAudioBanks))
+ {
return NULL;
}
@@ -1255,11 +1457,15 @@ struct PendingDmaAudioBank *func_sh_802f4cb4(uintptr_t devAddr, void *vAddr, s32
item->audioBank = vAddr;
item->vAddr = vAddr;
item->remaining = size;
- if (numChunks == 0) {
+ if (numChunks == 0)
+ {
item->transferSize = 0x1000;
- } else {
+ }
+ else
+ {
item->transferSize = ((size / numChunks) + 0xFF) & ~0xFF;
- if (item->transferSize < 0x100) {
+ if (item->transferSize < 0x100)
+ {
item->transferSize = 0x100;
}
}
@@ -1271,19 +1477,24 @@ struct PendingDmaAudioBank *func_sh_802f4cb4(uintptr_t devAddr, void *vAddr, s32
return item;
}
-void func_sh_802f4dcc(s32 audioResetStatus) {
+void func_sh_802f4dcc(s32 audioResetStatus)
+{
s32 i;
- if (gAudioLoadLockSH != 1) {
- for (i = 0; i < ARRAY_COUNT(sPendingDmaAudioBanks); i++) {
- if (sPendingDmaAudioBanks[i].inProgress == 1) {
+ if (gAudioLoadLockSH != 1)
+ {
+ for (i = 0; i < ARRAY_COUNT(sPendingDmaAudioBanks); i++)
+ {
+ if (sPendingDmaAudioBanks[i].inProgress == 1)
+ {
func_sh_802f4e50(&sPendingDmaAudioBanks[i], audioResetStatus);
}
}
}
}
-void func_sh_802f4e50(struct PendingDmaAudioBank *audioBank, s32 audioResetStatus) {
+void func_sh_802f4e50(struct PendingDmaAudioBank *audioBank, s32 audioResetStatus)
+{
ALSeqFile *alSeqFile;
u32 *encodedInfo;
OSMesg mesg;
@@ -1293,35 +1504,42 @@ void func_sh_802f4e50(struct PendingDmaAudioBank *audioBank, s32 audioResetStatu
s32 bankId2;
struct PatchStruct patchStruct;
alSeqFile = gAlTbl;
- if (audioBank->timer >= 2) {
+ if (audioBank->timer >= 2)
+ {
audioBank->timer--;
return;
}
- if (audioBank->timer == 1) {
+ if (audioBank->timer == 1)
+ {
audioBank->timer = 0;
- } else {
- if (audioResetStatus != 0) {
+ }
+ else
+ {
+ if (audioResetStatus != 0)
+ {
osRecvMesg(&audioBank->dmaRetQueue, NULL, OS_MESG_BLOCK);
audioBank->inProgress = 0;
return;
}
- if (osRecvMesg(&audioBank->dmaRetQueue, NULL, OS_MESG_NOBLOCK) == -1) {
+ if (osRecvMesg(&audioBank->dmaRetQueue, NULL, OS_MESG_NOBLOCK) == -1)
+ {
return;
}
}
encodedInfo = &audioBank->encodedInfo;
- if (audioBank->remaining == 0) {
- mesg = (OSMesg) audioBank->encodedInfo;
+ if (audioBank->remaining == 0)
+ {
+ mesg = (OSMesg)audioBank->encodedInfo;
#pragma GCC diagnostic push
#if defined(__clang__)
#pragma GCC diagnostic ignored "-Wself-assign"
#endif
- mesg = mesg; //! needs an extra read from mesg here to match...
+mesg= mesg; //! needs an extra read from mesg here to match...
#pragma GCC diagnostic pop
- temp = *encodedInfo;
- bankId = (temp >> 8) & 0xFF;
- switch ((u8) (temp >> 0x10)) {
+temp=*encodedInfo;
+bankId= (temp>> 8) & 0xFF;
+ switch ((u8) (temp>> 0x10)) {
case 0:
if (gSeqLoadStatus[bankId] != SOUND_LOAD_STATUS_5) {
gSeqLoadStatus[bankId] = (u8) (temp & 0xFF);
@@ -1354,10 +1572,10 @@ void func_sh_802f4e50(struct PendingDmaAudioBank *audioBank, s32 audioResetStatu
func_sh_802f5310(bankId, audioBank->audioBank, &patchStruct, 1);
break;
}
- mesg = (OSMesg) audioBank->encodedInfo;
- audioBank->inProgress = 0;
- osSendMesg(audioBank->retQueue, mesg, OS_MESG_NOBLOCK);
- } else if (audioBank->remaining < audioBank->transferSize) {
+mesg= (OSMesg) audioBank->encodedInfo;
+audioBank->inProgress=0;
+osSendMesg (audioBank->retQueue, mesg, OS_MESG_NOBLOCK);
+ } else if (audioBank->remainingtransferSize) {
if (audioBank->medium == 1) {
func_sh_802f517c(audioBank->devAddr, audioBank->vAddr, audioBank->remaining, alSeqFile->unk2);
} else {
@@ -1379,7 +1597,8 @@ void func_sh_802f4e50(struct PendingDmaAudioBank *audioBank, s32 audioResetStatu
}
extern char shindouDebugPrint110[]; // "BGCOPY"
-void func_sh_802f50ec(struct PendingDmaAudioBank *arg0, size_t len) {
+void func_sh_802f50ec(struct PendingDmaAudioBank *arg0, size_t len)
+{
len += 0xf;
len &= ~0xf;
osInvalDCache(arg0->vAddr, len);
@@ -1388,7 +1607,8 @@ void func_sh_802f50ec(struct PendingDmaAudioBank *arg0, size_t len) {
}
-void func_sh_802f517c(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3) {
+void func_sh_802f517c(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3)
+{
uintptr_t sp1C;
sp1C = devAddr;
@@ -1396,18 +1616,22 @@ void func_sh_802f517c(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3) {
func_sh_802f3ed4(func_sh_802f3ec4(arg3, &sp1C), sp1C, vAddr, nbytes);
}
-void patch_sound(struct AudioBankSound *sound, struct AudioBank *memBase, struct PatchStruct *patchInfo) {
+void patch_sound(struct AudioBankSound *sound, struct AudioBank *memBase, struct PatchStruct *patchInfo)
+{
struct AudioBankSample *sample;
void *patched;
-#define PATCH(x, base) (patched = (void *)((uintptr_t) (x) + (uintptr_t) base))
+ #define PATCH(x, base) (patched = (void *)((uintptr_t) (x) + (uintptr_t) base))
- if ((uintptr_t) sound->sample <= 0x80000000) {
+ if ((uintptr_t)sound->sample <= 0x80000000)
+ {
sample = sound->sample = PATCH(sound->sample, memBase);
- if (sample->size != 0 && sample->isPatched != TRUE) {
+ if (sample->size != 0 && sample->isPatched != TRUE)
+ {
sample->loop = PATCH(sample->loop, memBase);
sample->book = PATCH(sample->book, memBase);
- switch (sample->medium) {
+ switch (sample->medium)
+ {
case 0:
sample->sampleAddr = PATCH(sample->sampleAddr, patchInfo->baseAddr1);
sample->medium = patchInfo->medium1;
@@ -1422,17 +1646,19 @@ void patch_sound(struct AudioBankSound *sound, struct AudioBank *memBase, struct
break;
}
sample->isPatched = TRUE;
- if (sample->bit1 && sample->medium != 0) {
+ if (sample->bit1 && sample->medium != 0)
+ {
D_SH_8034EA88[D_SH_8034F688++] = sample;
}
}
}
-#undef PATCH
+ #undef PATCH
}
-BAD_RETURN(s32) func_sh_802f5310(s32 bankId, struct AudioBank *mem, struct PatchStruct *patchInfo, s32 arg3) {
+BAD_RETURN (s32) func_sh_802f5310(s32 bankId, struct AudioBank *mem, struct PatchStruct *patchInfo, s32 arg3)
+{
UNUSED u32 pad[2];
- u8 *addr;
+ u8 * addr;
UNUSED u32 pad1[3];
s32 sp4C;
struct AudioBankSample *temp_s0;
@@ -1441,32 +1667,44 @@ BAD_RETURN(s32) func_sh_802f5310(s32 bankId, struct AudioBank *mem, struct Patch
s32 temp;
sp4C = 0;
- if (D_SH_8034F68C != 0) {
+ if (D_SH_8034F68C != 0)
+ {
sp4C = 1;
- } else {
+ }
+ else
+ {
D_SH_80343CF0 = 0;
}
D_SH_8034F688 = 0;
patch_audio_bank(bankId, mem, patchInfo);
count = 0;
- for (i = 0; i < D_SH_8034F688; i++) {
+ for (i = 0; i < D_SH_8034F688; i++)
+ {
count += ALIGN16(D_SH_8034EA88[i]->size);
}
- for (i = 0; i < D_SH_8034F688; i++) {
- if (D_SH_8034F68C != 0x78) {
+ for (i = 0; i < D_SH_8034F688; i++)
+ {
+ if (D_SH_8034F68C != 0x78)
+ {
temp_s0 = D_SH_8034EA88[i];
- switch (arg3) {
+ switch (arg3)
+ {
case 0:
temp = temp_s0->medium = patchInfo->medium1;
- if (temp != 0) {
- if (temp_s0->size) {
+ if (temp != 0)
+ {
+ if (temp_s0->size)
+ {
}
addr = func_sh_802f1d90(temp_s0->size, patchInfo->bankId1, temp_s0->sampleAddr, temp_s0->medium);
- } else {
+ }
+ else
+ {
temp = temp_s0->medium = patchInfo->medium2;
- if (temp != 0) {
+ if (temp != 0)
+ {
addr = func_sh_802f1d90(temp_s0->size, patchInfo->bankId2, temp_s0->sampleAddr, temp_s0->medium);
}
}
@@ -1474,42 +1712,51 @@ BAD_RETURN(s32) func_sh_802f5310(s32 bankId, struct AudioBank *mem, struct Patch
case 1:
temp = temp_s0->medium = patchInfo->medium1;
- if (temp != 0) {
+ if (temp != 0)
+ {
addr = func_sh_802f1d40(temp_s0->size, patchInfo->bankId1, temp_s0->sampleAddr, temp_s0->medium);
- } else {
+ }
+ else
+ {
temp = temp_s0->medium = patchInfo->medium2;
- if (temp != 0) {
+ if (temp != 0)
+ {
addr = func_sh_802f1d40(temp_s0->size, patchInfo->bankId2, temp_s0->sampleAddr, temp_s0->medium);
}
}
break;
}
- switch ((uintptr_t) addr) {
+ switch ((uintptr_t)addr)
+ {
case 0:
break;
default:
- switch (arg3) {
- case 0:
- if (temp_s0->medium == 1) {
- func_sh_802f3d78((uintptr_t) temp_s0->sampleAddr, addr, temp_s0->size, gAlTbl->unk2);
- temp_s0->sampleAddr = addr;
- temp_s0->medium = 0;
- } else {
- func_sh_802f3c38((uintptr_t) temp_s0->sampleAddr, addr, temp_s0->size, temp_s0->medium);
- temp_s0->sampleAddr = addr;
- temp_s0->medium = 0;
- }
- break;
+ switch (arg3)
+ {
+ case 0:
+ if (temp_s0->medium == 1)
+ {
+ func_sh_802f3d78((uintptr_t)temp_s0->sampleAddr, addr, temp_s0->size, gAlTbl->unk2);
+ temp_s0->sampleAddr = addr;
+ temp_s0->medium = 0;
+ }
+ else
+ {
+ func_sh_802f3c38((uintptr_t)temp_s0->sampleAddr, addr, temp_s0->size, temp_s0->medium);
+ temp_s0->sampleAddr = addr;
+ temp_s0->medium = 0;
+ }
+ break;
- case 1:
- D_SH_8034EC88[D_SH_8034F68C].sample = temp_s0;
- D_SH_8034EC88[D_SH_8034F68C].ramAddr = addr;
- D_SH_8034EC88[D_SH_8034F68C].encodedInfo = (D_SH_8034F68C << 24) | 0xffffff;
- D_SH_8034EC88[D_SH_8034F68C].isFree = FALSE;
- D_SH_8034EC88[D_SH_8034F68C].endAndMediumIdentification = temp_s0->sampleAddr + temp_s0->size + temp_s0->medium;
- D_SH_8034F68C++;
- break;
- }
+ case 1:
+ D_SH_8034EC88[D_SH_8034F68C].sample = temp_s0;
+ D_SH_8034EC88[D_SH_8034F68C].ramAddr = addr;
+ D_SH_8034EC88[D_SH_8034F68C].encodedInfo = (D_SH_8034F68C << 24) | 0xffffff;
+ D_SH_8034EC88[D_SH_8034F68C].isFree = FALSE;
+ D_SH_8034EC88[D_SH_8034F68C].endAndMediumIdentification = temp_s0->sampleAddr + temp_s0->size + temp_s0->medium;
+ D_SH_8034F68C++;
+ break;
+ }
}
continue;
}
@@ -1517,11 +1764,12 @@ BAD_RETURN(s32) func_sh_802f5310(s32 bankId, struct AudioBank *mem, struct Patch
}
D_SH_8034F688 = 0;
- if (D_SH_8034F68C != 0 && sp4C == 0) {
+ if (D_SH_8034F68C != 0 && sp4C == 0)
+ {
temp_s0 = D_SH_8034EC88[D_SH_8034F68C - 1].sample;
temp = (temp_s0->size >> 12);
temp += 1;
- count = (uintptr_t) temp_s0->sampleAddr;
+ count = (uintptr_t)temp_s0->sampleAddr;
func_sh_802f4cb4(
count,
D_SH_8034EC88[D_SH_8034F68C - 1].ramAddr,
@@ -1533,38 +1781,46 @@ BAD_RETURN(s32) func_sh_802f5310(s32 bankId, struct AudioBank *mem, struct Patch
}
}
-s32 func_sh_802f573c(s32 audioResetStatus) {
+s32 func_sh_802f573c(s32 audioResetStatus)
+{
struct AudioBankSample *sample;
u32 idx;
- u8 *sampleAddr;
+ u8 * sampleAddr;
u32 size;
s32 unk;
- u8 *added;
+ u8 * added;
- if (D_SH_8034F68C > 0) {
- if (audioResetStatus != 0) {
- if (osRecvMesg(&gUnkQueue2, (OSMesg *) &idx, OS_MESG_NOBLOCK)){
+ if (D_SH_8034F68C > 0)
+ {
+ if (audioResetStatus != 0)
+ {
+ if (osRecvMesg(&gUnkQueue2, (OSMesg *)&idx, OS_MESG_NOBLOCK))
+ {
}
D_SH_8034F68C = 0;
return 0;
}
- if (osRecvMesg(&gUnkQueue2, (OSMesg *) &idx, OS_MESG_NOBLOCK) == -1) {
+ if (osRecvMesg(&gUnkQueue2, (OSMesg *)&idx, OS_MESG_NOBLOCK) == -1)
+ {
return 0;
}
idx >>= 0x18;
- if (D_SH_8034EC88[idx].isFree == FALSE) {
+ if (D_SH_8034EC88[idx].isFree == FALSE)
+ {
sample = D_SH_8034EC88[idx].sample;
added = (sample->sampleAddr + sample->size + sample->medium);
- if (added == D_SH_8034EC88[idx].endAndMediumIdentification) {
+ if (added == D_SH_8034EC88[idx].endAndMediumIdentification)
+ {
sample->sampleAddr = D_SH_8034EC88[idx].ramAddr;
sample->medium = 0;
}
D_SH_8034EC88[idx].isFree = TRUE;
}
-next:
- if (D_SH_8034F68C > 0) {
- if (D_SH_8034EC88[D_SH_8034F68C - 1].isFree == TRUE) {
+ next: if (D_SH_8034F68C > 0)
+ {
+ if (D_SH_8034EC88[D_SH_8034F68C - 1].isFree == TRUE)
+ {
D_SH_8034F68C--;
goto next;
}
@@ -1574,34 +1830,40 @@ next:
unk = size >> 0xC;
unk += 1;
added = ((sampleAddr + size) + sample->medium);
- if (added != D_SH_8034EC88[D_SH_8034F68C - 1].endAndMediumIdentification) {
+ if (added != D_SH_8034EC88[D_SH_8034F68C - 1].endAndMediumIdentification)
+ {
D_SH_8034EC88[D_SH_8034F68C - 1].isFree = TRUE;
D_SH_8034F68C--;
goto next;
}
size = sample->size;
- func_sh_802f4cb4((uintptr_t) sampleAddr, D_SH_8034EC88[D_SH_8034F68C - 1].ramAddr, size, sample->medium,
+ func_sh_802f4cb4((uintptr_t)sampleAddr, D_SH_8034EC88[D_SH_8034F68C - 1].ramAddr, size, sample->medium,
unk, &gUnkQueue2, D_SH_8034EC88[D_SH_8034F68C - 1].encodedInfo);
}
}
return 1;
}
-s32 func_sh_802f5900(struct AudioBankSample *sample, s32 numLoaded, struct AudioBankSample *arg2[]) {
+s32 func_sh_802f5900(struct AudioBankSample *sample, s32 numLoaded, struct AudioBankSample *arg2[])
+{
s32 i;
- for (i = 0; i < numLoaded; i++) {
- if (sample->sampleAddr == arg2[i]->sampleAddr) {
+ for (i = 0; i < numLoaded; i++)
+ {
+ if (sample->sampleAddr == arg2[i]->sampleAddr)
+ {
break;
}
}
- if (i == numLoaded) {
+ if (i == numLoaded)
+ {
arg2[numLoaded++] = sample;
}
return numLoaded;
}
-s32 func_sh_802f5948(s32 bankId, struct AudioBankSample *list[]) {
+s32 func_sh_802f5948(s32 bankId, struct AudioBankSample *list[])
+{
s32 i;
struct Drum *drum;
struct Instrument *inst;
@@ -1613,23 +1875,28 @@ s32 func_sh_802f5948(s32 bankId, struct AudioBankSample *list[]) {
numDrums = gCtlEntries[bankId].numDrums;
numInstruments = gCtlEntries[bankId].numInstruments;
- for (i = 0; i < numDrums; i++) {
+ for (i = 0; i < numDrums; i++)
+ {
drum = get_drum(bankId, i);
- if (drum == NULL) {
+ if (drum == NULL)
+ {
continue;
}
numLoaded = func_sh_802f5900(drum->sound.sample, numLoaded, list);
}
- for (i = 0; i < numInstruments; i++) {
+ for (i = 0; i < numInstruments; i++)
+ {
inst = get_instrument_inner(bankId, i);
- if (inst == NULL) {
+ if (inst == NULL)
+ {
continue;
-
}
- if (inst->normalRangeLo != 0) {
+ if (inst->normalRangeLo != 0)
+ {
numLoaded = func_sh_802f5900(inst->lowNotesSound.sample, numLoaded, list);
}
- if (inst->normalRangeHi != 127) {
+ if (inst->normalRangeHi != 127)
+ {
numLoaded = func_sh_802f5900(inst->highNotesSound.sample, numLoaded, list);
}
numLoaded = func_sh_802f5900(inst->normalNotesSound.sample, numLoaded, list);
diff --git a/src/decomp/audio/playback.c b/src/decomp/audio/playback.c
index ff42e76..312d1f9 100644
--- a/src/decomp/audio/playback.c
+++ b/src/decomp/audio/playback.c
@@ -24,73 +24,74 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, u8 pan, u8 reverbV
u8 strongLeft;
s32 smallPanIndex;
#ifdef VERSION_EU
- u16 unkMask = ~0x80;
+u16 unkMask = ~0x80;
#else
UNUSED u32 pad;
UNUSED u32 pad1;
- f32 velocity;
- u8 pan;
- u8 reverbVol;
- struct ReverbBitsData reverbBits;
+f32 velocity;
+u8 pan;
+u8 reverbVol;
+struct ReverbBitsData reverbBits;
#endif
#ifdef VERSION_SH
- note_set_resampling_rate(note, reverbInfo->freqScale);
- velocity = reverbInfo->velocity;
- pan = reverbInfo->pan;
- reverbVol = reverbInfo->reverbVol;
- reverbBits = reverbInfo->reverbBits.s;
- pan &= 0x7f;
+note_set_resampling_rate(note, reverbInfo->freqScale);
+velocity= reverbInfo->velocity;
+pan= reverbInfo->pan;
+reverbVol= reverbInfo->reverbVol;
+reverbBits= reverbInfo->reverbBits.s;
+pan&= 0x7f;
#else
- pan &= unkMask;
+pan&= unkMask;
#endif
- if (note->noteSubEu.stereoHeadsetEffects && gSoundMode == SOUND_MODE_HEADSET) {
+if (note->noteSubEu.stereoHeadsetEffects &&gSoundMode== SOUND_MODE_HEADSET) {
#ifdef VERSION_SH
- smallPanIndex = pan >> 1;
+smallPanIndex= pan>> 1;
#else
- smallPanIndex = pan >> 3;
+smallPanIndex= pan>> 3;
#endif
- if (smallPanIndex >= ARRAY_COUNT(gHeadsetPanQuantization)) {
+if (smallPanIndex>= ARRAY_COUNT (gHeadsetPanQuantization)) {
smallPanIndex = ARRAY_COUNT(gHeadsetPanQuantization) - 1;
}
- sub->headsetPanLeft = gHeadsetPanQuantization[smallPanIndex];
- sub->headsetPanRight = gHeadsetPanQuantization[ARRAY_COUNT(gHeadsetPanQuantization) - 1 - smallPanIndex];
- sub->stereoStrongRight = FALSE;
- sub->stereoStrongLeft = FALSE;
- sub->usesHeadsetPanEffects = TRUE;
+sub->headsetPanLeft= gHeadsetPanQuantization[smallPanIndex];
+sub->headsetPanRight= gHeadsetPanQuantization[ARRAY_COUNT(gHeadsetPanQuantization) - 1 - smallPanIndex];
+sub->stereoStrongRight= FALSE;
+sub->stereoStrongLeft= FALSE;
+sub->usesHeadsetPanEffects= TRUE;
- volLeft = gHeadsetPanVolume[pan];
- volRight = gHeadsetPanVolume[127 - pan];
- } else if (sub->stereoHeadsetEffects && gSoundMode == SOUND_MODE_STEREO) {
+volLeft= gHeadsetPanVolume[pan];
+volRight= gHeadsetPanVolume[127 - pan];
+ } else if (sub->stereoHeadsetEffects &&gSoundMode== SOUND_MODE_STEREO) {
#ifdef VERSION_SH
- strongRight = FALSE;
- strongLeft = FALSE;
- sub->headsetPanRight = 0;
- sub->headsetPanLeft = 0;
+strongRight= FALSE;
+strongLeft= FALSE;
+sub->headsetPanRight=0;
+sub->headsetPanLeft=0;
#else
- strongLeft = FALSE;
- strongRight = FALSE;
- sub->headsetPanLeft = 0;
- sub->headsetPanRight = 0;
+strongLeft= FALSE;
+strongRight= FALSE;
+sub->headsetPanLeft=0;
+sub->headsetPanRight=0;
#endif
- sub->usesHeadsetPanEffects = FALSE;
+sub->usesHeadsetPanEffects= FALSE;
- volLeft = gStereoPanVolume[pan];
- volRight = gStereoPanVolume[127 - pan];
- if (pan < 0x20) {
- strongLeft = TRUE;
- } else if (pan > 0x60) {
+volLeft= gStereoPanVolume[pan];
+volRight= gStereoPanVolume[127 - pan];
+ if (pan<0x20)
+{
+ strongLeft = TRUE;
+}else if (pan> 0x60) {
strongRight = TRUE;
}
- sub->stereoStrongRight = strongRight;
- sub->stereoStrongLeft = strongLeft;
+sub->stereoStrongRight= strongRight;
+sub->stereoStrongLeft= strongLeft;
#ifdef VERSION_SH
- switch (reverbBits.stereoHeadsetEffects) {
+switch (reverbBits.stereoHeadsetEffects) {
case 0:
sub->stereoStrongRight = reverbBits.strongRight;
sub->stereoStrongLeft = reverbBits.strongLeft;
@@ -110,7 +111,7 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, u8 pan, u8 reverbV
break;
}
#endif
- } else if (gSoundMode == SOUND_MODE_MONO) {
+} else if (gSoundMode== SOUND_MODE_MONO) {
volLeft = 0.707f;
volRight = 0.707f;
} else {
@@ -119,39 +120,41 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, u8 pan, u8 reverbV
}
#ifdef VERSION_SH
- if (velocity < 0.0f) {
- velocity = 0.0f;
- }
- if (velocity > 1.0f) {
+if (velocity<0.0f)
+{
+ velocity = 0.0f;
+}
+ if (velocity> 1.0f) {
velocity = 1.0f;
}
- sub->targetVolLeft = ((s32) (velocity * volLeft * 4095.999f));
- sub->targetVolRight = ((s32) (velocity * volRight * 4095.999f));
- sub->synthesisVolume = reverbInfo->synthesisVolume;
- sub->filter = reverbInfo->filter;
+sub->targetVolLeft= ((s32) (velocity * volLeft *4095.999f));
+sub->targetVolRight= ((s32) (velocity * volRight *4095.999f));
+sub->synthesisVolume= reverbInfo->synthesisVolume;
+sub->filter= reverbInfo->filter;
#else
- if (velocity < 0.0f) {
- stubbed_printf("Audio: setvol: volume minus %f\n", velocity);
- velocity = 0.0f;
- }
- if (velocity > 32767.f) {
+if (velocity<0.0f)
+{
+ stubbed_printf("Audio: setvol: volume minus %f\n", velocity);
+ velocity = 0.0f;
+}
+ if (velocity> 32767.f) {
stubbed_printf("Audio: setvol: volume overflow %f\n", velocity);
velocity = 32767.f;
}
- sub->targetVolLeft = ((s32) (velocity * volLeft) & 0xffff) >> 5;
- sub->targetVolRight = ((s32) (velocity * volRight) & 0xffff) >> 5;
+sub->targetVolLeft= ((s32) (velocity *volLeft) &0xffff) >> 5;
+sub->targetVolRight= ((s32) (velocity *volRight) &0xffff) >> 5;
#endif
- //! @bug for the change to UQ0.7, the if statement should also have been changed accordingly
- if (sub->reverbVol != reverbVol) {
+//! @bug for the change to UQ0.7, the if statement should also have been changed accordingly
+if (sub->reverbVol!= reverbVol) {
#ifdef VERSION_SH
- sub->reverbVol = reverbVol >> 1;
+sub->reverbVol= reverbVol>> 1;
#else
- sub->reverbVol = reverbVol;
+sub->reverbVol= reverbVol;
#endif
- sub->envMixerNeedsInit = TRUE;
+sub->envMixerNeedsInit= TRUE;
return;
}
@@ -168,26 +171,31 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, u8 pan, u8 reverbV
#define MIN_RESAMPLING_RATE 1.99996f
#endif
-void note_set_resampling_rate(struct Note *note, f32 resamplingRateInput) {
+void note_set_resampling_rate(struct Note *note, f32 resamplingRateInput)
+{
f32 resamplingRate = 0.0f;
struct NoteSubEu *tempSub = ¬e->noteSubEu;
#ifdef VERSION_EU
- if (resamplingRateInput < 0.0f) {
- stubbed_printf("Audio: setpitch: pitch minus %f\n", resamplingRateInput);
- resamplingRateInput = 0.0f;
- }
+if (resamplingRateInput<0.0f)
+{
+ stubbed_printf("Audio: setpitch: pitch minus %f\n", resamplingRateInput);
+ resamplingRateInput = 0.0f;
+}
#endif
- if (resamplingRateInput < 2.0f) {
- tempSub->hasTwoAdpcmParts = 0;
+if (resamplingRateInput<2.0f)
+{
+ tempSub->hasTwoAdpcmParts = 0;
- if (MIN_RESAMPLING_RATE < resamplingRateInput) {
- resamplingRate = MIN_RESAMPLING_RATE;
- } else {
- resamplingRate = resamplingRateInput;
- }
-
- } else {
+ if (MIN_RESAMPLING_RATE < resamplingRateInput)
+ {
+ resamplingRate = MIN_RESAMPLING_RATE;
+ }
+ else
+ {
+ resamplingRate = resamplingRateInput;
+ }
+}else {
tempSub->hasTwoAdpcmParts = 1;
if (2 * MIN_RESAMPLING_RATE < resamplingRateInput) {
resamplingRate = MIN_RESAMPLING_RATE;
@@ -195,75 +203,86 @@ void note_set_resampling_rate(struct Note *note, f32 resamplingRateInput) {
resamplingRate = resamplingRateInput * 0.5f;
}
}
- note->noteSubEu.resamplingRateFixedPoint = (s32) (resamplingRate * 32768.0f);
+note->noteSubEu.resamplingRateFixedPoint= (s32)(resamplingRate * 32768.0f);
}
#ifdef VERSION_EU
-struct AudioBankSound *instrument_get_audio_bank_sound(struct Instrument *instrument, s32 semitone) {
+struct AudioBankSound *instrument_get_audio_bank_sound(struct Instrument *instrument, s32 semitone)
+{
struct AudioBankSound *sound;
- if (semitone < instrument->normalRangeLo) {
+ if (semitone < instrument->normalRangeLo)
+ {
sound = &instrument->lowNotesSound;
- } else if (semitone <= instrument->normalRangeHi) {
+ }
+ else if (semitone <= instrument->normalRangeHi)
+ {
sound = &instrument->normalNotesSound;
- } else {
+ }
+ else
+ {
sound = &instrument->highNotesSound;
}
return sound;
}
-struct Instrument *get_instrument_inner(s32 bankId, s32 instId) {
+struct Instrument *get_instrument_inner(s32 bankId, s32 instId)
+{
struct Instrument *inst;
- if (IS_BANK_LOAD_COMPLETE(bankId) == FALSE) {
+ if (IS_BANK_LOAD_COMPLETE(bankId) == FALSE)
+ {
stubbed_printf("Audio: voiceman: No bank error %d\n", bankId);
gAudioErrorFlags = bankId + 0x10000000;
return NULL;
}
- if (instId >= gCtlEntries[bankId].numInstruments) {
+ if (instId >= gCtlEntries[bankId].numInstruments)
+ {
stubbed_printf("Audio: voiceman: progNo. overflow %d,%d\n",
- instId, gCtlEntries[bankId].numInstruments);
+ instId, gCtlEntries[bankId].numInstruments);
gAudioErrorFlags = ((bankId << 8) + instId) + 0x3000000;
return NULL;
}
inst = gCtlEntries[bankId].instruments[instId];
- if (inst == NULL) {
+ if (inst == NULL)
+ {
stubbed_printf("Audio: voiceman: progNo. undefined %d,%d\n", bankId, instId);
gAudioErrorFlags = ((bankId << 8) + instId) + 0x1000000;
return inst;
}
#ifdef VERSION_EU
- if (((uintptr_t) gBankLoadedPool.persistent.pool.start <= (uintptr_t) inst
- && (uintptr_t) inst <= (uintptr_t)(gBankLoadedPool.persistent.pool.start
- + gBankLoadedPool.persistent.pool.size))
- || ((uintptr_t) gBankLoadedPool.temporary.pool.start <= (uintptr_t) inst
- && (uintptr_t) inst <= (uintptr_t)(gBankLoadedPool.temporary.pool.start
- + gBankLoadedPool.temporary.pool.size))) {
+if (((uintptr_t) gBankLoadedPool.persistent.pool.start<= (uintptr_t) inst
+ &&(uintptr_t) inst<= (uintptr_t)(gBankLoadedPool.persistent.pool.start
+ + gBankLoadedPool.persistent.pool.size))
+ || ((uintptr_t) gBankLoadedPool.temporary.pool.start<= (uintptr_t) inst
+ &&(uintptr_t) inst<= (uintptr_t)(gBankLoadedPool.temporary.pool.start
+ + gBankLoadedPool.temporary.pool.size))) {
return inst;
}
- stubbed_printf("Audio: voiceman: BAD Voicepointer %x,%d,%d\n", inst, bankId, instId);
- gAudioErrorFlags = ((bankId << 8) + instId) + 0x2000000;
+stubbed_printf ("Audio: voiceman: BAD Voicepointer %x,%d,%d\n", inst, bankId, instId);
+gAudioErrorFlags= ((bankId<< 8) + instId) + 0x2000000;
return NULL;
#else
- return inst;
+return inst;
#endif
}
-struct Drum *get_drum(s32 bankId, s32 drumId) {
+struct Drum *get_drum(s32 bankId, s32 drumId)
+{
struct Drum *drum;
#ifdef VERSION_SH
- if (IS_BANK_LOAD_COMPLETE(bankId) == FALSE) {
+if (IS_BANK_LOAD_COMPLETE(bankId)== FALSE) {
stubbed_printf("Audio: voiceman: No bank error %d\n", bankId);
gAudioErrorFlags = bankId + 0x10000000;
return NULL;
}
#endif
- if (drumId >= gCtlEntries[bankId].numDrums) {
+if (drumId>= gCtlEntries [bankId].numDrums) {
stubbed_printf("Audio: voiceman: Percussion Overflow %d,%d\n",
drumId, gCtlEntries[bankId].numDrums);
gAudioErrorFlags = ((bankId << 8) + drumId) + 0x4000000;
@@ -271,14 +290,14 @@ struct Drum *get_drum(s32 bankId, s32 drumId) {
}
#ifndef NO_SEGMENTED_MEMORY
- if ((uintptr_t) gCtlEntries[bankId].drums < 0x80000000U) {
+if ((uintptr_t) gCtlEntries [bankId].drums<0x80000000U) {
stubbed_printf("Percussion Pointer Error\n");
return NULL;
}
#endif
- drum = gCtlEntries[bankId].drums[drumId];
- if (drum == NULL) {
+drum= gCtlEntries[bankId].drums [drumId];
+ if (drum== NULL) {
stubbed_printf("Audio: voiceman: Percpointer NULL %d,%d\n", bankId, drumId);
gAudioErrorFlags = ((bankId << 8) + drumId) + 0x5000000;
}
@@ -293,304 +312,364 @@ void note_init_for_layer(struct Note *note, struct SequenceChannelLayer *seqLaye
s32 note_init_for_layer(struct Note *note, struct SequenceChannelLayer *seqLayer);
#endif
-void note_init(struct Note *note) {
- if (note->parentLayer->adsr.releaseRate == 0) {
+void note_init(struct Note *note)
+{
+ if (note->parentLayer->adsr.releaseRate == 0)
+ {
adsr_init(¬e->adsr, note->parentLayer->seqChannel->adsr.envelope, ¬e->adsrVolScale);
- } else {
+ }
+ else
+ {
adsr_init(¬e->adsr, note->parentLayer->adsr.envelope, ¬e->adsrVolScale);
}
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
note->unkSH34 = 0;
-#endif
+ #endif
note->adsr.state = ADSR_STATE_INITIAL;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
note->noteSubEu = gDefaultNoteSub;
-#else
+ #else
note_init_volume(note);
note_enable(note);
-#endif
+ #endif
}
#if defined(VERSION_EU) || defined(VERSION_SH)
#define note_disable2 note_disable
-void note_disable(struct Note *note) {
- if (note->noteSubEu.needsInit == TRUE) {
+void note_disable(struct Note *note)
+{
+ if (note->noteSubEu.needsInit == TRUE)
+ {
note->noteSubEu.needsInit = FALSE;
}
#ifdef VERSION_EU
- else {
+else {
note_set_vel_pan_reverb(note, 0, 0x40, 0);
}
#endif
- note->priority = NOTE_PRIORITY_DISABLED;
+note->priority= NOTE_PRIORITY_DISABLED;
#ifdef VERSION_SH
- note->unkSH34 = 0;
+note->unkSH34=0;
#endif
- note->parentLayer = NO_LAYER;
- note->prevParentLayer = NO_LAYER;
- note->noteSubEu.enabled = FALSE;
- note->noteSubEu.finished = FALSE;
+note->parentLayer= NO_LAYER;
+note->prevParentLayer= NO_LAYER;
+note->noteSubEu.enabled= FALSE;
+note->noteSubEu.finished= FALSE;
#ifdef VERSION_SH
- note->adsr.state = ADSR_STATE_DISABLED;
- note->adsr.current = 0;
+note->adsr.state= ADSR_STATE_DISABLED;
+note->adsr.current=0;
#endif
}
#else
-void note_disable2(struct Note *note) {
+void note_disable2(struct Note *note)
+{
note_disable(note);
}
#endif // VERSION_EU || VERSION_SH
-void process_notes(void) {
+void process_notes(void)
+{
f32 scale;
-#ifndef VERSION_SH
+ #ifndef VERSION_SH
f32 frequency;
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #if defined(VERSION_JP) || defined(VERSION_US)
u8 reverbVol;
-#endif
+ #endif
f32 velocity;
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #if defined(VERSION_JP) || defined(VERSION_US)
f32 pan;
f32 cap;
-#endif
-#endif
+ #endif
+ #endif
struct Note *note;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
struct NotePlaybackState *playbackState;
struct NoteSubEu *noteSubEu;
-#ifndef VERSION_SH
+ #ifndef VERSION_SH
UNUSED u8 pad[12];
u8 reverbVol;
UNUSED u8 pad3;
u8 pan;
-#else
+ #else
UNUSED u8 pad[8];
struct ReverbInfo reverbInfo;
-#endif
+ #endif
u8 bookOffset;
-#endif
+ #endif
struct NoteAttributes *attributes;
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #if defined(VERSION_JP) || defined(VERSION_US)
struct AudioListItem *it;
-#endif
+ #endif
s32 i;
// Macro versions of audio_list_push_front and audio_list_remove.
// Should ideally be changed to use copt.
-#define PREPEND(item, head_arg) \
+ #define PREPEND(item, head_arg) \
((it = (item), it->prev != NULL) \
? it \
: (it->prev = (head_arg), it->next = (head_arg)->next, (head_arg)->next->prev = it, \
(head_arg)->next = it, (head_arg)->u.count++, it->pool = (head_arg)->pool, it))
-#define POP(item) \
+ #define POP(item) \
((it = (item), it->prev == NULL) \
? it \
: (it->prev->next = it->next, it->next->prev = it->prev, it->prev = NULL, it))
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
note = &gNotes[i];
-#if defined(VERSION_EU) || defined(VERSION_SH)
- playbackState = (struct NotePlaybackState *) ¬e->priority;
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ playbackState = (struct NotePlaybackState *)¬e->priority;
if (note->parentLayer != NO_LAYER) {
-#ifndef NO_SEGMENTED_MEMORY
- if ((uintptr_t) playbackState->parentLayer < 0x7fffffffU) {
- continue;
- }
-#endif
-#ifdef VERSION_SH
- if (note != playbackState->parentLayer->note && playbackState->unkSH34 == 0) {
- playbackState->adsr.action |= ADSR_ACTION_RELEASE;
- playbackState->adsr.fadeOutVel = gAudioBufferParameters.updatesPerFrameInv;
- playbackState->priority = 1;
- playbackState->unkSH34 = 2;
- goto d;
- } else if (!playbackState->parentLayer->enabled && playbackState->unkSH34 == 0 &&
- playbackState->priority >= 1) {
- // do nothing
- } else if (playbackState->parentLayer->seqChannel->seqPlayer == NULL) {
- sequence_channel_disable(playbackState->parentLayer->seqChannel);
- playbackState->priority = 1;
- playbackState->unkSH34 = 1;
- continue;
- } else if (playbackState->parentLayer->seqChannel->seqPlayer->muted &&
- (playbackState->parentLayer->seqChannel->muteBehavior
- & (MUTE_BEHAVIOR_STOP_NOTES))) {
- // do nothing
- } else {
- goto d;
- }
-
- seq_channel_layer_note_release(playbackState->parentLayer);
- audio_list_remove(¬e->listItem);
- audio_list_push_front(¬e->listItem.pool->decaying, ¬e->listItem);
+ #ifndef NO_SEGMENTED_MEMORY
+ if ((uintptr_t)playbackState->parentLayer < 0x7fffffffU)
+ {
+ continue;
+ }
+ #endif
+ #ifdef VERSION_SH
+ if (note != playbackState->parentLayer->note && playbackState->unkSH34 == 0)
+ {
+ playbackState->adsr.action |= ADSR_ACTION_RELEASE;
+ playbackState->adsr.fadeOutVel = gAudioBufferParameters.updatesPerFrameInv;
playbackState->priority = 1;
playbackState->unkSH34 = 2;
- } else if (playbackState->unkSH34 == 0 && playbackState->priority >= 1) {
- continue;
- }
-#else
- if (!playbackState->parentLayer->enabled && playbackState->priority >= NOTE_PRIORITY_MIN) {
- goto c;
- } else if (playbackState->parentLayer->seqChannel->seqPlayer == NULL) {
- eu_stubbed_printf_0("CAUTION:SUB IS SEPARATED FROM GROUP");
- sequence_channel_disable(playbackState->parentLayer->seqChannel);
- playbackState->priority = NOTE_PRIORITY_STOPPING;
- continue;
- } else if (playbackState->parentLayer->seqChannel->seqPlayer->muted) {
- if ((playbackState->parentLayer->seqChannel->muteBehavior
- & (MUTE_BEHAVIOR_STOP_SCRIPT | MUTE_BEHAVIOR_STOP_NOTES))) {
- goto c;
- }
- }
goto d;
- if (1) {
- c:
- seq_channel_layer_note_release(playbackState->parentLayer);
- audio_list_remove(¬e->listItem);
- audio_list_push_front(¬e->listItem.pool->decaying, ¬e->listItem);
- playbackState->priority = NOTE_PRIORITY_STOPPING;
- }
- } else if (playbackState->priority >= NOTE_PRIORITY_MIN) {
+ }
+ else if (!playbackState->parentLayer->enabled && playbackState->unkSH34 == 0 &&
+ playbackState->priority >= 1)
+ {
+ // do nothing
+ }
+ else if (playbackState->parentLayer->seqChannel->seqPlayer == NULL)
+ {
+ sequence_channel_disable(playbackState->parentLayer->seqChannel);
+ playbackState->priority = 1;
+ playbackState->unkSH34 = 1;
continue;
}
-#endif
- d:
- if (playbackState->priority != NOTE_PRIORITY_DISABLED) {
-#ifdef VERSION_SH
- if (1) {}
-#endif
- noteSubEu = ¬e->noteSubEu;
-#ifdef VERSION_SH
- if (playbackState->unkSH34 >= 1 || noteSubEu->finished) {
-#else
- if (playbackState->priority == NOTE_PRIORITY_STOPPING || noteSubEu->finished) {
-#endif
- if (playbackState->adsr.state == ADSR_STATE_DISABLED || noteSubEu->finished) {
- if (playbackState->wantedParentLayer != NO_LAYER) {
- note_disable(note);
- if (playbackState->wantedParentLayer->seqChannel != NULL) {
- note_init_for_layer(note, playbackState->wantedParentLayer);
- note_vibrato_init(note);
- audio_list_remove(¬e->listItem);
- audio_list_push_back(¬e->listItem.pool->active, ¬e->listItem);
- playbackState->wantedParentLayer = NO_LAYER;
- // don't skip
- } else {
- eu_stubbed_printf_0("Error:Wait Track disappear\n");
- note_disable(note);
- audio_list_remove(¬e->listItem);
- audio_list_push_back(¬e->listItem.pool->disabled, ¬e->listItem);
- playbackState->wantedParentLayer = NO_LAYER;
- goto skip;
- }
- } else {
- note_disable(note);
- audio_list_remove(¬e->listItem);
- audio_list_push_back(¬e->listItem.pool->disabled, ¬e->listItem);
- goto skip;
- }
+ else if (playbackState->parentLayer->seqChannel->seqPlayer->muted &&
+ (playbackState->parentLayer->seqChannel->muteBehavior
+ & (MUTE_BEHAVIOR_STOP_NOTES)))
+ {
+ // do nothing
+ }
+ else
+ {
+ goto d;
+ }
+
+ seq_channel_layer_note_release(playbackState->parentLayer);
+ audio_list_remove(¬e->listItem);
+ audio_list_push_front(¬e->listItem.pool->decaying, ¬e->listItem);
+ playbackState->priority = 1;
+ playbackState->unkSH34 = 2;
+ } else if (playbackState->unkSH34 == 0 && playbackState->priority >= 1)
+ {
+ continue;
+ }
+ #else
+ if (!playbackState->parentLayer->enabled && playbackState->priority >= NOTE_PRIORITY_MIN)
+ {
+ goto c;
+ }
+ else if (playbackState->parentLayer->seqChannel->seqPlayer == NULL)
+ {
+ eu_stubbed_printf_0("CAUTION:SUB IS SEPARATED FROM GROUP");
+ sequence_channel_disable(playbackState->parentLayer->seqChannel);
+ playbackState->priority = NOTE_PRIORITY_STOPPING;
+ continue;
+ }
+ else if (playbackState->parentLayer->seqChannel->seqPlayer->muted)
+ {
+ if ((playbackState->parentLayer->seqChannel->muteBehavior
+ & (MUTE_BEHAVIOR_STOP_SCRIPT | MUTE_BEHAVIOR_STOP_NOTES)))
+ {
+ goto c;
+ }
+ }
+ goto d;
+ if (1)
+ {
+ c: seq_channel_layer_note_release(playbackState->parentLayer);
+ audio_list_remove(¬e->listItem);
+ audio_list_push_front(¬e->listItem.pool->decaying, ¬e->listItem);
+ playbackState->priority = NOTE_PRIORITY_STOPPING;
+ }
+ } else if (playbackState->priority >= NOTE_PRIORITY_MIN)
+ {
+ continue;
+ }
+ #endif
+ d: if (playbackState->priority != NOTE_PRIORITY_DISABLED) {
+ #ifdef VERSION_SH
+ if (1)
+ {
+ }
+ #endif
+ noteSubEu = ¬e->noteSubEu;
+ #ifdef VERSION_SH
+ if (playbackState->unkSH34 >= 1 || noteSubEu->finished) {
+ #else
+ if (playbackState->priority == NOTE_PRIORITY_STOPPING || noteSubEu->finished) {
+ #endif
+ if (playbackState->adsr.state == ADSR_STATE_DISABLED || noteSubEu->finished)
+ {
+ if (playbackState->wantedParentLayer != NO_LAYER)
+ {
+ note_disable(note);
+ if (playbackState->wantedParentLayer->seqChannel != NULL)
+ {
+ note_init_for_layer(note, playbackState->wantedParentLayer);
+ note_vibrato_init(note);
+ audio_list_remove(¬e->listItem);
+ audio_list_push_back(¬e->listItem.pool->active, ¬e->listItem);
+ playbackState->wantedParentLayer = NO_LAYER;
+ // don't skip
}
-#ifndef VERSION_SH
- if (1) {
+ else
+ {
+ eu_stubbed_printf_0("Error:Wait Track disappear\n");
+ note_disable(note);
+ audio_list_remove(¬e->listItem);
+ audio_list_push_back(¬e->listItem.pool->disabled, ¬e->listItem);
+ playbackState->wantedParentLayer = NO_LAYER;
+ goto skip;
}
-#endif
- } else if (playbackState->adsr.state == ADSR_STATE_DISABLED) {
+ }
+ else
+ {
note_disable(note);
audio_list_remove(¬e->listItem);
audio_list_push_back(¬e->listItem.pool->disabled, ¬e->listItem);
goto skip;
}
-
- scale = adsr_update(&playbackState->adsr);
- note_vibrato_update(note);
- attributes = &playbackState->attributes;
-#ifdef VERSION_SH
- if (playbackState->unkSH34 == 1 || playbackState->unkSH34 == 2) {
- reverbInfo.freqScale = attributes->freqScale;
- reverbInfo.velocity = attributes->velocity;
- reverbInfo.pan = attributes->pan;
- reverbInfo.reverbVol = attributes->reverbVol;
- reverbInfo.reverbBits = attributes->reverbBits;
- reverbInfo.synthesisVolume = attributes->synthesisVolume;
- reverbInfo.filter = attributes->filter;
- bookOffset = noteSubEu->bookOffset;
- } else {
- reverbInfo.freqScale = playbackState->parentLayer->noteFreqScale;
- reverbInfo.velocity = playbackState->parentLayer->noteVelocity;
- reverbInfo.pan = playbackState->parentLayer->notePan;
- reverbInfo.reverbBits = playbackState->parentLayer->reverbBits;
- reverbInfo.reverbVol = playbackState->parentLayer->seqChannel->reverbVol;
- reverbInfo.synthesisVolume = playbackState->parentLayer->seqChannel->synthesisVolume;
- reverbInfo.filter = playbackState->parentLayer->seqChannel->filter;
- bookOffset = playbackState->parentLayer->seqChannel->bookOffset & 0x7;
- if (playbackState->parentLayer->seqChannel->seqPlayer->muted
- && (playbackState->parentLayer->seqChannel->muteBehavior & 8)) {
- reverbInfo.freqScale = 0.0f;
- reverbInfo.velocity = 0.0f;
- }
- }
-
- reverbInfo.freqScale *= playbackState->vibratoFreqScale * playbackState->portamentoFreqScale;
- reverbInfo.freqScale *= gAudioBufferParameters.resampleRate;
- reverbInfo.velocity *= scale;
- note_set_vel_pan_reverb(note, &reverbInfo);
-#else
- if (playbackState->priority == NOTE_PRIORITY_STOPPING) {
- frequency = attributes->freqScale;
- velocity = attributes->velocity;
- pan = attributes->pan;
- reverbVol = attributes->reverbVol;
- if (1) {
- }
- bookOffset = noteSubEu->bookOffset;
- } else {
- frequency = playbackState->parentLayer->noteFreqScale;
- velocity = playbackState->parentLayer->noteVelocity;
- pan = playbackState->parentLayer->notePan;
- reverbVol = playbackState->parentLayer->seqChannel->reverbVol;
- bookOffset = playbackState->parentLayer->seqChannel->bookOffset & 0x7;
- }
-
- frequency *= playbackState->vibratoFreqScale * playbackState->portamentoFreqScale;
- frequency *= gAudioBufferParameters.resampleRate;
- velocity = velocity * scale * scale;
- note_set_resampling_rate(note, frequency);
- note_set_vel_pan_reverb(note, velocity, pan, reverbVol);
-#endif
- noteSubEu->bookOffset = bookOffset;
- skip:;
}
-#else
- if (note->priority != NOTE_PRIORITY_DISABLED) {
- if (note->priority == NOTE_PRIORITY_STOPPING || note->finished) {
- if (note->adsrVolScale == 0 || note->finished) {
- if (note->wantedParentLayer != NO_LAYER) {
+ #ifndef VERSION_SH
+ if (1)
+ {
+ }
+ #endif
+ } else if (playbackState->adsr.state == ADSR_STATE_DISABLED)
+ {
+ note_disable(note);
+ audio_list_remove(¬e->listItem);
+ audio_list_push_back(¬e->listItem.pool->disabled, ¬e->listItem);
+ goto skip;
+ }
+
+ scale = adsr_update(&playbackState->adsr);
+ note_vibrato_update(note);
+ attributes = &playbackState->attributes;
+ #ifdef VERSION_SH
+ if (playbackState->unkSH34 == 1 || playbackState->unkSH34 == 2)
+ {
+ reverbInfo.freqScale = attributes->freqScale;
+ reverbInfo.velocity = attributes->velocity;
+ reverbInfo.pan = attributes->pan;
+ reverbInfo.reverbVol = attributes->reverbVol;
+ reverbInfo.reverbBits = attributes->reverbBits;
+ reverbInfo.synthesisVolume = attributes->synthesisVolume;
+ reverbInfo.filter = attributes->filter;
+ bookOffset = noteSubEu->bookOffset;
+ }
+ else
+ {
+ reverbInfo.freqScale = playbackState->parentLayer->noteFreqScale;
+ reverbInfo.velocity = playbackState->parentLayer->noteVelocity;
+ reverbInfo.pan = playbackState->parentLayer->notePan;
+ reverbInfo.reverbBits = playbackState->parentLayer->reverbBits;
+ reverbInfo.reverbVol = playbackState->parentLayer->seqChannel->reverbVol;
+ reverbInfo.synthesisVolume = playbackState->parentLayer->seqChannel->synthesisVolume;
+ reverbInfo.filter = playbackState->parentLayer->seqChannel->filter;
+ bookOffset = playbackState->parentLayer->seqChannel->bookOffset & 0x7;
+ if (playbackState->parentLayer->seqChannel->seqPlayer->muted
+ && (playbackState->parentLayer->seqChannel->muteBehavior & 8))
+ {
+ reverbInfo.freqScale = 0.0f;
+ reverbInfo.velocity = 0.0f;
+ }
+ }
+
+ reverbInfo.freqScale *= playbackState->vibratoFreqScale * playbackState->portamentoFreqScale;
+ reverbInfo.freqScale *= gAudioBufferParameters.resampleRate;
+ reverbInfo.velocity *= scale;
+ note_set_vel_pan_reverb(note, &reverbInfo);
+ #else
+ if (playbackState->priority == NOTE_PRIORITY_STOPPING)
+ {
+ frequency = attributes->freqScale;
+ velocity = attributes->velocity;
+ pan = attributes->pan;
+ reverbVol = attributes->reverbVol;
+ if (1)
+ {
+ }
+ bookOffset = noteSubEu->bookOffset;
+ }
+ else
+ {
+ frequency = playbackState->parentLayer->noteFreqScale;
+ velocity = playbackState->parentLayer->noteVelocity;
+ pan = playbackState->parentLayer->notePan;
+ reverbVol = playbackState->parentLayer->seqChannel->reverbVol;
+ bookOffset = playbackState->parentLayer->seqChannel->bookOffset & 0x7;
+ }
+
+ frequency *= playbackState->vibratoFreqScale * playbackState->portamentoFreqScale;
+ frequency *= gAudioBufferParameters.resampleRate;
+ velocity = velocity * scale * scale;
+ note_set_resampling_rate(note, frequency);
+ note_set_vel_pan_reverb(note, velocity, pan, reverbVol);
+ #endif
+ noteSubEu->bookOffset = bookOffset;
+ skip:;
+ }
+ #else
+ if (note->priority != NOTE_PRIORITY_DISABLED)
+ {
+ if (note->priority == NOTE_PRIORITY_STOPPING || note->finished)
+ {
+ if (note->adsrVolScale == 0 || note->finished)
+ {
+ if (note->wantedParentLayer != NO_LAYER)
+ {
note_disable2(note);
- if (note->wantedParentLayer->seqChannel != NULL) {
- if (note_init_for_layer(note, note->wantedParentLayer) == TRUE) {
+ if (note->wantedParentLayer->seqChannel != NULL)
+ {
+ if (note_init_for_layer(note, note->wantedParentLayer) == TRUE)
+ {
note_disable2(note);
POP(¬e->listItem);
PREPEND(¬e->listItem, &gNoteFreeLists.disabled);
- } else {
+ }
+ else
+ {
note_vibrato_init(note);
audio_list_push_back(¬e->listItem.pool->active,
POP(¬e->listItem));
note->wantedParentLayer = NO_LAYER;
}
- } else {
+ }
+ else
+ {
note_disable2(note);
audio_list_push_back(¬e->listItem.pool->disabled, POP(¬e->listItem));
note->wantedParentLayer = NO_LAYER;
continue;
}
- } else {
+ }
+ else
+ {
note_disable2(note);
audio_list_push_back(¬e->listItem.pool->disabled, POP(¬e->listItem));
continue;
}
}
- } else {
- if (note->adsr.state == ADSR_STATE_DISABLED) {
+ }
+ else
+ {
+ if (note->adsr.state == ADSR_STATE_DISABLED)
+ {
note_disable2(note);
audio_list_push_back(¬e->listItem.pool->disabled, POP(¬e->listItem));
continue;
@@ -600,12 +679,15 @@ void process_notes(void) {
adsr_update(¬e->adsr);
note_vibrato_update(note);
attributes = ¬e->attributes;
- if (note->priority == NOTE_PRIORITY_STOPPING) {
+ if (note->priority == NOTE_PRIORITY_STOPPING)
+ {
frequency = attributes->freqScale;
velocity = attributes->velocity;
pan = attributes->pan;
reverbVol = attributes->reverbVol;
- } else {
+ }
+ else
+ {
frequency = note->parentLayer->noteFreqScale;
velocity = note->parentLayer->noteVelocity;
pan = note->parentLayer->notePan;
@@ -615,50 +697,61 @@ void process_notes(void) {
scale = note->adsrVolScale;
frequency *= note->vibratoFreqScale * note->portamentoFreqScale;
cap = 3.99992f;
- if (gAiFrequency != 32006) {
- frequency *= US_FLOAT(32000.0) / (f32) gAiFrequency;
+ if (gAiFrequency != 32006)
+ {
+ frequency *= US_FLOAT(32000.0) / (f32)gAiFrequency;
}
- frequency = (frequency < cap ? frequency : cap);
+ frequency = frequency < cap ? frequency : cap;
scale *= 4.3498e-5f; // ~1 / 23000
velocity = velocity * scale * scale;
note_set_frequency(note, frequency);
note_set_vel_pan_reverb(note, velocity, pan, reverbVol);
continue;
}
-#endif
+ #endif
}
-#undef PREPEND
-#undef POP
+ #undef PREPEND
+ #undef POP
}
#if defined(VERSION_SH)
// These three are matching but have been moved from above in shindou:
-struct AudioBankSound *instrument_get_audio_bank_sound(struct Instrument *instrument, s32 semitone) {
+struct AudioBankSound *instrument_get_audio_bank_sound(struct Instrument *instrument, s32 semitone)
+{
struct AudioBankSound *sound;
- if (semitone < instrument->normalRangeLo) {
+ if (semitone < instrument->normalRangeLo)
+ {
sound = &instrument->lowNotesSound;
- } else if (semitone <= instrument->normalRangeHi) {
+ }
+ else if (semitone <= instrument->normalRangeHi)
+ {
sound = &instrument->normalNotesSound;
- } else {
+ }
+ else
+ {
sound = &instrument->highNotesSound;
}
return sound;
}
-struct Instrument *get_instrument_inner(s32 bankId, s32 instId) {
+struct Instrument *get_instrument_inner(s32 bankId, s32 instId)
+{
struct Instrument *inst;
- if (IS_BANK_LOAD_COMPLETE(bankId) == FALSE) {
+ if (IS_BANK_LOAD_COMPLETE(bankId) == FALSE)
+ {
gAudioErrorFlags = bankId + 0x10000000;
return NULL;
}
- if (instId >= gCtlEntries[bankId].numInstruments) {
+ if (instId >= gCtlEntries[bankId].numInstruments)
+ {
gAudioErrorFlags = ((bankId << 8) + instId) + 0x3000000;
return NULL;
}
inst = gCtlEntries[bankId].instruments[instId];
- if (inst == NULL) {
+ if (inst == NULL)
+ {
gAudioErrorFlags = ((bankId << 8) + instId) + 0x1000000;
return inst;
}
@@ -666,194 +759,223 @@ struct Instrument *get_instrument_inner(s32 bankId, s32 instId) {
return inst;
}
-struct Drum *get_drum(s32 bankId, s32 drumId) {
+struct Drum *get_drum(s32 bankId, s32 drumId)
+{
struct Drum *drum;
- if (IS_BANK_LOAD_COMPLETE(bankId) == FALSE) {
+ if (IS_BANK_LOAD_COMPLETE(bankId) == FALSE)
+ {
gAudioErrorFlags = bankId + 0x10000000;
return NULL;
}
- if (drumId >= gCtlEntries[bankId].numDrums) {
+ if (drumId >= gCtlEntries[bankId].numDrums)
+ {
gAudioErrorFlags = ((bankId << 8) + drumId) + 0x4000000;
return NULL;
}
#ifndef NO_SEGMENTED_MEMORY
- if ((uintptr_t) gCtlEntries[bankId].drums < 0x80000000U) {
+if ((uintptr_t) gCtlEntries [bankId].drums<0x80000000U) {
return NULL;
}
#endif
- drum = gCtlEntries[bankId].drums[drumId];
- if (drum == NULL) {
+drum= gCtlEntries[bankId].drums [drumId];
+ if (drum== NULL) {
gAudioErrorFlags = ((bankId << 8) + drumId) + 0x5000000;
}
return drum;
}
#endif
-void seq_channel_layer_decay_release_internal(struct SequenceChannelLayer *seqLayer, s32 target) {
+void seq_channel_layer_decay_release_internal(struct SequenceChannelLayer *seqLayer, s32 target)
+{
struct Note *note;
struct NoteAttributes *attributes;
- if (seqLayer == NO_LAYER) {
+ if (seqLayer == NO_LAYER)
+ {
return;
}
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
seqLayer->status = SOUND_LOAD_STATUS_NOT_LOADED;
-#endif
+ #endif
- if (seqLayer->note == NULL) {
+ if (seqLayer->note == NULL)
+ {
return;
}
note = seqLayer->note;
attributes = ¬e->attributes;
-#if defined(VERSION_JP) || defined(VERSION_US)
- if (seqLayer->seqChannel != NULL && seqLayer->seqChannel->noteAllocPolicy == 0) {
+ #if defined(VERSION_JP) || defined(VERSION_US)
+ if (seqLayer->seqChannel != NULL && seqLayer->seqChannel->noteAllocPolicy == 0)
+ {
seqLayer->note = NULL;
}
-#endif
+ #endif
- if (note->wantedParentLayer == seqLayer) {
+ if (note->wantedParentLayer == seqLayer)
+ {
note->wantedParentLayer = NO_LAYER;
}
- if (note->parentLayer != seqLayer) {
-
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ if (note->parentLayer != seqLayer)
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
if (note->parentLayer == NO_LAYER && note->wantedParentLayer == NO_LAYER &&
- note->prevParentLayer == seqLayer && target != ADSR_STATE_DECAY) {
+ note->prevParentLayer == seqLayer && target != ADSR_STATE_DECAY)
+ {
// Just guessing that this printf goes here... it's hard to parse.
eu_stubbed_printf_0("Slow Release Batting\n");
note->adsr.fadeOutVel = gAudioBufferParameters.updatesPerFrameInv;
note->adsr.action |= ADSR_ACTION_RELEASE;
}
-#endif
+ #endif
return;
}
-#ifndef VERSION_SH
+ #ifndef VERSION_SH
seqLayer->status = SOUND_LOAD_STATUS_NOT_LOADED;
-#endif
- if (note->adsr.state != ADSR_STATE_DECAY) {
+ #endif
+ if (note->adsr.state != ADSR_STATE_DECAY)
+ {
attributes->freqScale = seqLayer->noteFreqScale;
attributes->velocity = seqLayer->noteVelocity;
attributes->pan = seqLayer->notePan;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
attributes->reverbBits = seqLayer->reverbBits;
-#endif
- if (seqLayer->seqChannel != NULL) {
+ #endif
+ if (seqLayer->seqChannel != NULL)
+ {
attributes->reverbVol = seqLayer->seqChannel->reverbVol;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
attributes->synthesisVolume = seqLayer->seqChannel->synthesisVolume;
attributes->filter = seqLayer->seqChannel->filter;
- if (seqLayer->seqChannel->seqPlayer->muted && (seqLayer->seqChannel->muteBehavior & 8) != 0) {
+ if (seqLayer->seqChannel->seqPlayer->muted && (seqLayer->seqChannel->muteBehavior & 8) != 0)
+ {
note->noteSubEu.finished = TRUE;
}
note->priority = seqLayer->seqChannel->unkSH06;
-#endif
+ #endif
}
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
else {
-#endif
- note->priority = NOTE_PRIORITY_STOPPING;
-#ifdef VERSION_SH
+ #endif
+ note->priority = NOTE_PRIORITY_STOPPING;
+ #ifdef VERSION_SH
}
-#endif
+ #endif
note->prevParentLayer = note->parentLayer;
note->parentLayer = NO_LAYER;
- if (target == ADSR_STATE_RELEASE) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ if (target == ADSR_STATE_RELEASE)
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
note->adsr.fadeOutVel = gAudioBufferParameters.updatesPerFrameInv;
-#else
+ #else
note->adsr.fadeOutVel = 0x8000 / gAudioUpdatesPerFrame;
-#endif
+ #endif
note->adsr.action |= ADSR_ACTION_RELEASE;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
note->unkSH34 = 2;
-#endif
- } else {
-#ifdef VERSION_SH
+ #endif
+ }
+ else
+ {
+ #ifdef VERSION_SH
note->unkSH34 = 1;
-#endif
+ #endif
note->adsr.action |= ADSR_ACTION_DECAY;
-#if defined(VERSION_EU) || defined(VERSION_SH)
- if (seqLayer->adsr.releaseRate == 0) {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ if (seqLayer->adsr.releaseRate == 0)
+ {
note->adsr.fadeOutVel = seqLayer->seqChannel->adsr.releaseRate * gAudioBufferParameters.unkUpdatesPerFrameScaled;
- } else {
+ }
+ else
+ {
note->adsr.fadeOutVel = seqLayer->adsr.releaseRate * gAudioBufferParameters.unkUpdatesPerFrameScaled;
}
note->adsr.sustain = (FLOAT_CAST(seqLayer->seqChannel->adsr.sustain) * note->adsr.current) / 256.0f;
-#else
- if (seqLayer->adsr.releaseRate == 0) {
+ #else
+ if (seqLayer->adsr.releaseRate == 0)
+ {
note->adsr.fadeOutVel = seqLayer->seqChannel->adsr.releaseRate * 24;
- } else {
+ }
+ else
+ {
note->adsr.fadeOutVel = seqLayer->adsr.releaseRate * 24;
}
- note->adsr.sustain = (note->adsr.current * seqLayer->seqChannel->adsr.sustain) / 0x10000;
-#endif
+ note->adsr.sustain = note->adsr.current * seqLayer->seqChannel->adsr.sustain / 0x10000;
+ #endif
}
}
- if (target == ADSR_STATE_DECAY) {
+ if (target == ADSR_STATE_DECAY)
+ {
audio_list_remove(¬e->listItem);
audio_list_push_front(¬e->listItem.pool->decaying, ¬e->listItem);
}
}
-void seq_channel_layer_note_decay(struct SequenceChannelLayer *seqLayer) {
+void seq_channel_layer_note_decay(struct SequenceChannelLayer *seqLayer)
+{
seq_channel_layer_decay_release_internal(seqLayer, ADSR_STATE_DECAY);
}
-void seq_channel_layer_note_release(struct SequenceChannelLayer *seqLayer) {
+void seq_channel_layer_note_release(struct SequenceChannelLayer *seqLayer)
+{
seq_channel_layer_decay_release_internal(seqLayer, ADSR_STATE_RELEASE);
}
#if defined(VERSION_EU) || defined(VERSION_SH)
-s32 build_synthetic_wave(struct Note *note, struct SequenceChannelLayer *seqLayer, s32 waveId) {
+s32 build_synthetic_wave(struct Note *note, struct SequenceChannelLayer *seqLayer, s32 waveId)
+{
f32 freqScale;
f32 ratio;
u8 sampleCountIndex;
if (waveId < 128) {
#ifdef VERSION_EU
- stubbed_printf("Audio:Wavemem: Bad voiceno (%d)\n", waveId);
+stubbed_printf ("Audio:Wavemem: Bad voiceno (%d)\n", waveId);
#endif
- waveId = 128;
+waveId=128;
}
- freqScale = seqLayer->freqScale;
- if (seqLayer->portamento.mode != 0 && 0.0f < seqLayer->portamento.extent) {
+freqScale= seqLayer->freqScale;
+ if (seqLayer->portamento.mode!= 0 && 0.0f < seqLayer->portamento.extent) {
freqScale *= (seqLayer->portamento.extent + 1.0f);
}
- if (freqScale < 1.0f) {
- sampleCountIndex = 0;
- ratio = 1.0465f;
- } else if (freqScale < 2.0f) {
- sampleCountIndex = 1;
- ratio = 0.52325f;
- } else if (freqScale < 4.0f) {
- sampleCountIndex = 2;
- ratio = 0.26263f;
- } else {
+ if (freqScale<1.0f)
+{
+ sampleCountIndex = 0;
+ ratio = 1.0465f;
+}else if (freqScale<2.0f)
+{
+ sampleCountIndex = 1;
+ ratio = 0.52325f;
+}else if (freqScale<4.0f)
+{
+ sampleCountIndex = 2;
+ ratio = 0.26263f;
+}else {
sampleCountIndex = 3;
ratio = 0.13081f;
}
- seqLayer->freqScale *= ratio;
- note->waveId = waveId;
- note->sampleCountIndex = sampleCountIndex;
+seqLayer->freqScale*= ratio;
+note->waveId= waveId;
+note->sampleCountIndex= sampleCountIndex;
- note->noteSubEu.sound.samples = &gWaveSamples[waveId - 128][sampleCountIndex * 64];
+note->noteSubEu.sound.samples=&gWaveSamples [waveId - 128][sampleCountIndex * 64];
return sampleCountIndex;
}
#else
-void build_synthetic_wave(struct Note *note, struct SequenceChannelLayer *seqLayer) {
+void build_synthetic_wave(struct Note *note, struct SequenceChannelLayer *seqLayer)
+{
s32 i;
s32 j;
s32 pos;
@@ -862,44 +984,59 @@ void build_synthetic_wave(struct Note *note, struct SequenceChannelLayer *seqLay
u8 lim;
u8 origSampleCount = note->sampleCount;
- if (seqLayer->freqScale < US_FLOAT(1.0)) {
+ if (seqLayer->freqScale < US_FLOAT(1.0))
+ {
note->sampleCount = 64;
seqLayer->freqScale *= US_FLOAT(1.0465);
stepSize = 1;
- } else if (seqLayer->freqScale < US_FLOAT(2.0)) {
+ }
+ else if (seqLayer->freqScale < US_FLOAT(2.0))
+ {
note->sampleCount = 32;
seqLayer->freqScale *= US_FLOAT(0.52325);
stepSize = 2;
- } else if (seqLayer->freqScale < US_FLOAT(4.0)) {
+ }
+ else if (seqLayer->freqScale < US_FLOAT(4.0))
+ {
note->sampleCount = 16;
seqLayer->freqScale *= US_FLOAT(0.26263);
stepSize = 4;
- } else {
+ }
+ else
+ {
note->sampleCount = 8;
seqLayer->freqScale *= US_FLOAT(0.13081);
stepSize = 8;
}
- if (note->sampleCount == origSampleCount && seqLayer->seqChannel->instOrWave == note->instOrWave) {
+ if (note->sampleCount == origSampleCount && seqLayer->seqChannel->instOrWave == note->instOrWave)
+ {
return;
}
// Load wave sample
- note->instOrWave = (u8) seqLayer->seqChannel->instOrWave;
- for (i = -1, pos = 0; pos < 0x40; pos += stepSize) {
+ note->instOrWave = (u8)seqLayer->seqChannel->instOrWave;
+ for (i = -1, pos = 0; pos < 0x40; pos += stepSize)
+ {
i++;
note->synthesisBuffers->samples[i] = gWaveSamples[seqLayer->seqChannel->instOrWave - 0x80][pos];
}
// Repeat sample
- for (offset = note->sampleCount; offset < 0x40; offset += note->sampleCount) {
+ for (offset = note->sampleCount; offset < 0x40; offset += note->sampleCount)
+ {
lim = note->sampleCount;
- if (offset < 0 || offset > 0) {
- for (j = 0; j < lim; j++) {
+ if (offset < 0 || offset > 0)
+ {
+ for (j = 0; j < lim; j++)
+ {
note->synthesisBuffers->samples[offset + j] = note->synthesisBuffers->samples[j];
}
- } else {
- for (j = 0; j < lim; j++) {
+ }
+ else
+ {
+ for (j = 0; j < lim; j++)
+ {
note->synthesisBuffers->samples[offset + j] = note->synthesisBuffers->samples[j];
}
}
@@ -909,39 +1046,46 @@ void build_synthetic_wave(struct Note *note, struct SequenceChannelLayer *seqLay
}
#endif
-void init_synthetic_wave(struct Note *note, struct SequenceChannelLayer *seqLayer) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+void init_synthetic_wave(struct Note *note, struct SequenceChannelLayer *seqLayer)
+{
+ #if defined(VERSION_EU) || defined(VERSION_SH)
s32 sampleCountIndex;
s32 waveSampleCountIndex;
s32 waveId = seqLayer->instOrWave;
- if (waveId == 0xff) {
+ if (waveId == 0xff)
+ {
waveId = seqLayer->seqChannel->instOrWave;
}
sampleCountIndex = note->sampleCountIndex;
waveSampleCountIndex = build_synthetic_wave(note, seqLayer, waveId);
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
note->synthesisState.samplePosInt = note->synthesisState.samplePosInt * euUnknownData_8030194c[waveSampleCountIndex] / euUnknownData_8030194c[sampleCountIndex];
-#else // Not a real change. Just temporary so I can remove this variable.
+ #else // Not a real change. Just temporary so I can remove this variable.
note->synthesisState.samplePosInt = note->synthesisState.samplePosInt * gDefaultShortNoteVelocityTable[waveSampleCountIndex] / gDefaultShortNoteVelocityTable[sampleCountIndex];
-#endif
-#else
+ #endif
+ #else
s32 sampleCount = note->sampleCount;
build_synthetic_wave(note, seqLayer);
- if (sampleCount != 0) {
+ if (sampleCount != 0)
+ {
note->samplePosInt *= note->sampleCount / sampleCount;
- } else {
+ }
+ else
+ {
note->samplePosInt = 0;
}
-#endif
+ #endif
}
-void init_note_list(struct AudioListItem *list) {
+void init_note_list(struct AudioListItem *list)
+{
list->prev = list;
list->next = list;
list->u.count = 0;
}
-void init_note_lists(struct NotePool *pool) {
+void init_note_lists(struct NotePool *pool)
+{
init_note_list(&pool->disabled);
init_note_list(&pool->decaying);
init_note_list(&pool->releasing);
@@ -952,26 +1096,31 @@ void init_note_lists(struct NotePool *pool) {
pool->active.pool = pool;
}
-void init_note_free_list(void) {
+void init_note_free_list(void)
+{
s32 i;
init_note_lists(&gNoteFreeLists);
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
gNotes[i].listItem.u.value = &gNotes[i];
gNotes[i].listItem.prev = NULL;
audio_list_push_back(&gNoteFreeLists.disabled, &gNotes[i].listItem);
}
}
-void note_pool_clear(struct NotePool *pool) {
+void note_pool_clear(struct NotePool *pool)
+{
s32 i;
struct AudioListItem *source;
struct AudioListItem *cur;
struct AudioListItem *dest;
UNUSED s32 j; // unused in EU
- for (i = 0; i < 4; i++) {
- switch (i) {
+ for (i = 0; i < 4; i++)
+ {
+ switch (i)
+ {
case 0:
source = &pool->disabled;
dest = &gNoteFreeLists.disabled;
@@ -993,35 +1142,42 @@ void note_pool_clear(struct NotePool *pool) {
break;
}
-#if defined(VERSION_EU) || defined(VERSION_SH)
- for (;;) {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ for (;;)
+ {
cur = source->next;
- if (cur == source) {
+ if (cur == source)
+ {
break;
}
- if (cur == NULL) {
+ if (cur == NULL)
+ {
eu_stubbed_printf_0("Audio: C-Alloc : Dealloc voice is NULL\n");
break;
}
audio_list_remove(cur);
audio_list_push_back(dest, cur);
}
-#else
+ #else
j = 0;
- do {
+ do
+ {
cur = source->next;
- if (cur == source) {
+ if (cur == source)
+ {
break;
}
audio_list_remove(cur);
audio_list_push_back(dest, cur);
j++;
- } while (j <= gMaxSimultaneousNotes);
-#endif
+ }
+ while (j <= gMaxSimultaneousNotes);
+ #endif
}
}
-void note_pool_fill(struct NotePool *pool, s32 count) {
+void note_pool_fill(struct NotePool *pool, s32 count)
+{
s32 i;
s32 j;
struct Note *note;
@@ -1030,13 +1186,16 @@ void note_pool_fill(struct NotePool *pool, s32 count) {
note_pool_clear(pool);
- for (i = 0, j = 0; j < count; i++) {
- if (i == 4) {
+ for (i = 0, j = 0; j < count; i++)
+ {
+ if (i == 4)
+ {
eu_stubbed_printf_1("Alloc Error:Dim voice-Alloc %d", count);
return;
}
- switch (i) {
+ switch (i)
+ {
case 0:
source = &gNoteFreeLists.disabled;
dest = &pool->disabled;
@@ -1058,9 +1217,11 @@ void note_pool_fill(struct NotePool *pool, s32 count) {
break;
}
- while (j < count) {
+ while (j < count)
+ {
note = audio_list_pop_back(source);
- if (note == NULL) {
+ if (note == NULL)
+ {
break;
}
audio_list_push_back(dest, ¬e->listItem);
@@ -1069,11 +1230,15 @@ void note_pool_fill(struct NotePool *pool, s32 count) {
}
}
-void audio_list_push_front(struct AudioListItem *list, struct AudioListItem *item) {
+void audio_list_push_front(struct AudioListItem *list, struct AudioListItem *item)
+{
// add 'item' to the front of the list given by 'list', if it's not in any list
- if (item->prev != NULL) {
+ if (item->prev != NULL)
+ {
eu_stubbed_printf_0("Error:Same List Add\n");
- } else {
+ }
+ else
+ {
item->prev = list;
item->next = list->next;
list->next->prev = item;
@@ -1083,53 +1248,65 @@ void audio_list_push_front(struct AudioListItem *list, struct AudioListItem *ite
}
}
-void audio_list_remove(struct AudioListItem *item) {
+void audio_list_remove(struct AudioListItem *item)
+{
// remove 'item' from the list it's in, if any
- if (item->prev == NULL) {
+ if (item->prev == NULL)
+ {
eu_stubbed_printf_0("Already Cut\n");
- } else {
+ }
+ else
+ {
item->prev->next = item->next;
item->next->prev = item->prev;
item->prev = NULL;
}
}
-struct Note *pop_node_with_lower_prio(struct AudioListItem *list, s32 limit) {
+struct Note *pop_node_with_lower_prio(struct AudioListItem *list, s32 limit)
+{
struct AudioListItem *cur = list->next;
struct AudioListItem *best;
- if (cur == list) {
+ if (cur == list)
+ {
return NULL;
}
- for (best = cur; cur != list; cur = cur->next) {
- if (((struct Note *) best->u.value)->priority >= ((struct Note *) cur->u.value)->priority) {
+ for (best = cur; cur != list; cur = cur->next)
+ {
+ if (((struct Note *)best->u.value)->priority >= ((struct Note *)cur->u.value)->priority)
+ {
best = cur;
}
}
-#if defined(VERSION_EU) || defined(VERSION_SH)
- if (best == NULL) {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ if (best == NULL)
+ {
return NULL;
}
- if (limit <= ((struct Note *) best->u.value)->priority) {
+ if (limit <= ((struct Note *)best->u.value)->priority)
+ {
return NULL;
}
-#else
- if (limit < ((struct Note *) best->u.value)->priority) {
+ #else
+ if (limit < ((struct Note *)best->u.value)->priority)
+ {
return NULL;
}
-#endif
+ #endif
-#ifndef VERSION_SH
+ #ifndef VERSION_SH
audio_list_remove(best);
-#endif
+ #endif
return best->u.value;
}
#if defined(VERSION_EU) || defined(VERSION_SH)
-void note_init_for_layer(struct Note *note, struct SequenceChannelLayer *seqLayer) {
+void note_init_for_layer(struct Note *note, struct SequenceChannelLayer *seqLayer)
+{
UNUSED s32 pad[4];
s16 instId;
struct NoteSubEu *sub = ¬e->noteSubEu;
@@ -1145,34 +1322,41 @@ void note_init_for_layer(struct Note *note, struct SequenceChannelLayer *seqLaye
seqLayer->noteVelocity = 0.0f;
note_init(note);
instId = seqLayer->instOrWave;
- if (instId == 0xff) {
+ if (instId == 0xff)
+ {
instId = seqLayer->seqChannel->instOrWave;
}
sub->sound.audioBankSound = seqLayer->sound;
- if (instId >= 0x80) {
+ if (instId >= 0x80)
+ {
sub->isSyntheticWave = TRUE;
- } else {
+ }
+ else
+ {
sub->isSyntheticWave = FALSE;
}
- if (sub->isSyntheticWave) {
+ if (sub->isSyntheticWave)
+ {
build_synthetic_wave(note, seqLayer, instId);
}
#ifdef VERSION_SH
- note->bankId = seqLayer->seqChannel->bankId;
+note->bankId= seqLayer->seqChannel->bankId;
#else
- sub->bankId = seqLayer->seqChannel->bankId;
+sub->bankId= seqLayer->seqChannel->bankId;
#endif
- sub->stereoHeadsetEffects = seqLayer->seqChannel->stereoHeadsetEffects;
- sub->reverbIndex = seqLayer->seqChannel->reverbIndex & 3;
+sub->stereoHeadsetEffects= seqLayer->seqChannel->stereoHeadsetEffects;
+sub->reverbIndex= seqLayer->seqChannel->reverbIndex &3;
}
#else
-s32 note_init_for_layer(struct Note *note, struct SequenceChannelLayer *seqLayer) {
+s32 note_init_for_layer(struct Note *note, struct SequenceChannelLayer *seqLayer)
+{
note->prevParentLayer = NO_LAYER;
note->parentLayer = seqLayer;
note->priority = seqLayer->seqChannel->notePriority;
- if (IS_BANK_LOAD_COMPLETE(seqLayer->seqChannel->bankId) == FALSE) {
+ if (IS_BANK_LOAD_COMPLETE(seqLayer->seqChannel->bankId) == FALSE)
+ {
return TRUE;
}
@@ -1183,7 +1367,8 @@ s32 note_init_for_layer(struct Note *note, struct SequenceChannelLayer *seqLayer
seqLayer->note = note;
seqLayer->seqChannel->noteUnused = note;
seqLayer->seqChannel->layerUnused = seqLayer;
- if (note->sound == NULL) {
+ if (note->sound == NULL)
+ {
build_synthetic_wave(note, seqLayer);
}
note_init(note);
@@ -1191,87 +1376,101 @@ s32 note_init_for_layer(struct Note *note, struct SequenceChannelLayer *seqLayer
}
#endif
-void func_80319728(struct Note *note, struct SequenceChannelLayer *seqLayer) {
+void func_80319728(struct Note *note, struct SequenceChannelLayer *seqLayer)
+{
seq_channel_layer_note_release(note->parentLayer);
note->wantedParentLayer = seqLayer;
}
-void note_release_and_take_ownership(struct Note *note, struct SequenceChannelLayer *seqLayer) {
+void note_release_and_take_ownership(struct Note *note, struct SequenceChannelLayer *seqLayer)
+{
note->wantedParentLayer = seqLayer;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
note->priority = seqLayer->seqChannel->notePriority;
-#else
+ #else
note->priority = NOTE_PRIORITY_STOPPING;
-#endif
+ #endif
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
note->adsr.fadeOutVel = gAudioBufferParameters.updatesPerFrameInv;
-#else
+ #else
note->adsr.fadeOutVel = 0x8000 / gAudioUpdatesPerFrame;
-#endif
+ #endif
note->adsr.action |= ADSR_ACTION_RELEASE;
}
-struct Note *alloc_note_from_disabled(struct NotePool *pool, struct SequenceChannelLayer *seqLayer) {
+struct Note *alloc_note_from_disabled(struct NotePool *pool, struct SequenceChannelLayer *seqLayer)
+{
struct Note *note = audio_list_pop_back(&pool->disabled);
- if (note != NULL) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ if (note != NULL)
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
note_init_for_layer(note, seqLayer);
-#else
- if (note_init_for_layer(note, seqLayer) == TRUE) {
+ #else
+ if (note_init_for_layer(note, seqLayer) == TRUE)
+ {
audio_list_push_front(&gNoteFreeLists.disabled, ¬e->listItem);
return NULL;
}
-#endif
+ #endif
audio_list_push_front(&pool->active, ¬e->listItem);
}
return note;
}
-struct Note *alloc_note_from_decaying(struct NotePool *pool, struct SequenceChannelLayer *seqLayer) {
+struct Note *alloc_note_from_decaying(struct NotePool *pool, struct SequenceChannelLayer *seqLayer)
+{
struct Note *note = audio_list_pop_back(&pool->decaying);
- if (note != NULL) {
+ if (note != NULL)
+ {
note_release_and_take_ownership(note, seqLayer);
audio_list_push_back(&pool->releasing, ¬e->listItem);
}
return note;
}
-struct Note *alloc_note_from_active(struct NotePool *pool, struct SequenceChannelLayer *seqLayer) {
-#ifdef VERSION_SH
+struct Note *alloc_note_from_active(struct NotePool *pool, struct SequenceChannelLayer *seqLayer)
+{
+ #ifdef VERSION_SH
struct Note *rNote;
-#endif
+ #endif
struct Note *aNote;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
s32 rPriority, aPriority;
rPriority = aPriority = 0x10;
rNote = pop_node_with_lower_prio(&pool->releasing, seqLayer->seqChannel->notePriority);
- if (rNote != NULL) {
+ if (rNote != NULL)
+ {
rPriority = rNote->priority;
}
-#endif
+ #endif
aNote = pop_node_with_lower_prio(&pool->active, seqLayer->seqChannel->notePriority);
- if (aNote == NULL) {
+ if (aNote == NULL)
+ {
eu_stubbed_printf_0("Audio: C-Alloc : lowerPrio is NULL\n");
- } else {
-#ifdef VERSION_SH
+ }
+ else
+ {
+ #ifdef VERSION_SH
aPriority = aNote->priority;
-#else
+ #else
func_80319728(aNote, seqLayer);
audio_list_push_back(&pool->releasing, &aNote->listItem);
-#endif
+ #endif
}
-#ifdef VERSION_SH
- if (rNote == NULL && aNote == NULL) {
+ #ifdef VERSION_SH
+ if (rNote == NULL && aNote == NULL)
+ {
return NULL;
}
- if (aPriority < rPriority) {
+ if (aPriority < rPriority)
+ {
audio_list_remove(&aNote->listItem);
func_80319728(aNote, seqLayer);
audio_list_push_back(&pool->releasing, &aNote->listItem);
@@ -1281,77 +1480,86 @@ struct Note *alloc_note_from_active(struct NotePool *pool, struct SequenceChanne
rNote->wantedParentLayer = seqLayer;
rNote->priority = seqLayer->seqChannel->notePriority;
return rNote;
-#else
+ #else
return aNote;
-#endif
+ #endif
}
-struct Note *alloc_note(struct SequenceChannelLayer *seqLayer) {
+struct Note *alloc_note(struct SequenceChannelLayer *seqLayer)
+{
struct Note *ret;
u32 policy = seqLayer->seqChannel->noteAllocPolicy;
- if (policy & NOTE_ALLOC_LAYER) {
+ if (policy & NOTE_ALLOC_LAYER)
+ {
ret = seqLayer->note;
if (ret != NULL && ret->prevParentLayer == seqLayer
-#if defined(VERSION_EU) || defined(VERSION_SH)
- && ret->wantedParentLayer == NO_LAYER
-#endif
- ) {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ && ret->wantedParentLayer == NO_LAYER
+ #endif
+ )
+ {
note_release_and_take_ownership(ret, seqLayer);
audio_list_remove(&ret->listItem);
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
audio_list_push_back(&ret->listItem.pool->releasing, &ret->listItem);
-#else
+ #else
audio_list_push_back(&gNoteFreeLists.releasing, &ret->listItem);
-#endif
+ #endif
return ret;
}
}
- if (policy & NOTE_ALLOC_CHANNEL) {
+ if (policy & NOTE_ALLOC_CHANNEL)
+ {
if (!(ret = alloc_note_from_disabled(&seqLayer->seqChannel->notePool, seqLayer))
&& !(ret = alloc_note_from_decaying(&seqLayer->seqChannel->notePool, seqLayer))
- && !(ret = alloc_note_from_active(&seqLayer->seqChannel->notePool, seqLayer))) {
-#ifdef VERSION_SH
+ && !(ret = alloc_note_from_active(&seqLayer->seqChannel->notePool, seqLayer)))
+ {
+ #ifdef VERSION_SH
goto null_return;
-#else
+ #else
eu_stubbed_printf_0("Sub Limited Warning: Drop Voice");
seqLayer->status = SOUND_LOAD_STATUS_NOT_LOADED;
return NULL;
-#endif
+ #endif
}
return ret;
}
- if (policy & NOTE_ALLOC_SEQ) {
+ if (policy & NOTE_ALLOC_SEQ)
+ {
if (!(ret = alloc_note_from_disabled(&seqLayer->seqChannel->notePool, seqLayer))
&& !(ret = alloc_note_from_disabled(&seqLayer->seqChannel->seqPlayer->notePool, seqLayer))
&& !(ret = alloc_note_from_decaying(&seqLayer->seqChannel->notePool, seqLayer))
&& !(ret = alloc_note_from_decaying(&seqLayer->seqChannel->seqPlayer->notePool, seqLayer))
&& !(ret = alloc_note_from_active(&seqLayer->seqChannel->notePool, seqLayer))
- && !(ret = alloc_note_from_active(&seqLayer->seqChannel->seqPlayer->notePool, seqLayer))) {
-#ifdef VERSION_SH
+ && !(ret = alloc_note_from_active(&seqLayer->seqChannel->seqPlayer->notePool, seqLayer)))
+ {
+ #ifdef VERSION_SH
goto null_return;
-#else
+ #else
eu_stubbed_printf_0("Warning: Drop Voice");
seqLayer->status = SOUND_LOAD_STATUS_NOT_LOADED;
return NULL;
-#endif
+ #endif
}
return ret;
}
- if (policy & NOTE_ALLOC_GLOBAL_FREELIST) {
+ if (policy & NOTE_ALLOC_GLOBAL_FREELIST)
+ {
if (!(ret = alloc_note_from_disabled(&gNoteFreeLists, seqLayer))
&& !(ret = alloc_note_from_decaying(&gNoteFreeLists, seqLayer))
- && !(ret = alloc_note_from_active(&gNoteFreeLists, seqLayer))) {
-#ifdef VERSION_SH
+ && !(ret = alloc_note_from_active(&gNoteFreeLists, seqLayer)))
+ {
+ #ifdef VERSION_SH
goto null_return;
-#else
+ #else
eu_stubbed_printf_0("Warning: Drop Voice");
seqLayer->status = SOUND_LOAD_STATUS_NOT_LOADED;
return NULL;
-#endif
+ #endif
}
return ret;
}
@@ -1364,53 +1572,67 @@ struct Note *alloc_note(struct SequenceChannelLayer *seqLayer) {
&& !(ret = alloc_note_from_decaying(&gNoteFreeLists, seqLayer))
&& !(ret = alloc_note_from_active(&seqLayer->seqChannel->notePool, seqLayer))
&& !(ret = alloc_note_from_active(&seqLayer->seqChannel->seqPlayer->notePool, seqLayer))
- && !(ret = alloc_note_from_active(&gNoteFreeLists, seqLayer))) {
-#ifdef VERSION_SH
+ && !(ret = alloc_note_from_active(&gNoteFreeLists, seqLayer)))
+ {
+ #ifdef VERSION_SH
goto null_return;
-#else
+ #else
eu_stubbed_printf_0("Warning: Drop Voice");
seqLayer->status = SOUND_LOAD_STATUS_NOT_LOADED;
return NULL;
-#endif
+ #endif
}
return ret;
-#ifdef VERSION_SH
-null_return:
- seqLayer->status = SOUND_LOAD_STATUS_NOT_LOADED;
+ #ifdef VERSION_SH
+null_return: seqLayer->status = SOUND_LOAD_STATUS_NOT_LOADED;
return NULL;
-#endif
+ #endif
}
#if defined(VERSION_JP) || defined(VERSION_US)
-void reclaim_notes(void) {
+void reclaim_notes(void)
+{
struct Note *note;
s32 i;
s32 cond;
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
note = &gNotes[i];
- if (note->parentLayer != NO_LAYER) {
+ if (note->parentLayer != NO_LAYER)
+ {
cond = FALSE;
- if (!note->parentLayer->enabled && note->priority >= NOTE_PRIORITY_MIN) {
+ if (!note->parentLayer->enabled && note->priority >= NOTE_PRIORITY_MIN)
+ {
cond = TRUE;
- } else if (note->parentLayer->seqChannel == NULL) {
+ }
+ else if (note->parentLayer->seqChannel == NULL)
+ {
audio_list_push_back(&gLayerFreeList, ¬e->parentLayer->listItem);
seq_channel_layer_disable(note->parentLayer);
note->priority = NOTE_PRIORITY_STOPPING;
- } else if (note->parentLayer->seqChannel->seqPlayer == NULL) {
+ }
+ else if (note->parentLayer->seqChannel->seqPlayer == NULL)
+ {
sequence_channel_disable(note->parentLayer->seqChannel);
note->priority = NOTE_PRIORITY_STOPPING;
- } else if (note->parentLayer->seqChannel->seqPlayer->muted) {
+ }
+ else if (note->parentLayer->seqChannel->seqPlayer->muted)
+ {
if (note->parentLayer->seqChannel->muteBehavior
- & (MUTE_BEHAVIOR_STOP_SCRIPT | MUTE_BEHAVIOR_STOP_NOTES)) {
+ & (MUTE_BEHAVIOR_STOP_SCRIPT | MUTE_BEHAVIOR_STOP_NOTES))
+ {
cond = TRUE;
}
- } else {
+ }
+ else
+ {
cond = FALSE;
}
- if (cond) {
+ if (cond)
+ {
seq_channel_layer_note_release(note->parentLayer);
audio_list_remove(¬e->listItem);
audio_list_push_front(¬e->listItem.pool->disabled, ¬e->listItem);
@@ -1421,30 +1643,32 @@ void reclaim_notes(void) {
}
#endif
-void note_init_all(void) {
+void note_init_all(void)
+{
struct Note *note;
s32 i;
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
note = &gNotes[i];
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
note->noteSubEu = gZeroNoteSub;
-#else
+ #else
note->enabled = FALSE;
note->stereoStrongRight = FALSE;
note->stereoStrongLeft = FALSE;
note->stereoHeadsetEffects = FALSE;
-#endif
+ #endif
note->priority = NOTE_PRIORITY_DISABLED;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
note->unkSH34 = 0;
-#endif
+ #endif
note->parentLayer = NO_LAYER;
note->wantedParentLayer = NO_LAYER;
note->prevParentLayer = NO_LAYER;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
note->waveId = 0;
-#else
+ #else
note->reverbVol = 0;
note->usesHeadsetPanEffects = FALSE;
note->sampleCount = 0;
@@ -1453,7 +1677,7 @@ void note_init_all(void) {
note->targetVolRight = 0;
note->frequency = 0.0f;
note->unused1 = 0x3f;
-#endif
+ #endif
note->attributes.velocity = 0.0f;
note->adsrVolScale = 0;
note->adsr.state = ADSR_STATE_DISABLED;
@@ -1461,12 +1685,12 @@ void note_init_all(void) {
note->vibratoState.active = FALSE;
note->portamento.cur = 0.0f;
note->portamento.speed = 0.0f;
-#if defined(VERSION_SH)
+ #if defined(VERSION_SH)
note->synthesisState.synthesisBuffers = sound_alloc_uninitialized(&gNotesAndBuffersPool, sizeof(struct NoteSynthesisBuffers));
-#elif defined(VERSION_EU)
+ #elif defined(VERSION_EU)
note->synthesisState.synthesisBuffers = soundAlloc(&gNotesAndBuffersPool, sizeof(struct NoteSynthesisBuffers));
-#else
+ #else
note->synthesisBuffers = soundAlloc(&gNotesAndBuffersPool, sizeof(struct NoteSynthesisBuffers));
-#endif
+ #endif
}
}
diff --git a/src/decomp/audio/playback.h b/src/decomp/audio/playback.h
index e2e15bf..fe67d86 100644
--- a/src/decomp/audio/playback.h
+++ b/src/decomp/audio/playback.h
@@ -17,17 +17,29 @@
#define NOTE_ALLOC_GLOBAL_FREELIST 8
void process_notes(void);
+
void seq_channel_layer_note_decay(struct SequenceChannelLayer *seqLayer);
+
void seq_channel_layer_note_release(struct SequenceChannelLayer *seqLayer);
+
void init_synthetic_wave(struct Note *note, struct SequenceChannelLayer *seqLayer);
+
void init_note_lists(struct NotePool *pool);
+
void init_note_free_list(void);
+
void note_pool_clear(struct NotePool *pool);
+
void note_pool_fill(struct NotePool *pool, s32 count);
+
void audio_list_push_front(struct AudioListItem *list, struct AudioListItem *item);
+
void audio_list_remove(struct AudioListItem *item);
+
struct Note *alloc_note(struct SequenceChannelLayer *seqLayer);
+
void reclaim_notes(void);
+
void note_init_all(void);
#if defined(VERSION_SH)
diff --git a/src/decomp/audio/port_eu.c b/src/decomp/audio/port_eu.c
index d607f77..303ac74 100644
--- a/src/decomp/audio/port_eu.c
+++ b/src/decomp/audio/port_eu.c
@@ -34,7 +34,8 @@ s32 audio_shut_down_and_reset_step(void);
void func_802ad7ec(u32);
#ifdef TARGET_N64
-struct SPTask *create_next_audio_frame_task(void) {
+struct SPTask *create_next_audio_frame_task(void)
+{
u32 samplesRemainingInAI;
s32 writtenCmds;
s32 index;
@@ -46,12 +47,13 @@ struct SPTask *create_next_audio_frame_task(void) {
OSMesg sp2C;
gAudioFrameCount++;
- if (gAudioFrameCount % gAudioBufferParameters.presetUnk4 != 0) {
+ if (gAudioFrameCount % gAudioBufferParameters.presetUnk4 != 0)
+ {
stubbed_printf("DAC:Lost 1 Frame.\n");
return NULL;
}
- osSendMesg(OSMesgQueues[0], (OSMesg) gAudioFrameCount, 0);
+ osSendMesg(OSMesgQueues[0], (OSMesg)gAudioFrameCount, 0);
gAudioTaskIndex ^= 1;
gCurrAiBufferIndex++;
@@ -59,26 +61,33 @@ struct SPTask *create_next_audio_frame_task(void) {
index = (gCurrAiBufferIndex - 2 + NUMAIBUFFERS) % NUMAIBUFFERS;
samplesRemainingInAI = osAiGetLength() / 4;
- if (gAiBufferLengths[index] != 0) {
+ if (gAiBufferLengths[index] != 0)
+ {
osAiSetNextBuffer(gAiBuffers[index], gAiBufferLengths[index] * 4);
}
oldDmaCount = gCurrAudioFrameDmaCount;
- if (oldDmaCount > AUDIO_FRAME_DMA_QUEUE_SIZE) {
+ if (oldDmaCount > AUDIO_FRAME_DMA_QUEUE_SIZE)
+ {
stubbed_printf("DMA: Request queue over.( %d )\n", oldDmaCount);
}
gCurrAudioFrameDmaCount = 0;
decrease_sample_dma_ttls();
- if (osRecvMesg(OSMesgQueues[2], &sp30, 0) != -1) {
- gAudioResetPresetIdToLoad = (u8) (s32) sp30;
+ if (osRecvMesg(OSMesgQueues[2], &sp30, 0) != -1)
+ {
+ gAudioResetPresetIdToLoad = (u8)(s32)
+ sp30;
gAudioResetStatus = 5;
}
- if (gAudioResetStatus != 0) {
- if (audio_shut_down_and_reset_step() == 0) {
- if (gAudioResetStatus == 0) {
- osSendMesg(OSMesgQueues[3], (OSMesg) (s32) gAudioResetPresetIdToLoad, OS_MESG_NOBLOCK);
+ if (gAudioResetStatus != 0)
+ {
+ if (audio_shut_down_and_reset_step() == 0)
+ {
+ if (gAudioResetStatus == 0)
+ {
+ osSendMesg(OSMesgQueues[3], (OSMesg)(s32) gAudioResetPresetIdToLoad, OS_MESG_NOBLOCK);
}
return NULL;
}
@@ -90,16 +99,19 @@ struct SPTask *create_next_audio_frame_task(void) {
currAiBuffer = gAiBuffers[index];
gAiBufferLengths[index] = ((gAudioBufferParameters.samplesPerFrameTarget - samplesRemainingInAI +
- EXTRA_BUFFERED_AI_SAMPLES_TARGET) & ~0xf) + SAMPLES_TO_OVERPRODUCE;
- if (gAiBufferLengths[index] < gAudioBufferParameters.minAiBufferLength) {
+ EXTRA_BUFFERED_AI_SAMPLES_TARGET) & ~0xf) + SAMPLES_TO_OVERPRODUCE;
+ if (gAiBufferLengths[index] < gAudioBufferParameters.minAiBufferLength)
+ {
gAiBufferLengths[index] = gAudioBufferParameters.minAiBufferLength;
}
- if (gAiBufferLengths[index] > gAudioBufferParameters.maxAiBufferLength) {
+ if (gAiBufferLengths[index] > gAudioBufferParameters.maxAiBufferLength)
+ {
gAiBufferLengths[index] = gAudioBufferParameters.maxAiBufferLength;
}
- if (osRecvMesg(OSMesgQueues[1], &sp2C, OS_MESG_NOBLOCK) != -1) {
- func_802ad7ec((u32) sp2C);
+ if (osRecvMesg(OSMesgQueues[1], &sp2C, OS_MESG_NOBLOCK) != -1)
+ {
+ func_802ad7ec((u32)sp2C);
}
flags = 0;
@@ -115,7 +127,7 @@ struct SPTask *create_next_audio_frame_task(void) {
task->type = M_AUDTASK;
task->flags = flags;
task->ucode_boot = rspF3DBootStart;
- task->ucode_boot_size = (u8 *) rspF3DBootEnd - (u8 *) rspF3DBootStart;
+ task->ucode_boot_size = (u8 *)rspF3DBootEnd - (u8 *)rspF3DBootStart;
task->ucode = rspAspMainStart;
task->ucode_data = rspAspMainDataStart;
task->ucode_size = 0x800; // (this size is ignored)
@@ -131,25 +143,31 @@ struct SPTask *create_next_audio_frame_task(void) {
return gAudioTask;
}
#else
-struct SPTask *create_next_audio_frame_task(void) {
+struct SPTask *create_next_audio_frame_task(void)
+{
return NULL;
}
-void create_next_audio_buffer(s16 *samples, u32 num_samples) {
+void create_next_audio_buffer(s16 *samples, u32 num_samples)
+{
s32 writtenCmds;
OSMesg msg;
gAudioFrameCount++;
decrease_sample_dma_ttls();
- if (osRecvMesg(OSMesgQueues[2], &msg, 0) != -1) {
- gAudioResetPresetIdToLoad = (u8) (intptr_t) msg;
+ if (osRecvMesg(OSMesgQueues[2], &msg, 0) != -1)
+ {
+ gAudioResetPresetIdToLoad = (u8)(intptr_t)
+ msg;
gAudioResetStatus = 5;
}
- if (gAudioResetStatus != 0) {
+ if (gAudioResetStatus != 0)
+ {
audio_reset_session();
gAudioResetStatus = 0;
}
- if (osRecvMesg(OSMesgQueues[1], &msg, OS_MESG_NOBLOCK) != -1) {
- func_802ad7ec((u32) msg);
+ if (osRecvMesg(OSMesgQueues[1], &msg, OS_MESG_NOBLOCK) != -1)
+ {
+ func_802ad7ec((u32)msg);
}
synthesis_execute(gAudioCmdBuffers[0], &writtenCmds, samples, num_samples);
gAudioRandom = ((gAudioRandom + gAudioFrameCount) * gAudioFrameCount);
@@ -157,48 +175,55 @@ void create_next_audio_buffer(s16 *samples, u32 num_samples) {
}
#endif
-void eu_process_audio_cmd(struct EuAudioCmd *cmd) {
+void eu_process_audio_cmd(struct EuAudioCmd *cmd)
+{
s32 i;
- switch (cmd->u.s.op) {
- case 0x81:
- preload_sequence(cmd->u.s.arg2, 3);
- break;
+ switch (cmd->u.s.op)
+ {
+ case 0x81:
+ preload_sequence(cmd->u.s.arg2, 3);
+ break;
- case 0x82:
- case 0x88:
- load_sequence(cmd->u.s.arg1, cmd->u.s.arg2, cmd->u.s.arg3);
- func_8031D690(cmd->u.s.arg1, cmd->u2.as_s32);
- break;
+ case 0x82:
+ case 0x88:
+ load_sequence(cmd->u.s.arg1, cmd->u.s.arg2, cmd->u.s.arg3);
+ func_8031D690(cmd->u.s.arg1, cmd->u2.as_s32);
+ break;
- case 0x83:
- if (gSequencePlayers[cmd->u.s.arg1].enabled != FALSE) {
- if (cmd->u2.as_s32 == 0) {
- sequence_player_disable(&gSequencePlayers[cmd->u.s.arg1]);
+ case 0x83:
+ if (gSequencePlayers[cmd->u.s.arg1].enabled != FALSE)
+ {
+ if (cmd->u2.as_s32 == 0)
+ {
+ sequence_player_disable(&gSequencePlayers[cmd->u.s.arg1]);
+ }
+ else
+ {
+ seq_player_fade_to_zero_volume(cmd->u.s.arg1, cmd->u2.as_s32);
+ }
}
- else {
- seq_player_fade_to_zero_volume(cmd->u.s.arg1, cmd->u2.as_s32);
+ break;
+
+ case 0xf0:
+ gSoundMode = cmd->u2.as_s32;
+ break;
+
+ case 0xf1:
+ for (i = 0; i < 4; i++)
+ {
+ gSequencePlayers[i].muted = TRUE;
+ gSequencePlayers[i].recalculateVolume = TRUE;
}
- }
- break;
+ break;
- case 0xf0:
- gSoundMode = cmd->u2.as_s32;
- break;
-
- case 0xf1:
- for (i = 0; i < 4; i++) {
- gSequencePlayers[i].muted = TRUE;
- gSequencePlayers[i].recalculateVolume = TRUE;
- }
- break;
-
- case 0xf2:
- for (i = 0; i < 4; i++) {
- gSequencePlayers[i].muted = FALSE;
- gSequencePlayers[i].recalculateVolume = TRUE;
- }
- break;
+ case 0xf2:
+ for (i = 0; i < 4; i++)
+ {
+ gSequencePlayers[i].muted = FALSE;
+ gSequencePlayers[i].recalculateVolume = TRUE;
+ }
+ break;
}
}
@@ -212,18 +237,21 @@ extern OSMesg OSMesg1;
extern OSMesg OSMesg2;
extern OSMesg OSMesg3;
-void seq_player_fade_to_zero_volume(s32 player, FadeT fadeOutTime) {
- if (fadeOutTime == 0) {
+void seq_player_fade_to_zero_volume(s32 player, FadeT fadeOutTime)
+{
+ if (fadeOutTime == 0)
+ {
fadeOutTime = 1;
}
gSequencePlayers[player].fadeVelocity = -(gSequencePlayers[player].fadeVolume / fadeOutTime);
gSequencePlayers[player].state = 2;
gSequencePlayers[player].fadeRemainingFrames = fadeOutTime;
-
}
-void func_8031D690(s32 player, FadeT fadeInTime) {
- if (fadeInTime != 0) {
+void func_8031D690(s32 player, FadeT fadeInTime)
+{
+ if (fadeInTime != 0)
+ {
gSequencePlayers[player].state = 1;
gSequencePlayers[player].fadeTimerUnkEu = fadeInTime;
gSequencePlayers[player].fadeRemainingFrames = fadeInTime;
@@ -232,7 +260,8 @@ void func_8031D690(s32 player, FadeT fadeInTime) {
}
}
-void port_eu_init_queues(void) {
+void port_eu_init_queues(void)
+{
D_EU_80302010 = 0;
D_EU_80302014 = 0;
osCreateMesgQueue(OSMesgQueues[0], &OSMesg0, 1);
@@ -241,100 +270,114 @@ void port_eu_init_queues(void) {
osCreateMesgQueue(OSMesgQueues[3], &OSMesg3, 1);
}
-void func_802ad6f0(s32 arg0, s32 *arg1) {
+void func_802ad6f0(s32 arg0, s32 *arg1)
+{
struct EuAudioCmd *cmd = &sAudioCmd[D_EU_80302010 & 0xff];
cmd->u.first = arg0;
cmd->u2.as_u32 = *arg1;
D_EU_80302010++;
}
-void func_802ad728(u32 arg0, f32 arg1) {
- func_802ad6f0(arg0, (s32*) &arg1);
+void func_802ad728(u32 arg0, f32 arg1)
+{
+ func_802ad6f0(arg0, (s32 *)&arg1);
}
-void func_802ad74c(u32 arg0, u32 arg1) {
- func_802ad6f0(arg0, (s32*) &arg1);
+void func_802ad74c(u32 arg0, u32 arg1)
+{
+ func_802ad6f0(arg0, (s32 *)&arg1);
}
-void func_802ad770(u32 arg0, s8 arg1) {
+void func_802ad770(u32 arg0, s8 arg1)
+{
s32 sp1C = arg1 << 24;
func_802ad6f0(arg0, &sp1C);
}
-void func_802ad7a0(void) {
+void func_802ad7a0(void)
+{
osSendMesg(OSMesgQueues[1],
- (OSMesg)(u32)((D_EU_80302014 & 0xff) << 8 | (D_EU_80302010 & 0xff)),
- OS_MESG_NOBLOCK);
+ (OSMesg)(u32)((D_EU_80302014 & 0xff) << 8 | (D_EU_80302010 & 0xff)),
+ OS_MESG_NOBLOCK);
D_EU_80302014 = D_EU_80302010;
}
-void func_802ad7ec(u32 arg0) {
+void func_802ad7ec(u32 arg0)
+{
struct EuAudioCmd *cmd;
struct SequencePlayer *seqPlayer;
struct SequenceChannel *chan;
u8 end = arg0 & 0xff;
u8 i = (arg0 >> 8) & 0xff;
- for (;;) {
+ for (;;)
+ {
if (i == end) break;
cmd = &sAudioCmd[i++ & 0xff];
- if (cmd->u.s.arg1 < SEQUENCE_PLAYERS) {
+ if (cmd->u.s.arg1 < SEQUENCE_PLAYERS)
+ {
seqPlayer = &gSequencePlayers[cmd->u.s.arg1];
- if ((cmd->u.s.op & 0x80) != 0) {
+ if ((cmd->u.s.op & 0x80) != 0)
+ {
eu_process_audio_cmd(cmd);
}
- else if ((cmd->u.s.op & 0x40) != 0) {
- switch (cmd->u.s.op) {
- case 0x41:
- seqPlayer->fadeVolumeScale = cmd->u2.as_f32;
- seqPlayer->recalculateVolume = TRUE;
- break;
+ else if ((cmd->u.s.op & 0x40) != 0)
+ {
+ switch (cmd->u.s.op)
+ {
+ case 0x41:
+ seqPlayer->fadeVolumeScale = cmd->u2.as_f32;
+ seqPlayer->recalculateVolume = TRUE;
+ break;
- case 0x47:
- seqPlayer->tempo = cmd->u2.as_s32 * TATUMS_PER_BEAT;
- break;
+ case 0x47:
+ seqPlayer->tempo = cmd->u2.as_s32 * TATUMS_PER_BEAT;
+ break;
- case 0x48:
- seqPlayer->transposition = cmd->u2.as_s8;
- break;
+ case 0x48:
+ seqPlayer->transposition = cmd->u2.as_s8;
+ break;
- case 0x46:
- seqPlayer->seqVariationEu[cmd->u.s.arg3] = cmd->u2.as_s8;
- break;
+ case 0x46:
+ seqPlayer->seqVariationEu[cmd->u.s.arg3] = cmd->u2.as_s8;
+ break;
}
}
- else if (seqPlayer->enabled != FALSE && cmd->u.s.arg2 < 0x10) {
+ else if (seqPlayer->enabled != FALSE && cmd->u.s.arg2 < 0x10)
+ {
chan = seqPlayer->channels[cmd->u.s.arg2];
if (IS_SEQUENCE_CHANNEL_VALID(chan))
{
- switch (cmd->u.s.op) {
- case 1:
- chan->volumeScale = cmd->u2.as_f32;
- chan->changes.as_bitfields.volume = TRUE;
- break;
- case 2:
- chan->volume = cmd->u2.as_f32;
- chan->changes.as_bitfields.volume = TRUE;
- break;
- case 3:
- chan->newPan = cmd->u2.as_s8;
- chan->changes.as_bitfields.pan = TRUE;
- break;
- case 4:
- chan->freqScale = cmd->u2.as_f32;
- chan->changes.as_bitfields.freqScale = TRUE;
- break;
- case 5:
- chan->reverbVol = cmd->u2.as_s8;
- break;
- case 6:
- if (cmd->u.s.arg3 < 8) {
- chan->soundScriptIO[cmd->u.s.arg3] = cmd->u2.as_s8;
- }
- break;
- case 8:
- chan->stopSomething2 = cmd->u2.as_s8;
+ switch (cmd->u.s.op)
+ {
+ case 1:
+ chan->volumeScale = cmd->u2.as_f32;
+ chan->changes.as_bitfields.volume = TRUE;
+ break;
+ case 2:
+ chan->volume = cmd->u2.as_f32;
+ chan->changes.as_bitfields.volume = TRUE;
+ break;
+ case 3:
+ chan->newPan = cmd->u2.as_s8;
+ chan->changes.as_bitfields.pan = TRUE;
+ break;
+ case 4:
+ chan->freqScale = cmd->u2.as_f32;
+ chan->changes.as_bitfields.freqScale = TRUE;
+ break;
+ case 5:
+ chan->reverbVol = cmd->u2.as_s8;
+ break;
+ case 6:
+ if (cmd->u.s.arg3 < 8)
+ {
+ chan->soundScriptIO[cmd->u.s.arg3] = cmd->u2.as_s8;
+ }
+ break;
+ case 8:
+ chan->stopSomething2 = cmd->u2.as_s8;
}
}
}
@@ -344,7 +387,8 @@ void func_802ad7ec(u32 arg0) {
}
}
-void port_eu_init(void) {
+void port_eu_init(void)
+{
port_eu_init_queues();
}
diff --git a/src/decomp/audio/port_sh.c b/src/decomp/audio/port_sh.c
index 66cbc3b..d2c5ade 100644
--- a/src/decomp/audio/port_sh.c
+++ b/src/decomp/audio/port_sh.c
@@ -24,7 +24,8 @@ void seq_player_fade_to_zero_volume(s32 arg0, s32 numFrames);
void func_802ad7ec(u32 arg0);
#ifdef TARGET_N64
-struct SPTask *create_next_audio_frame_task(void) {
+struct SPTask *create_next_audio_frame_task(void)
+{
u32 samplesRemainingInAI;
s32 writtenCmds;
s32 index;
@@ -37,13 +38,15 @@ struct SPTask *create_next_audio_frame_task(void) {
s32 writtenCmdsCopy;
gAudioFrameCount++;
- if (gAudioFrameCount % gAudioBufferParameters.presetUnk4 != 0) {
- if ((gAudioFrameCount % gAudioBufferParameters.presetUnk4) + 1 == gAudioBufferParameters.presetUnk4) {
+ if (gAudioFrameCount % gAudioBufferParameters.presetUnk4 != 0)
+ {
+ if ((gAudioFrameCount % gAudioBufferParameters.presetUnk4) + 1 == gAudioBufferParameters.presetUnk4)
+ {
return D_SH_80314FCC;
}
return NULL;
}
- osSendMesg(D_SH_80350F38, (OSMesg) gAudioFrameCount, OS_MESG_NOBLOCK);
+ osSendMesg(D_SH_80350F38, (OSMesg)gAudioFrameCount, OS_MESG_NOBLOCK);
gAudioTaskIndex ^= 1;
gCurrAiBufferIndex++;
@@ -51,66 +54,81 @@ struct SPTask *create_next_audio_frame_task(void) {
index = (gCurrAiBufferIndex - 2 + NUMAIBUFFERS) % NUMAIBUFFERS;
samplesRemainingInAI = osAiGetLength() / 4;
- if (gAudioLoadLockSH < 0x10U) {
- if (gAiBufferLengths[index] != 0) {
+ if (gAudioLoadLockSH < 0x10U)
+ {
+ if (gAiBufferLengths[index] != 0)
+ {
osAiSetNextBuffer(gAiBuffers[index], gAiBufferLengths[index] * 4);
}
}
oldDmaCount = gCurrAudioFrameDmaCount;
- if (oldDmaCount > AUDIO_FRAME_DMA_QUEUE_SIZE) {
+ if (oldDmaCount > AUDIO_FRAME_DMA_QUEUE_SIZE)
+ {
}
gCurrAudioFrameDmaCount = 0;
decrease_sample_dma_ttls();
func_sh_802f41e4(gAudioResetStatus);
- if (osRecvMesg(D_SH_80350F88, (OSMesg *) &sp38, OS_MESG_NOBLOCK) != -1) {
- if (gAudioResetStatus == 0) {
+ if (osRecvMesg(D_SH_80350F88, (OSMesg *)&sp38, OS_MESG_NOBLOCK) != -1)
+ {
+ if (gAudioResetStatus == 0)
+ {
gAudioResetStatus = 5;
}
- gAudioResetPresetIdToLoad = (u8) sp38;
+ gAudioResetPresetIdToLoad = (u8)sp38;
}
- if (gAudioResetStatus != 0) {
- if (audio_shut_down_and_reset_step() == 0) {
- if (gAudioResetStatus == 0) {
- osSendMesg(D_SH_80350FA8, (OSMesg) (s32) gAudioResetPresetIdToLoad, OS_MESG_NOBLOCK);
+ if (gAudioResetStatus != 0)
+ {
+ if (audio_shut_down_and_reset_step() == 0)
+ {
+ if (gAudioResetStatus == 0)
+ {
+ osSendMesg(D_SH_80350FA8, (OSMesg)(s32) gAudioResetPresetIdToLoad, OS_MESG_NOBLOCK);
}
D_SH_80314FCC = 0;
return NULL;
}
}
- if (gAudioLoadLockSH >= 0x11U) {
+ if (gAudioLoadLockSH >= 0x11U)
+ {
return NULL;
}
- if (gAudioLoadLockSH != 0) {
+ if (gAudioLoadLockSH != 0)
+ {
gAudioLoadLockSH++;
}
gAudioTask = &gAudioTasks[gAudioTaskIndex];
- gAudioCmd = (u64 *) gAudioCmdBuffers[gAudioTaskIndex];
+ gAudioCmd = (u64 *)gAudioCmdBuffers[gAudioTaskIndex];
index = gCurrAiBufferIndex;
currAiBuffer = gAiBuffers[index];
- gAiBufferLengths[index] = (s16) ((((gAudioBufferParameters.samplesPerFrameTarget - samplesRemainingInAI) +
- EXTRA_BUFFERED_AI_SAMPLES_TARGET) & ~0xf) + SAMPLES_TO_OVERPRODUCE);
- if (gAiBufferLengths[index] < gAudioBufferParameters.minAiBufferLength) {
+ gAiBufferLengths[index] = (s16)((((gAudioBufferParameters.samplesPerFrameTarget - samplesRemainingInAI) +
+ EXTRA_BUFFERED_AI_SAMPLES_TARGET) & ~0xf) + SAMPLES_TO_OVERPRODUCE);
+ if (gAiBufferLengths[index] < gAudioBufferParameters.minAiBufferLength)
+ {
gAiBufferLengths[index] = gAudioBufferParameters.minAiBufferLength;
}
- if (gAiBufferLengths[index] > gAudioBufferParameters.maxAiBufferLength) {
+ if (gAiBufferLengths[index] > gAudioBufferParameters.maxAiBufferLength)
+ {
gAiBufferLengths[index] = gAudioBufferParameters.maxAiBufferLength;
}
- if (osRecvMesg(D_SH_80350F68, (OSMesg *) &sp34, 0) != -1) {
- do {
+ if (osRecvMesg(D_SH_80350F68, (OSMesg *)&sp34, 0) != -1)
+ {
+ do
+ {
func_802ad7ec(sp34);
- } while (osRecvMesg(D_SH_80350F68, (OSMesg *) &sp34, 0) != -1);
+ }
+ while (osRecvMesg(D_SH_80350F68, (OSMesg *)&sp34, 0) != -1);
}
flags = 0;
gAudioCmd = synthesis_execute(gAudioCmd, &writtenCmds, currAiBuffer, gAiBufferLengths[index]);
- gAudioRandom = (u32) (osGetCount() * (gAudioRandom + gAudioFrameCount));
- gAudioRandom = (u32) (gAiBuffers[index][gAudioFrameCount & 0xFF] + gAudioRandom);
+ gAudioRandom = (u32)(osGetCount() * (gAudioRandom + gAudioFrameCount));
+ gAudioRandom = (u32)(gAiBuffers[index][gAudioFrameCount & 0xFF] + gAudioRandom);
index = gAudioTaskIndex;
gAudioTask->msgqueue = NULL;
@@ -120,7 +138,7 @@ struct SPTask *create_next_audio_frame_task(void) {
task->type = M_AUDTASK;
task->flags = flags;
task->ucode_boot = rspF3DBootStart;
- task->ucode_boot_size = (u8 *) rspF3DStart - (u8 *) rspF3DBootStart;
+ task->ucode_boot_size = (u8 *)rspF3DStart - (u8 *)rspF3DBootStart;
task->ucode = rspAspMainStart;
task->ucode_data = rspAspMainDataStart;
task->ucode_size = 0x1000;
@@ -135,39 +153,50 @@ struct SPTask *create_next_audio_frame_task(void) {
task->yield_data_size = 0;
writtenCmdsCopy = writtenCmds;
- if (D_SH_80314FC8 < writtenCmdsCopy) {
+ if (D_SH_80314FC8 < writtenCmdsCopy)
+ {
D_SH_80314FC8 = writtenCmdsCopy;
}
- if (gAudioBufferParameters.presetUnk4 == 1) {
+ if (gAudioBufferParameters.presetUnk4 == 1)
+ {
return gAudioTask;
- } else {
+ }
+ else
+ {
D_SH_80314FCC = gAudioTask;
return NULL;
}
}
#else
-struct SPTask *create_next_audio_frame_task(void) {
+struct SPTask *create_next_audio_frame_task(void)
+{
return NULL;
}
-void create_next_audio_buffer(s16 *samples, u32 num_samples) {
+void create_next_audio_buffer(s16 *samples, u32 num_samples)
+{
s32 writtenCmds;
OSMesg msg;
gAudioFrameCount++;
decrease_sample_dma_ttls();
- if (osRecvMesg(D_SH_80350F88, &msg, 0) != -1) {
- gAudioResetPresetIdToLoad = (u8) (intptr_t) msg;
- if (gAudioResetStatus == 0) {
+ if (osRecvMesg(D_SH_80350F88, &msg, 0) != -1)
+ {
+ gAudioResetPresetIdToLoad = (u8)(intptr_t)
+ msg;
+ if (gAudioResetStatus == 0)
+ {
gAudioResetStatus = 5;
}
}
- if (gAudioResetStatus != 0) {
+ if (gAudioResetStatus != 0)
+ {
audio_reset_session();
gAudioResetStatus = 0;
}
- while (osRecvMesg(D_SH_80350F68, &msg, OS_MESG_NOBLOCK) != -1) {
- func_802ad7ec((u32) msg);
+ while (osRecvMesg(D_SH_80350F68, &msg, OS_MESG_NOBLOCK) != -1)
+ {
+ func_802ad7ec((u32)msg);
}
synthesis_execute(gAudioCmdBuffers[0], &writtenCmds, samples, num_samples);
gAudioRandom = ((gAudioRandom + gAudioFrameCount) * gAudioFrameCount);
@@ -176,99 +205,114 @@ void create_next_audio_buffer(s16 *samples, u32 num_samples) {
}
#endif
-void eu_process_audio_cmd(struct EuAudioCmd *cmd) {
+void eu_process_audio_cmd(struct EuAudioCmd *cmd)
+{
s32 i;
struct Note *note;
struct NoteSubEu *sub;
- switch (cmd->u.s.op) {
- case 0x81:
- preload_sequence(cmd->u.s.arg2, 3);
- break;
+ switch (cmd->u.s.op)
+ {
+ case 0x81:
+ preload_sequence(cmd->u.s.arg2, 3);
+ break;
- case 0x82:
- case 0x88:
- load_sequence(cmd->u.s.arg1, cmd->u.s.arg2, cmd->u.s.arg3);
- func_8031D690(cmd->u.s.arg1, cmd->u2.as_s32);
- break;
+ case 0x82:
+ case 0x88:
+ load_sequence(cmd->u.s.arg1, cmd->u.s.arg2, cmd->u.s.arg3);
+ func_8031D690(cmd->u.s.arg1, cmd->u2.as_s32);
+ break;
- case 0x83:
- if (gSequencePlayers[cmd->u.s.arg1].enabled != FALSE) {
- if (cmd->u2.as_s32 == 0) {
- sequence_player_disable(&gSequencePlayers[cmd->u.s.arg1]);
+ case 0x83:
+ if (gSequencePlayers[cmd->u.s.arg1].enabled != FALSE)
+ {
+ if (cmd->u2.as_s32 == 0)
+ {
+ sequence_player_disable(&gSequencePlayers[cmd->u.s.arg1]);
+ }
+ else
+ {
+ seq_player_fade_to_zero_volume(cmd->u.s.arg1, cmd->u2.as_s32);
+ }
}
- else {
- seq_player_fade_to_zero_volume(cmd->u.s.arg1, cmd->u2.as_s32);
+ break;
+
+ case 0x84:
+ break;
+
+ case 0xf0:
+ gSoundMode = cmd->u2.as_s32;
+ break;
+
+ case 0xf1:
+ for (i = 0; i < 4; i++)
+ {
+ gSequencePlayers[i].muted = TRUE;
+ gSequencePlayers[i].recalculateVolume = TRUE;
}
- }
- break;
+ break;
- case 0x84:
- break;
-
- case 0xf0:
- gSoundMode = cmd->u2.as_s32;
- break;
-
- case 0xf1:
- for (i = 0; i < 4; i++) {
- gSequencePlayers[i].muted = TRUE;
- gSequencePlayers[i].recalculateVolume = TRUE;
- }
- break;
-
- case 0xf2:
- if (cmd->u2.as_s32 == 1) {
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
- note = &gNotes[i];
- sub = ¬e->noteSubEu;
- if (note->noteSubEu.enabled && note->unkSH34 == 0) {
- if ((note->parentLayer->seqChannel->muteBehavior & 8) != 0) {
- sub->finished = TRUE;
+ case 0xf2:
+ if (cmd->u2.as_s32 == 1)
+ {
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
+ note = &gNotes[i];
+ sub = ¬e->noteSubEu;
+ if (note->noteSubEu.enabled && note->unkSH34 == 0)
+ {
+ if ((note->parentLayer->seqChannel->muteBehavior & 8) != 0)
+ {
+ sub->finished = TRUE;
+ }
}
}
}
- }
- for (i = 0; i < 4; i++) {
- gSequencePlayers[i].muted = FALSE;
- gSequencePlayers[i].recalculateVolume = TRUE;
- }
- break;
+ for (i = 0; i < 4; i++)
+ {
+ gSequencePlayers[i].muted = FALSE;
+ gSequencePlayers[i].recalculateVolume = TRUE;
+ }
+ break;
- case 0xf3:
- func_sh_802f3024(cmd->u.s.arg1, cmd->u.s.arg2, cmd->u.s.arg3);
- break;
+ case 0xf3:
+ func_sh_802f3024(cmd->u.s.arg1, cmd->u.s.arg2, cmd->u.s.arg3);
+ break;
- case 0xf4:
- func_sh_802f30f4(cmd->u.s.arg1, cmd->u.s.arg2, cmd->u.s.arg3, &gUnkQueue1);
- break;
+ case 0xf4:
+ func_sh_802f30f4(cmd->u.s.arg1, cmd->u.s.arg2, cmd->u.s.arg3, &gUnkQueue1);
+ break;
- case 0xf5:
- func_sh_802f3158(cmd->u.s.arg1, cmd->u.s.arg2, cmd->u.s.arg3, &gUnkQueue1);
- break;
+ case 0xf5:
+ func_sh_802f3158(cmd->u.s.arg1, cmd->u.s.arg2, cmd->u.s.arg3, &gUnkQueue1);
+ break;
- case 0xf6:
- func_sh_802f3288(cmd->u.s.arg2);
- break;
+ case 0xf6:
+ func_sh_802f3288(cmd->u.s.arg2);
+ break;
}
}
-void seq_player_fade_to_zero_volume(s32 arg0, s32 fadeOutTime) {
+void seq_player_fade_to_zero_volume(s32 arg0, s32 fadeOutTime)
+{
struct SequencePlayer *player;
- if (fadeOutTime == 0) {
+ if (fadeOutTime == 0)
+ {
fadeOutTime = 1;
}
player = &gSequencePlayers[arg0];
player->state = 2;
player->fadeRemainingFrames = fadeOutTime;
- player->fadeVelocity = -(player->fadeVolume / (f32) fadeOutTime);
+ player->fadeVelocity = -(player->fadeVolume / (f32)fadeOutTime);
}
-void func_8031D690(s32 playerIndex, s32 fadeInTime) {
+void func_8031D690(s32 playerIndex, s32 fadeInTime)
+{
struct SequencePlayer *player;
- if (fadeInTime != 0) {
+ if (fadeInTime != 0)
+ {
player = &gSequencePlayers[playerIndex];
player->state = 1;
player->fadeTimerUnkEu = fadeInTime;
@@ -278,7 +322,8 @@ void func_8031D690(s32 playerIndex, s32 fadeInTime) {
}
}
-void port_eu_init_queues(void) {
+void port_eu_init_queues(void)
+{
D_SH_80350F18 = 0;
D_SH_80350F19 = 0;
D_SH_80350F38 = &D_SH_80350F20;
@@ -292,36 +337,43 @@ void port_eu_init_queues(void) {
}
extern struct EuAudioCmd sAudioCmd[0x100];
-void func_802ad6f0(s32 arg0, s32 *arg1) {
+void func_802ad6f0(s32 arg0, s32 *arg1)
+{
struct EuAudioCmd *cmd = &sAudioCmd[D_SH_80350F18 & 0xff];
cmd->u.first = arg0;
cmd->u2.as_u32 = *arg1;
D_SH_80350F18++;
- if (D_SH_80350F18 == D_SH_80350F19) {
+ if (D_SH_80350F18 == D_SH_80350F19)
+ {
D_SH_80350F18--;
}
}
-void func_802ad728(u32 arg0, f32 arg1) {
- func_802ad6f0(arg0, (s32 *) &arg1);
+void func_802ad728(u32 arg0, f32 arg1)
+{
+ func_802ad6f0(arg0, (s32 *)&arg1);
}
-void func_802ad74c(u32 arg0, u32 arg1) {
- func_802ad6f0(arg0, (s32 *) &arg1);
+void func_802ad74c(u32 arg0, u32 arg1)
+{
+ func_802ad6f0(arg0, (s32 *)&arg1);
}
-void func_802ad770(u32 arg0, s8 arg1) {
+void func_802ad770(u32 arg0, s8 arg1)
+{
s32 sp1C = arg1 << 24;
func_802ad6f0(arg0, &sp1C);
}
char shindouDebugPrint133[] = "AudioSend: %d -> %d (%d)\n";
-void func_sh_802F64C8(void) {
+void func_sh_802F64C8(void)
+{
static s32 D_SH_8031503C = 0;
s32 mesg;
- if (((D_SH_80350F18 - D_SH_80350F19 + 0x100) & 0xff) > D_SH_8031503C) {
+ if (((D_SH_80350F18 - D_SH_80350F19 + 0x100) & 0xff) > D_SH_8031503C)
+ {
D_SH_8031503C = (D_SH_80350F18 - D_SH_80350F19 + 0x100) & 0xff;
}
mesg = ((D_SH_80350F19 & 0xff) << 8) | (D_SH_80350F18 & 0xff);
@@ -329,11 +381,13 @@ void func_sh_802F64C8(void) {
D_SH_80350F19 = D_SH_80350F18;
}
-void func_sh_802f6540(void) {
+void func_sh_802f6540(void)
+{
D_SH_80350F19 = D_SH_80350F18;
}
-void func_802ad7ec(u32 arg0) {
+void func_802ad7ec(u32 arg0)
+{
struct EuAudioCmd *cmd;
struct SequencePlayer *seqPlayer;
struct SequenceChannel *chan;
@@ -347,102 +401,120 @@ void func_802ad7ec(u32 arg0) {
static u8 D_SH_80315098 = 0;
static u8 D_SH_8031509C = 0;
- if (D_SH_8031509C == 0) {
+ if (D_SH_8031509C == 0)
+ {
D_SH_80315098 = (arg0 >> 8) & 0xff;
}
end = arg0 & 0xff;
- for (;;) {
- if (D_SH_80315098 == end) {
+ for (;;)
+ {
+ if (D_SH_80315098 == end)
+ {
D_SH_8031509C = 0;
break;
}
cmd = &sAudioCmd[D_SH_80315098 & 0xff];
D_SH_80315098++;
- if (cmd->u.s.op == 0xf8) {
+ if (cmd->u.s.op == 0xf8)
+ {
D_SH_8031509C = 1;
break;
}
- else if ((cmd->u.s.op & 0xf0) == 0xf0) {
+ else if ((cmd->u.s.op & 0xf0) == 0xf0)
+ {
eu_process_audio_cmd(cmd);
}
- else if (cmd->u.s.arg1 < SEQUENCE_PLAYERS) {
+ else if (cmd->u.s.arg1 < SEQUENCE_PLAYERS)
+ {
seqPlayer = &gSequencePlayers[cmd->u.s.arg1];
- if ((cmd->u.s.op & 0x80) != 0) {
+ if ((cmd->u.s.op & 0x80) != 0)
+ {
eu_process_audio_cmd(cmd);
}
- else if ((cmd->u.s.op & 0x40) != 0) {
- switch (cmd->u.s.op) {
- case 0x41:
- if (seqPlayer->fadeVolumeScale != cmd->u2.as_f32) {
- seqPlayer->fadeVolumeScale = cmd->u2.as_f32;
- seqPlayer->recalculateVolume = TRUE;
- }
- break;
+ else if ((cmd->u.s.op & 0x40) != 0)
+ {
+ switch (cmd->u.s.op)
+ {
+ case 0x41:
+ if (seqPlayer->fadeVolumeScale != cmd->u2.as_f32)
+ {
+ seqPlayer->fadeVolumeScale = cmd->u2.as_f32;
+ seqPlayer->recalculateVolume = TRUE;
+ }
+ break;
- case 0x47:
- seqPlayer->tempo = cmd->u2.as_s32 * TATUMS_PER_BEAT;
- break;
+ case 0x47:
+ seqPlayer->tempo = cmd->u2.as_s32 * TATUMS_PER_BEAT;
+ break;
- case 0x49:
- seqPlayer->tempoAdd = cmd->u2.as_s32 * TEMPO_SCALE;
- break;
+ case 0x49:
+ seqPlayer->tempoAdd = cmd->u2.as_s32 * TEMPO_SCALE;
+ break;
- case 0x48:
- seqPlayer->transposition = cmd->u2.as_s8;
- break;
+ case 0x48:
+ seqPlayer->transposition = cmd->u2.as_s8;
+ break;
- case 0x46:
- seqPlayer->seqVariationEu[cmd->u.s.arg3] = cmd->u2.as_s8;
- break;
+ case 0x46:
+ seqPlayer->seqVariationEu[cmd->u.s.arg3] = cmd->u2.as_s8;
+ break;
}
}
- else if (seqPlayer->enabled != FALSE && cmd->u.s.arg2 < 0x10) {
+ else if (seqPlayer->enabled != FALSE && cmd->u.s.arg2 < 0x10)
+ {
chan = seqPlayer->channels[cmd->u.s.arg2];
if (IS_SEQUENCE_CHANNEL_VALID(chan))
{
- switch (cmd->u.s.op) {
- case 1:
- if (chan->volumeScale != cmd->u2.as_f32) {
- chan->volumeScale = cmd->u2.as_f32;
- chan->changes.as_bitfields.volume = TRUE;
- }
- break;
- case 2:
- if (chan->volume != cmd->u2.as_f32) {
- chan->volume = cmd->u2.as_f32;
- chan->changes.as_bitfields.volume = TRUE;
- }
- break;
- case 3:
- if (chan->newPan != cmd->u2.as_s8) {
- chan->newPan = cmd->u2.as_s8;
- chan->changes.as_bitfields.pan = TRUE;
- }
- break;
- case 4:
- if (chan->freqScale != cmd->u2.as_f32) {
- chan->freqScale = cmd->u2.as_f32;
- chan->changes.as_bitfields.freqScale = TRUE;
- }
- break;
- case 5:
- //! @bug u8 s8 comparison (but harmless)
- if (chan->reverbVol != cmd->u2.as_s8) {
- chan->reverbVol = cmd->u2.as_s8;
- }
- break;
- case 6:
- if (cmd->u.s.arg3 < 8) {
- chan->soundScriptIO[cmd->u.s.arg3] = cmd->u2.as_s8;
- }
- break;
- case 8:
- chan->stopSomething2 = cmd->u2.as_s8;
- break;
- case 9:
- chan->muteBehavior = cmd->u2.as_s8;
+ switch (cmd->u.s.op)
+ {
+ case 1:
+ if (chan->volumeScale != cmd->u2.as_f32)
+ {
+ chan->volumeScale = cmd->u2.as_f32;
+ chan->changes.as_bitfields.volume = TRUE;
+ }
+ break;
+ case 2:
+ if (chan->volume != cmd->u2.as_f32)
+ {
+ chan->volume = cmd->u2.as_f32;
+ chan->changes.as_bitfields.volume = TRUE;
+ }
+ break;
+ case 3:
+ if (chan->newPan != cmd->u2.as_s8)
+ {
+ chan->newPan = cmd->u2.as_s8;
+ chan->changes.as_bitfields.pan = TRUE;
+ }
+ break;
+ case 4:
+ if (chan->freqScale != cmd->u2.as_f32)
+ {
+ chan->freqScale = cmd->u2.as_f32;
+ chan->changes.as_bitfields.freqScale = TRUE;
+ }
+ break;
+ case 5:
+ //! @bug u8 s8 comparison (but harmless)
+ if (chan->reverbVol != cmd->u2.as_s8)
+ {
+ chan->reverbVol = cmd->u2.as_s8;
+ }
+ break;
+ case 6:
+ if (cmd->u.s.arg3 < 8)
+ {
+ chan->soundScriptIO[cmd->u.s.arg3] = cmd->u2.as_s8;
+ }
+ break;
+ case 8:
+ chan->stopSomething2 = cmd->u2.as_s8;
+ break;
+ case 9:
+ chan->muteBehavior = cmd->u2.as_s8;
}
}
}
@@ -452,74 +524,91 @@ void func_802ad7ec(u32 arg0) {
}
}
-u32 func_sh_802f6878(s32 *arg0) {
+u32 func_sh_802f6878(s32 *arg0)
+{
u32 sp1C;
- if (osRecvMesg(&gUnkQueue1, (OSMesg *) &sp1C, 0) == -1) {
+ if (osRecvMesg(&gUnkQueue1, (OSMesg *)&sp1C, 0) == -1)
+ {
*arg0 = 0;
return 0U;
}
- *arg0 = (s32) (sp1C & 0xFFFFFF);
+ *arg0 = (s32)(sp1C & 0xFFFFFF);
return sp1C >> 0x18;
}
-u8 *func_sh_802f68e0(u32 index, u32 *a1) {
+u8 *func_sh_802f68e0(u32 index, u32 *a1)
+{
return func_sh_802f3220(index, a1);
}
-s32 func_sh_802f6900(void) {
+s32 func_sh_802f6900(void)
+{
s32 ret;
s32 sp18;
- ret = osRecvMesg(D_SH_80350FA8, (OSMesg *) &sp18, 0);
+ ret = osRecvMesg(D_SH_80350FA8, (OSMesg *)&sp18, 0);
- if (ret == -1) {
+ if (ret == -1)
+ {
return 0;
}
- if (sp18 != gAudioResetPresetIdToLoad) {
+ if (sp18 != gAudioResetPresetIdToLoad)
+ {
return 0;
- } else {
+ }
+ else
+ {
return 1;
}
}
// TODO: (Scrub C)
-void func_sh_802f6958(OSMesg mesg) {
+void func_sh_802f6958(OSMesg mesg)
+{
s32 a;
OSMesg recvMesg;
- do {
+ do
+ {
a = -1;
- } while (osRecvMesg(D_SH_80350FA8, &recvMesg, OS_MESG_NOBLOCK) != a);
+ }
+ while (osRecvMesg(D_SH_80350FA8, &recvMesg, OS_MESG_NOBLOCK) != a);
func_sh_802f6540();
osSendMesg(D_SH_80350F88, mesg, OS_MESG_NOBLOCK);
}
-void func_sh_802f69cc(void) {
+void func_sh_802f69cc(void)
+{
gAudioLoadLockSH = 1;
func_sh_802f6958(0);
gAudioResetStatus = 0;
}
-s32 func_sh_802f6a08(s32 playerIndex, s32 channelIndex, s32 soundScriptIOIndex) {
+s32 func_sh_802f6a08(s32 playerIndex, s32 channelIndex, s32 soundScriptIOIndex)
+{
struct SequenceChannel *seqChannel;
struct SequencePlayer *player;
player = &gSequencePlayers[playerIndex];
- if (player->enabled) {
+ if (player->enabled)
+ {
seqChannel = player->channels[channelIndex];
- if (IS_SEQUENCE_CHANNEL_VALID(seqChannel)) {
+ if (IS_SEQUENCE_CHANNEL_VALID(seqChannel))
+ {
return seqChannel->soundScriptIO[soundScriptIOIndex];
}
}
return -1;
}
-s8 func_sh_802f6a6c(s32 playerIndex, s32 index) {
+s8 func_sh_802f6a6c(s32 playerIndex, s32 index)
+{
return gSequencePlayers[playerIndex].seqVariationEu[index];
}
-void port_eu_init(void) {
+void port_eu_init(void)
+{
port_eu_init_queues();
}
@@ -544,7 +633,7 @@ char shindouDebugPrint155[] = "Audio: voiceman: Percpointer NULL %d,%d\n";
char shindouDebugPrint156[] = "--4 %x\n";
char shindouDebugPrint157[] = "NoteOff Comes during wait release %x (note %x)\n";
char shindouDebugPrint158[] = "Slow Release Batting\n";
-u8 euUnknownData_8030194c[4] = { 0x40, 0x20, 0x10, 0x08 };
+u8 euUnknownData_8030194c[4] = {0x40, 0x20, 0x10, 0x08};
char shindouDebugPrint159[] = "Audio:Wavemem: Bad voiceno (%d)\n";
char shindouDebugPrint160[] = "Audio: C-Alloc : Dealloc voice is NULL\n";
char shindouDebugPrint161[] = "Alloc Error:Dim voice-Alloc %d";
diff --git a/src/decomp/audio/seqplayer.c b/src/decomp/audio/seqplayer.c
index c9e95b6..be112f9 100644
--- a/src/decomp/audio/seqplayer.c
+++ b/src/decomp/audio/seqplayer.c
@@ -24,11 +24,15 @@ s32 seq_channel_layer_process_script_part4(struct SequenceChannelLayer *layer, s
s32 seq_channel_layer_process_script_part5(struct SequenceChannelLayer *layer, s32 cmd);
#endif
void seq_channel_layer_process_script(struct SequenceChannelLayer *layer);
-void sequence_channel_process_script(struct SequenceChannel *seqChannel);
-u8 get_instrument(struct SequenceChannel *seqChannel, u8 instId, struct Instrument **instOut,
- struct AdsrSettings *adsr);
-void sequence_channel_init(struct SequenceChannel *seqChannel) {
+void sequence_channel_process_script(struct SequenceChannel *seqChannel);
+
+u8 get_instrument(
+ struct SequenceChannel *seqChannel, u8 instId, struct Instrument **instOut,
+ struct AdsrSettings *adsr);
+
+void sequence_channel_init(struct SequenceChannel *seqChannel)
+{
s32 i;
seqChannel->enabled = FALSE;
@@ -39,7 +43,7 @@ void sequence_channel_init(struct SequenceChannel *seqChannel) {
seqChannel->stereoHeadsetEffects = FALSE;
seqChannel->transposition = 0;
seqChannel->largeNotes = FALSE;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
seqChannel->bookOffset = 0;
seqChannel->changes.as_u8 = 0xff;
seqChannel->scriptState.depth = 0;
@@ -47,7 +51,7 @@ void sequence_channel_init(struct SequenceChannel *seqChannel) {
seqChannel->panChannelWeight = 0x80;
seqChannel->noteUnused = NULL;
seqChannel->reverbIndex = 0;
-#else
+ #else
seqChannel->scriptState.depth = 0;
seqChannel->volume = 1.0f;
seqChannel->volumeScale = 1.0f;
@@ -55,22 +59,22 @@ void sequence_channel_init(struct SequenceChannel *seqChannel) {
seqChannel->pan = 0.5f;
seqChannel->panChannelWeight = 1.0f;
seqChannel->noteUnused = NULL;
-#endif
+ #endif
seqChannel->reverbVol = 0;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
seqChannel->synthesisVolume = 0;
-#endif
+ #endif
seqChannel->notePriority = NOTE_PRIORITY_DEFAULT;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
seqChannel->unkSH06 = 1;
-#endif
+ #endif
seqChannel->delay = 0;
seqChannel->adsr.envelope = gDefaultEnvelope;
seqChannel->adsr.releaseRate = 0x20;
seqChannel->adsr.sustain = 0;
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #if defined(VERSION_JP) || defined(VERSION_US)
seqChannel->updatesPerFrameUnused = gAudioUpdatesPerFrame;
-#endif
+ #endif
seqChannel->vibratoRateTarget = 0x800;
seqChannel->vibratoRateStart = 0x800;
seqChannel->vibratoExtentTarget = 0;
@@ -78,16 +82,17 @@ void sequence_channel_init(struct SequenceChannel *seqChannel) {
seqChannel->vibratoRateChangeDelay = 0;
seqChannel->vibratoExtentChangeDelay = 0;
seqChannel->vibratoDelay = 0;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
seqChannel->filter = NULL;
-#endif
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #endif
+ #if defined(VERSION_EU) || defined(VERSION_SH)
seqChannel->volume = 1.0f;
seqChannel->volumeScale = 1.0f;
seqChannel->freqScale = 1.0f;
-#endif
+ #endif
- for (i = 0; i < 8; i++) {
+ for (i = 0; i < 8; i++)
+ {
seqChannel->soundScriptIO[i] = -1;
}
@@ -95,20 +100,25 @@ void sequence_channel_init(struct SequenceChannel *seqChannel) {
init_note_lists(&seqChannel->notePool);
}
-s32 seq_channel_set_layer(struct SequenceChannel *seqChannel, s32 layerIndex) {
+s32 seq_channel_set_layer(struct SequenceChannel *seqChannel, s32 layerIndex)
+{
struct SequenceChannelLayer *layer;
- if (seqChannel->layers[layerIndex] == NULL) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ if (seqChannel->layers[layerIndex] == NULL)
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
struct SequenceChannelLayer *layer;
-#endif
+ #endif
layer = audio_list_pop_back(&gLayerFreeList);
seqChannel->layers[layerIndex] = layer;
- if (layer == NULL) {
+ if (layer == NULL)
+ {
seqChannel->layers[layerIndex] = NULL;
return -1;
}
- } else {
+ }
+ else
+ {
seq_channel_layer_note_decay(seqChannel->layers[layerIndex]);
}
@@ -120,56 +130,61 @@ s32 seq_channel_set_layer(struct SequenceChannel *seqChannel, s32 layerIndex) {
layer->stopSomething = FALSE;
layer->continuousNotes = FALSE;
layer->finished = FALSE;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
layer->ignoreDrumPan = FALSE;
-#endif
-#ifdef VERSION_SH
+ #endif
+ #ifdef VERSION_SH
layer->reverbBits.asByte = 0x40;
-#endif
+ #endif
layer->portamento.mode = 0;
layer->scriptState.depth = 0;
layer->status = SOUND_LOAD_STATUS_NOT_LOADED;
layer->noteDuration = 0x80;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
layer->pan = 0x40;
-#endif
+ #endif
layer->transposition = 0;
layer->delay = 0;
layer->duration = 0;
layer->delayUnused = 0;
layer->note = NULL;
layer->instrument = NULL;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
layer->freqScale = 1.0f;
layer->velocitySquare = 0.0f;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
layer->freqScaleMultiplier = 1.0f;
-#endif
+ #endif
layer->instOrWave = 0xff;
-#else
+ #else
layer->velocitySquare = 0.0f;
layer->pan = 0.5f;
-#endif
+ #endif
return 0;
}
-void seq_channel_layer_disable(struct SequenceChannelLayer *layer) {
- if (layer != NULL) {
+void seq_channel_layer_disable(struct SequenceChannelLayer *layer)
+{
+ if (layer != NULL)
+ {
seq_channel_layer_note_decay(layer);
layer->enabled = FALSE;
layer->finished = TRUE;
}
}
-void seq_channel_layer_free(struct SequenceChannel *seqChannel, s32 layerIndex) {
+void seq_channel_layer_free(struct SequenceChannel *seqChannel, s32 layerIndex)
+{
struct SequenceChannelLayer *layer = seqChannel->layers[layerIndex];
- if (layer != NULL) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ if (layer != NULL)
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
audio_list_push_back(&gLayerFreeList, &layer->listItem);
-#else
+ #else
struct AudioListItem *item = &layer->listItem;
- if (item->prev == NULL) {
+ if (item->prev == NULL)
+ {
gLayerFreeList.prev->next = item;
item->prev = gLayerFreeList.prev;
item->next = &gLayerFreeList;
@@ -177,15 +192,17 @@ void seq_channel_layer_free(struct SequenceChannel *seqChannel, s32 layerIndex)
gLayerFreeList.u.count++;
item->pool = gLayerFreeList.pool;
}
-#endif
+ #endif
seq_channel_layer_disable(layer);
seqChannel->layers[layerIndex] = NULL;
}
}
-void sequence_channel_disable(struct SequenceChannel *seqChannel) {
+void sequence_channel_disable(struct SequenceChannel *seqChannel)
+{
s32 i;
- for (i = 0; i < LAYERS_MAX; i++) {
+ for (i = 0; i < LAYERS_MAX; i++)
+ {
seq_channel_layer_free(seqChannel, i);
}
@@ -194,37 +211,47 @@ void sequence_channel_disable(struct SequenceChannel *seqChannel) {
seqChannel->finished = TRUE;
}
-struct SequenceChannel *allocate_sequence_channel(void) {
+struct SequenceChannel *allocate_sequence_channel(void)
+{
s32 i;
- for (i = 0; i < ARRAY_COUNT(gSequenceChannels); i++) {
- if (gSequenceChannels[i].seqPlayer == NULL) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ for (i = 0; i < ARRAY_COUNT(gSequenceChannels); i++)
+ {
+ if (gSequenceChannels[i].seqPlayer == NULL)
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
return &gSequenceChannels[i];
-#else
+ #else
return gSequenceChannels + i;
-#endif
+ #endif
}
}
return &gSequenceChannelNone;
}
-void sequence_player_init_channels(struct SequencePlayer *seqPlayer, u16 channelBits) {
+void sequence_player_init_channels(struct SequencePlayer *seqPlayer, u16 channelBits)
+{
struct SequenceChannel *seqChannel;
s32 i;
- for (i = 0; i < CHANNELS_MAX; i++) {
- if (channelBits & 1) {
+ for (i = 0; i < CHANNELS_MAX; i++)
+ {
+ if (channelBits & 1)
+ {
seqChannel = seqPlayer->channels[i];
- if (IS_SEQUENCE_CHANNEL_VALID(seqChannel) == TRUE && seqChannel->seqPlayer == seqPlayer) {
+ if (IS_SEQUENCE_CHANNEL_VALID(seqChannel) == TRUE && seqChannel->seqPlayer == seqPlayer)
+ {
sequence_channel_disable(seqChannel);
seqChannel->seqPlayer = NULL;
}
seqChannel = allocate_sequence_channel();
- if (IS_SEQUENCE_CHANNEL_VALID(seqChannel) == FALSE) {
+ if (IS_SEQUENCE_CHANNEL_VALID(seqChannel) == FALSE)
+ {
eu_stubbed_printf_0("Audio:Track:Warning: No Free Notetrack\n");
gAudioErrorFlags = i + 0x10000;
seqPlayer->channels[i] = seqChannel;
- } else {
+ }
+ else
+ {
sequence_channel_init(seqChannel);
seqPlayer->channels[i] = seqChannel;
seqChannel->seqPlayer = seqPlayer;
@@ -233,128 +260,157 @@ void sequence_player_init_channels(struct SequencePlayer *seqPlayer, u16 channel
seqChannel->noteAllocPolicy = seqPlayer->noteAllocPolicy;
}
}
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
channelBits = channelBits >> 1;
-#else
+ #else
channelBits >>= 1;
-#endif
+ #endif
}
}
-void sequence_player_disable_channels(struct SequencePlayer *seqPlayer, u16 channelBits) {
+void sequence_player_disable_channels(struct SequencePlayer *seqPlayer, u16 channelBits)
+{
struct SequenceChannel *seqChannel;
s32 i;
eu_stubbed_printf_0("SUBTRACK DIM\n");
- for (i = 0; i < CHANNELS_MAX; i++) {
- if (channelBits & 1) {
+ for (i = 0; i < CHANNELS_MAX; i++)
+ {
+ if (channelBits & 1)
+ {
seqChannel = seqPlayer->channels[i];
- if (IS_SEQUENCE_CHANNEL_VALID(seqChannel) == TRUE) {
- if (seqChannel->seqPlayer == seqPlayer) {
+ if (IS_SEQUENCE_CHANNEL_VALID(seqChannel) == TRUE)
+ {
+ if (seqChannel->seqPlayer == seqPlayer)
+ {
sequence_channel_disable(seqChannel);
seqChannel->seqPlayer = NULL;
}
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
else {
-#ifdef VERSION_EU
- stubbed_printf("Audio:Track: Warning SUBTRACK PARENT CHANGED\n");
-#endif
+ #ifdef VERSION_EU
+ stubbed_printf("Audio:Track: Warning SUBTRACK PARENT CHANGED\n");
+ #endif
}
-#endif
+ #endif
seqPlayer->channels[i] = &gSequenceChannelNone;
}
}
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
channelBits = channelBits >> 1;
-#else
+ #else
channelBits >>= 1;
-#endif
+ #endif
}
}
-void sequence_channel_enable(struct SequencePlayer *seqPlayer, u8 channelIndex, void *script) {
+void sequence_channel_enable(struct SequencePlayer *seqPlayer, u8 channelIndex, void *script)
+{
struct SequenceChannel *seqChannel = seqPlayer->channels[channelIndex];
s32 i;
- if (IS_SEQUENCE_CHANNEL_VALID(seqChannel) == FALSE) {
-#ifdef VERSION_EU
+ if (IS_SEQUENCE_CHANNEL_VALID(seqChannel) == FALSE)
+ {
+ #ifdef VERSION_EU
struct SequencePlayer *bgMusic = &gSequencePlayers[0];
struct SequencePlayer *miscMusic = &gSequencePlayers[1];
- if (seqPlayer == bgMusic) {
+ if (seqPlayer == bgMusic)
+ {
stubbed_printf("GROUP 0:");
- } else if (seqPlayer == miscMusic) {
+ }
+ else if (seqPlayer == miscMusic)
+ {
stubbed_printf("GROUP 1:");
- } else {
+ }
+ else
+ {
stubbed_printf("SEQID %d,BANKID %d\n",
- seqPlayer->seqId, seqPlayer->defaultBank[0]);
+ seqPlayer->seqId, seqPlayer->defaultBank[0]);
}
stubbed_printf("ERR:SUBTRACK %d NOT ALLOCATED\n", channelIndex);
-#endif
- } else {
+ #endif
+ }
+ else
+ {
seqChannel->enabled = TRUE;
seqChannel->finished = FALSE;
seqChannel->scriptState.depth = 0;
seqChannel->scriptState.pc = script;
seqChannel->delay = 0;
- for (i = 0; i < LAYERS_MAX; i++) {
- if (seqChannel->layers[i] != NULL) {
+ for (i = 0; i < LAYERS_MAX; i++)
+ {
+ if (seqChannel->layers[i] != NULL)
+ {
seq_channel_layer_free(seqChannel, i);
}
}
}
}
-void sequence_player_disable(struct SequencePlayer *seqPlayer) {
+void sequence_player_disable(struct SequencePlayer *seqPlayer)
+{
sequence_player_disable_channels(seqPlayer, 0xffff);
note_pool_clear(&seqPlayer->notePool);
seqPlayer->finished = TRUE;
seqPlayer->enabled = FALSE;
if (IS_SEQ_LOAD_COMPLETE(seqPlayer->seqId)
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
&& gSeqLoadStatus[seqPlayer->seqId] != 5
-#endif
- ) {
+ #endif
+ )
+ {
gSeqLoadStatus[seqPlayer->seqId] = SOUND_LOAD_STATUS_DISCARDABLE;
}
if (IS_BANK_LOAD_COMPLETE(seqPlayer->defaultBank[0])
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
&& gBankLoadStatus[seqPlayer->defaultBank[0]] != 5
-#endif
- ) {
-#ifdef VERSION_SH
+ #endif
+ )
+ {
+ #ifdef VERSION_SH
gBankLoadStatus[seqPlayer->defaultBank[0]] = 4;
-#else
+ #else
gBankLoadStatus[seqPlayer->defaultBank[0]] = SOUND_LOAD_STATUS_DISCARDABLE;
-#endif
+ #endif
}
// (Note that if this is called from alloc_bank_or_seq, the side will get swapped
// later in that function. Thus, we signal that we want to load into the slot
// of the bank that we no longer need.)
-#if defined(VERSION_EU) || defined(VERSION_SH)
- if (seqPlayer->defaultBank[0] == gBankLoadedPool.temporary.entries[0].id) {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ if (seqPlayer->defaultBank[0] == gBankLoadedPool.temporary.entries[0].id)
+ {
gBankLoadedPool.temporary.nextSide = 1;
- } else if (seqPlayer->defaultBank[0] == gBankLoadedPool.temporary.entries[1].id) {
+ }
+ else if (seqPlayer->defaultBank[0] == gBankLoadedPool.temporary.entries[1].id)
+ {
gBankLoadedPool.temporary.nextSide = 0;
}
-#else
- if (gBankLoadedPool.temporary.entries[0].id == seqPlayer->defaultBank[0]) {
+ #else
+ if (gBankLoadedPool.temporary.entries[0].id == seqPlayer->defaultBank[0])
+ {
gBankLoadedPool.temporary.nextSide = 1;
- } else if (gBankLoadedPool.temporary.entries[1].id == seqPlayer->defaultBank[0]) {
+ }
+ else if (gBankLoadedPool.temporary.entries[1].id == seqPlayer->defaultBank[0])
+ {
gBankLoadedPool.temporary.nextSide = 0;
}
-#endif
+ #endif
}
/**
* Add an item to the end of a list, if it's not already in any list.
*/
-void audio_list_push_back(struct AudioListItem *list, struct AudioListItem *item) {
- if (item->prev != NULL) {
+void audio_list_push_back(struct AudioListItem *list, struct AudioListItem *item)
+{
+ if (item->prev != NULL)
+ {
eu_stubbed_printf_0("Error:Same List Add\n");
- } else {
+ }
+ else
+ {
list->prev->next = item;
item->prev = list->prev;
item->next = list;
@@ -367,9 +423,11 @@ void audio_list_push_back(struct AudioListItem *list, struct AudioListItem *item
/**
* Remove the last item from a list, and return it (or NULL if empty).
*/
-void *audio_list_pop_back(struct AudioListItem *list) {
+void *audio_list_pop_back(struct AudioListItem *list)
+{
struct AudioListItem *item = list->prev;
- if (item == list) {
+ if (item == list)
+ {
return NULL;
}
item->prev->next = list;
@@ -379,7 +437,8 @@ void *audio_list_pop_back(struct AudioListItem *list) {
return item->u.value;
}
-void init_layer_freelist(void) {
+void init_layer_freelist(void)
+{
s32 i;
gLayerFreeList.prev = &gLayerFreeList;
@@ -387,51 +446,60 @@ void init_layer_freelist(void) {
gLayerFreeList.u.count = 0;
gLayerFreeList.pool = NULL;
- for (i = 0; i < ARRAY_COUNT(gSequenceLayers); i++) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ for (i = 0; i < ARRAY_COUNT(gSequenceLayers); i++)
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
gSequenceLayers[i].listItem.u.value = &gSequenceLayers[i];
-#else
+ #else
gSequenceLayers[i].listItem.u.value = gSequenceLayers + i;
-#endif
+ #endif
gSequenceLayers[i].listItem.prev = NULL;
audio_list_push_back(&gLayerFreeList, &gSequenceLayers[i].listItem);
}
}
-u8 m64_read_u8(struct M64ScriptState *state) {
- DEBUG_PRINT("m64_read_u8()");
- DEBUG_PRINT("- state at %x", state);
+u8 m64_read_u8(struct M64ScriptState *state)
+{
+ DEBUG_PRINT("m64_read_u8()");
+ DEBUG_PRINT("- state at %x", state);
u8 *midiArg = state->pc++;
- DEBUG_PRINT("- read u8 (%d) at (%x)", *midiArg, midiArg);
+ DEBUG_PRINT("- read u8 (%d) at (%x)", *midiArg, midiArg);
return *midiArg;
}
-s16 m64_read_s16(struct M64ScriptState *state) {
- s16 ret = *(state->pc++) << 8;
- ret = *(state->pc++) | ret;
+s16 m64_read_s16(struct M64ScriptState *state)
+{
+ s16 ret = *state->pc++ << 8;
+ ret = *state->pc++ | ret;
return ret;
}
-u16 m64_read_compressed_u16(struct M64ScriptState *state) {
- u16 ret = *(state->pc++);
- if (ret & 0x80) {
- ret = (ret << 8) & 0x7f00;
- ret = *(state->pc++) | ret;
+u16 m64_read_compressed_u16(struct M64ScriptState *state)
+{
+ u16 ret = *state->pc++;
+ if (ret & 0x80)
+ {
+ ret = ret << 8 & 0x7f00;
+ ret = *state->pc++ | ret;
}
return ret;
}
#if defined(VERSION_SH)
-void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
+void seq_channel_layer_process_script(struct SequenceChannelLayer *layer)
+{
s32 cmd;
- if (layer->enabled == FALSE) {
+ if (layer->enabled == FALSE)
+ {
return;
}
- if (layer->delay > 1) {
+ if (layer->delay > 1)
+ {
layer->delay--;
- if (!layer->stopSomething && layer->delay <= layer->duration) {
+ if (!layer->stopSomething && layer->delay <= layer->duration)
+ {
seq_channel_layer_note_decay(layer);
layer->stopSomething = TRUE;
}
@@ -440,64 +508,70 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
seq_channel_layer_process_script_part1(layer);
cmd = seq_channel_layer_process_script_part2(layer);
- if (cmd != -1) {
+ if (cmd != -1)
+ {
cmd = seq_channel_layer_process_script_part3(layer, cmd);
- if (cmd != -1) {
+ if (cmd != -1)
+ {
cmd = seq_channel_layer_process_script_part4(layer, cmd);
}
- if (cmd != -1) {
+ if (cmd != -1)
+ {
seq_channel_layer_process_script_part5(layer, cmd);
}
- if (layer->stopSomething == TRUE) {
- if (layer->note != NULL || layer->continuousNotes) {
+ if (layer->stopSomething == TRUE)
+ {
+ if (layer->note != NULL || layer->continuousNotes)
+ {
seq_channel_layer_note_decay(layer);
}
}
}
}
#elif defined(VERSION_EU)
-void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
+void seq_channel_layer_process_script(struct SequenceChannelLayer *layer)
+{
struct SequencePlayer *seqPlayer;
struct SequenceChannel *seqChannel;
#ifdef VERSION_EU
UNUSED u32 pad0;
#endif
- struct M64ScriptState *state;
- struct Portamento *portamento;
- struct AudioBankSound *sound;
- struct Instrument *instrument;
- struct Drum *drum;
- s32 temp_a0_5;
+struct M64ScriptState *state;
+struct Portamento *portamento;
+struct AudioBankSound *sound;
+struct Instrument *instrument;
+struct Drum *drum;
+s32 temp_a0_5;
#ifdef VERSION_EU
- u16 sp3A;
- s32 sameSound;
+u16 sp3A;
+s32 sameSound;
#endif
UNUSED u32 pad1;
#ifndef VERSION_EU
- u8 sameSound;
+u8 sameSound;
#endif
- u8 cmd;
+u8 cmd;
UNUSED u8 cmdSemitone;
#ifndef VERSION_EU
- u16 sp3A;
+u16 sp3A;
#endif
- f32 tuning;
- s32 vel;
+f32 tuning;
+s32 vel;
UNUSED s32 usedSemitone;
- f32 freqScale;
+f32 freqScale;
#ifndef VERSION_EU
UNUSED f32 sp24;
#endif
- f32 temp_f12;
- f32 temp_f2;
+f32 temp_f12;
+f32 temp_f2;
- sameSound = TRUE;
- if (layer->enabled == FALSE) {
+sameSound= TRUE;
+ if (layer->enabled== FALSE) {
return;
}
- if (layer->delay > 1) {
+ if (layer->delay> 1) {
layer->delay--;
if (!layer->stopSomething && layer->delay <= layer->duration) {
seq_channel_layer_note_decay(layer);
@@ -511,17 +585,17 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
}
if (PORTAMENTO_MODE(layer->portamento) == PORTAMENTO_MODE_1 ||
- PORTAMENTO_MODE(layer->portamento) == PORTAMENTO_MODE_2) {
+PORTAMENTO_MODE(layer->portamento) == PORTAMENTO_MODE_2) {
layer->portamento.mode = 0;
}
- seqChannel = layer->seqChannel;
- seqPlayer = seqChannel->seqPlayer;
+seqChannel= layer->seqChannel;
+seqPlayer= seqChannel->seqPlayer;
#if defined(VERSION_EU) || defined(VERSION_SH)
- layer->notePropertiesNeedInit = TRUE;
+layer->notePropertiesNeedInit= TRUE;
#endif
- for (;;) {
+for (;;) {
state = &layer->scriptState;
cmd = m64_read_u8(state);
@@ -571,29 +645,29 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
break;
#if defined(VERSION_EU) || defined(VERSION_SH)
- case 0xf4:
- state->pc += (s8)m64_read_u8(state);
+case 0xf4:
+state->pc+= (s8)m64_read_u8(state);
break;
#endif
- case 0xc1: // layer_setshortnotevelocity
+case 0xc1: // layer_setshortnotevelocity
case 0xca: // layer_setpan
- temp_a0_5 = *(state->pc++);
- if (cmd == 0xc1) {
+temp_a0_5=*(state->pc++);
+ if (cmd== 0xc1) {
layer->velocitySquare = (f32)(temp_a0_5 * temp_a0_5);
} else {
#if defined(VERSION_EU) || defined(VERSION_SH)
- layer->pan = temp_a0_5;
+layer->pan= temp_a0_5;
#else
- layer->pan = (f32) temp_a0_5 / US_FLOAT(128.0);
+layer->pan= (f32) temp_a0_5/ US_FLOAT (128.0);
#endif
- }
+}
break;
case 0xc2: // layer_transpose; set transposition in semitones
case 0xc9: // layer_setshortnoteduration
- temp_a0_5 = *(state->pc++);
- if (cmd == 0xc9) {
+temp_a0_5=*(state->pc++);
+ if (cmd== 0xc9) {
layer->noteDuration = temp_a0_5;
} else {
layer->transposition = temp_a0_5;
@@ -602,27 +676,28 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
case 0xc4: // layer_somethingon
case 0xc5: // layer_somethingoff
- if (cmd == 0xc4) {
+ if (cmd== 0xc4) {
layer->continuousNotes = TRUE;
} else {
layer->continuousNotes = FALSE;
}
- seq_channel_layer_note_decay(layer);
+seq_channel_layer_note_decay (layer);
break;
case 0xc3: // layer_setshortnotedefaultplaypercentage
- sp3A = m64_read_compressed_u16(state);
- layer->shortNoteDefaultPlayPercentage = sp3A;
+sp3A= m64_read_compressed_u16(state);
+layer->shortNoteDefaultPlayPercentage= sp3A;
break;
case 0xc6: // layer_setinstr
- cmd = m64_read_u8(state);
+cmd= m64_read_u8(state);
#if defined(VERSION_JP) || defined(VERSION_US)
- if (cmd < 127) {
- cmd = get_instrument(seqChannel, cmd, &layer->instrument, &layer->adsr);
- }
+if (cmd<127)
+{
+ cmd = get_instrument(seqChannel, cmd, &layer->instrument, &layer->adsr);
+}
#else
- if (cmd >= 0x7f) {
+if (cmd>= 0x7f) {
if (cmd == 0x7f) {
layer->instOrWave = 0;
} else {
@@ -639,54 +714,54 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
break;
}
- if ((layer->instOrWave = get_instrument(seqChannel, cmd, &layer->instrument, &layer->adsr)) == 0) {
+ if ((layer->instOrWave= get_instrument(seqChannel, cmd, &layer->instrument, &layer->adsr)) == 0) {
eu_stubbed_printf_1("WARNING: NPRG: cannot change %d\n", cmd);
layer->instOrWave = 0xff;
}
#endif
- break;
+break;
case 0xc7: // layer_portamento
- layer->portamento.mode = m64_read_u8(state);
+layer->portamento.mode= m64_read_u8(state);
- // cmd is reused for the portamento's semitone
- cmd = m64_read_u8(state) + seqChannel->transposition +
- layer->transposition + seqPlayer->transposition;
+// cmd is reused for the portamento's semitone
+cmd= m64_read_u8(state)+ seqChannel->transposition+
+layer->transposition+ seqPlayer->transposition;
- if (cmd >= 0x80) {
+ if (cmd>= 0x80) {
cmd = 0;
}
- layer->portamentoTargetNote = cmd;
+layer->portamentoTargetNote= cmd;
- // If special, the next param is u8 instead of var
+// If special, the next param is u8 instead of var
if (PORTAMENTO_IS_SPECIAL(layer->portamento)) {
layer->portamentoTime = *((state)->pc++);
break;
}
- sp3A = m64_read_compressed_u16(state);
- layer->portamentoTime = sp3A;
+sp3A= m64_read_compressed_u16(state);
+layer->portamentoTime= sp3A;
break;
case 0xc8: // layer_disableportamento
- layer->portamento.mode = 0;
+layer->portamento.mode=0;
break;
#if defined(VERSION_EU) || defined(VERSION_SH)
- case 0xcb:
- sp3A = m64_read_s16(state);
- layer->adsr.envelope = (struct AdsrEnvelope *) (seqPlayer->seqData + sp3A);
- layer->adsr.releaseRate = m64_read_u8(state);
+case 0xcb:
+sp3A= m64_read_s16(state);
+layer->adsr.envelope= (struct AdsrEnvelope *) (seqPlayer->seqData+ sp3A);
+layer->adsr.releaseRate= m64_read_u8(state);
break;
case 0xcc:
- layer->ignoreDrumPan = TRUE;
+layer->ignoreDrumPan= TRUE;
break;
#endif
- default:
- switch (cmd & 0xf0) {
+default :
+ switch (cmd &0xf0) {
case 0xd0: // layer_setshortnotevelocityfromtable
sp3A = seqPlayer->shortNoteVelocityTable[cmd & 0xf];
layer->velocitySquare = (f32)(sp3A * sp3A);
@@ -701,7 +776,7 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
}
}
- if (cmd == 0xc0) { // layer_delay
+ if (cmd== 0xc0) { // layer_delay
layer->delay = m64_read_compressed_u16(state);
layer->stopSomething = TRUE;
} else {
@@ -733,11 +808,11 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
// the remaining bits are used for the semitone
cmd -= (cmd & 0xc0);
#if defined(VERSION_EU) || defined(VERSION_SH)
- layer->velocitySquare = (f32)(vel) * (f32)vel;
+layer->velocitySquare= (f32)(vel) *(f32)vel;
#else
- layer->velocitySquare = vel * vel;
+layer->velocitySquare= vel* vel;
#endif
- } else {
+} else {
switch (cmd & 0xc0) {
case 0x00: // play note, type 0 (play percentage)
sp3A = m64_read_compressed_u16(state);
@@ -757,35 +832,35 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
cmd -= cmd & 0xc0;
}
- layer->delay = sp3A;
+layer->delay= sp3A;
#if defined(VERSION_EU) || defined(VERSION_SH)
- layer->duration = layer->noteDuration * sp3A >> 8;
+layer->duration= layer->noteDuration *sp3A>> 8;
#else
- layer->duration = layer->noteDuration * sp3A / 256;
+layer->duration= layer->noteDuration *sp3A/ 256;
#endif
- if ((seqPlayer->muted && (seqChannel->muteBehavior & MUTE_BEHAVIOR_STOP_NOTES) != 0)
+if ((seqPlayer->muted &&(seqChannel->muteBehavior &MUTE_BEHAVIOR_STOP_NOTES) != 0)
|| seqChannel->stopSomething2
#if defined(VERSION_JP) || defined(VERSION_US)
- || !seqChannel->hasInstrument
+|| !seqChannel->hasInstrument
#endif
- ) {
+) {
layer->stopSomething = TRUE;
} else {
#if defined(VERSION_EU) || defined(VERSION_SH)
- s32 temp = layer->instOrWave;
- if (temp == 0xff) temp = seqChannel->instOrWave;
- if (temp == 0)
+s32 temp = layer->instOrWave;
+ if (temp== 0xff) temp= seqChannel->instOrWave;
+ if (temp== 0)
#else
- if (seqChannel->instOrWave == 0)
+if (seqChannel->instOrWave== 0)
#endif
- { // drum
+{ // drum
// cmd is reused for the drum semitone
cmd += seqChannel->transposition + layer->transposition;
#if defined(VERSION_EU)
- drum = get_drum(seqChannel->bankId, cmd);
+drum= get_drum(seqChannel->bankId, cmd);
#else
- if (cmd >= gCtlEntries[seqChannel->bankId].numDrums) {
+if (cmd>= gCtlEntries [seqChannel->bankId].numDrums) {
cmd = gCtlEntries[seqChannel->bankId].numDrums;
if (cmd == 0) {
// this goto looks a bit like a function return...
@@ -796,27 +871,27 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
cmd--;
}
- drum = gCtlEntries[seqChannel->bankId].drums[cmd];
+drum= gCtlEntries[seqChannel->bankId].drums [cmd];
#endif
- if (drum == NULL) {
+if (drum== NULL) {
layer->stopSomething = TRUE;
} else {
layer->adsr.envelope = drum->envelope;
layer->adsr.releaseRate = drum->releaseRate;
#if defined(VERSION_EU) || defined(VERSION_SH)
- if (!layer->ignoreDrumPan) {
+if (!layer->ignoreDrumPan) {
layer->pan = drum->pan;
}
#else
- layer->pan = FLOAT_CAST(drum->pan) / US_FLOAT(128.0);
+layer->pan= FLOAT_CAST(drum->pan) / US_FLOAT (128.0);
#endif
- layer->sound = &drum->sound;
- layer->freqScale = layer->sound->tuning;
+layer->sound=&drum->sound;
+layer->freqScale= layer->sound->tuning;
}
#if defined(VERSION_JP) || defined(VERSION_US) || defined(VERSION_SH)
- skip:;
+skip : ;
#endif
- } else { // instrument
+} else { // instrument
// cmd is reused for the instrument semitone
cmd += seqPlayer->transposition + seqChannel->transposition + layer->transposition;
@@ -824,19 +899,19 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
layer->stopSomething = TRUE;
} else {
#if defined(VERSION_EU) || defined(VERSION_SH)
- if (layer->instOrWave == 0xffu) {
+if (layer->instOrWave== 0xffu) {
instrument = seqChannel->instrument;
} else {
instrument = layer->instrument;
}
#else
- instrument = layer->instrument;
- if (instrument == NULL) {
+instrument= layer->instrument;
+ if (instrument== NULL) {
instrument = seqChannel->instrument;
}
#endif
- if (layer->portamento.mode != 0) {
+if (layer->portamento.mode!= 0) {
if (layer->portamentoTargetNote < cmd) {
vel = cmd;
} else {
@@ -845,120 +920,122 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
if (instrument != NULL) {
#if defined(VERSION_EU)
- sound = instrument_get_audio_bank_sound(instrument, vel);
+sound= instrument_get_audio_bank_sound(instrument, vel);
#else
- sound = (u8) vel < instrument->normalRangeLo ? &instrument->lowNotesSound
- : (u8) vel <= instrument->normalRangeHi ?
- &instrument->normalNotesSound : &instrument->highNotesSound;
+sound= (u8) velnormalRangeLo
+ ? &instrument->lowNotesSound
+ : (u8)vel <= instrument->normalRangeHi
+ ? &instrument->normalNotesSound
+ : &instrument->highNotesSound;
#endif
- sameSound = (sound == layer->sound);
- layer->sound = sound;
- tuning = sound->tuning;
+sameSound= (sound== layer->sound);
+layer->sound= sound;
+tuning= sound->tuning;
} else {
layer->sound = NULL;
tuning = 1.0f;
}
- temp_f2 = gNoteFrequencies[cmd] * tuning;
- temp_f12 = gNoteFrequencies[layer->portamentoTargetNote] * tuning;
+temp_f2= gNoteFrequencies[cmd]* tuning;
+temp_f12= gNoteFrequencies[layer->portamentoTargetNote]* tuning;
- portamento = &layer->portamento;
+portamento=&layer->portamento;
switch (PORTAMENTO_MODE(layer->portamento)) {
case PORTAMENTO_MODE_1:
case PORTAMENTO_MODE_3:
case PORTAMENTO_MODE_5:
#if defined(VERSION_JP) || defined(VERSION_US)
- sp24 = temp_f2;
+sp24= temp_f2;
#endif
- freqScale = temp_f12;
+freqScale= temp_f12;
break;
case PORTAMENTO_MODE_2:
case PORTAMENTO_MODE_4:
#if defined(VERSION_EU) || defined(VERSION_SH)
- default:
+default :
#endif
- freqScale = temp_f2;
+freqScale= temp_f2;
#if defined(VERSION_JP) || defined(VERSION_US)
- sp24 = temp_f12;
+sp24= temp_f12;
#endif
- break;
+break;
}
#if defined(VERSION_EU) || defined(VERSION_SH)
- portamento->extent = temp_f2 / freqScale - 1.0f;
+portamento->extent= temp_f2/ freqScale- 1.0f;
#else
- portamento->extent = sp24 / freqScale - US_FLOAT(1.0);
+portamento->extent= sp24/ freqScale- US_FLOAT (1.0);
#endif
- if (PORTAMENTO_IS_SPECIAL(layer->portamento)) {
+if (PORTAMENTO_IS_SPECIAL(layer->portamento)) {
portamento->speed = US_FLOAT(32512.0) * FLOAT_CAST(seqPlayer->tempo)
/ ((f32) layer->delay * (f32) gTempoInternalToExternal
* FLOAT_CAST(layer->portamentoTime));
} else {
portamento->speed = US_FLOAT(127.0) / FLOAT_CAST(layer->portamentoTime);
}
- portamento->cur = 0.0f;
- layer->freqScale = freqScale;
+portamento->cur=0.0f;
+layer->freqScale= freqScale;
if (PORTAMENTO_MODE(layer->portamento) == PORTAMENTO_MODE_5) {
layer->portamentoTargetNote = cmd;
}
- } else if (instrument != NULL) {
+ } else if (instrument!= NULL) {
#if defined(VERSION_EU)
- sound = instrument_get_audio_bank_sound(instrument, cmd);
+sound= instrument_get_audio_bank_sound(instrument, cmd);
#else
- sound = cmd < instrument->normalRangeLo ?
- &instrument->lowNotesSound : cmd <= instrument->normalRangeHi ?
+sound= cmd< instrument->normalRangeLo?
+ &instrument->lowNotesSound : cmd<= instrument->normalRangeHi?
&instrument->normalNotesSound : &instrument->highNotesSound;
#endif
- sameSound = (sound == layer->sound);
- layer->sound = sound;
- layer->freqScale = gNoteFrequencies[cmd] * sound->tuning;
+sameSound= (sound== layer->sound);
+layer->sound= sound;
+layer->freqScale= gNoteFrequencies[cmd]* sound->tuning;
} else {
layer->sound = NULL;
layer->freqScale = gNoteFrequencies[cmd];
}
}
}
- layer->delayUnused = layer->delay;
+layer->delayUnused= layer->delay;
}
}
- if (layer->stopSomething == TRUE) {
+ if (layer->stopSomething== TRUE) {
if (layer->note != NULL || layer->continuousNotes) {
seq_channel_layer_note_decay(layer);
}
return;
}
- cmd = FALSE;
+cmd= FALSE;
if (!layer->continuousNotes) {
cmd = TRUE;
- } else if (layer->note == NULL || layer->status == SOUND_LOAD_STATUS_NOT_LOADED) {
+ } else if (layer->note== NULL|| layer->status== SOUND_LOAD_STATUS_NOT_LOADED) {
cmd = TRUE;
- } else if (sameSound == FALSE) {
+ } else if (sameSound== FALSE) {
seq_channel_layer_note_decay(layer);
cmd = TRUE;
}
#if defined(VERSION_EU) || defined(VERSION_SH)
- else if (layer != layer->note->parentLayer) {
+else if (layer!= layer->note->parentLayer) {
cmd = TRUE;
}
#endif
- else if (layer->sound == NULL) {
+else if (layer->sound== NULL) {
init_synthetic_wave(layer->note, layer);
}
- if (cmd != FALSE) {
+ if (cmd!= FALSE) {
layer->note = alloc_note(layer);
}
- if (layer->note != NULL && layer->note->parentLayer == layer) {
+ if (layer->note!= NULL &&layer->note->parentLayer== layer) {
note_vibrato_init(layer->note);
}
#if defined(VERSION_EU) || defined(VERSION_SH)
- if (seqChannel) {
- }
+if (seqChannel){
+}
#endif
}
@@ -973,46 +1050,60 @@ u8 audioString107[] = "Error: Your assignchannel is stolen.\n";
#endif
#ifdef VERSION_SH
-void seq_channel_layer_process_script_part1(struct SequenceChannelLayer *layer) {
- if (!layer->continuousNotes) {
+void seq_channel_layer_process_script_part1(struct SequenceChannelLayer *layer)
+{
+ if (!layer->continuousNotes)
+ {
seq_channel_layer_note_decay(layer);
- } else if (layer->note != NULL && layer->note->wantedParentLayer == layer) {
+ }
+ else if (layer->note != NULL && layer->note->wantedParentLayer == layer)
+ {
seq_channel_layer_note_decay(layer);
}
if (PORTAMENTO_MODE(layer->portamento) == PORTAMENTO_MODE_1 ||
- PORTAMENTO_MODE(layer->portamento) == PORTAMENTO_MODE_2) {
+ PORTAMENTO_MODE(layer->portamento) == PORTAMENTO_MODE_2)
+ {
layer->portamento.mode = 0;
}
layer->notePropertiesNeedInit = TRUE;
}
-s32 seq_channel_layer_process_script_part5(struct SequenceChannelLayer *layer, s32 cmd) {
+s32 seq_channel_layer_process_script_part5(struct SequenceChannelLayer *layer, s32 cmd)
+{
if (!layer->stopSomething && layer->sound != NULL && layer->sound->sample->codec == CODEC_SKIP &&
- layer->sound->sample->medium != 0) {
+ layer->sound->sample->medium != 0)
+ {
layer->stopSomething = TRUE;
return -1;
}
if (layer->continuousNotes == 1 && layer->note != NULL && layer->status && cmd == 1 &&
- layer->note->parentLayer == layer) {
- if (layer->sound == NULL) {
+ layer->note->parentLayer == layer)
+ {
+ if (layer->sound == NULL)
+ {
init_synthetic_wave(layer->note, layer);
}
- } else {
- if (cmd == 0) {
+ }
+ else
+ {
+ if (cmd == 0)
+ {
seq_channel_layer_note_decay(layer);
}
layer->note = alloc_note(layer);
}
- if (layer->note != NULL && layer->note->parentLayer == layer) {
+ if (layer->note != NULL && layer->note->parentLayer == layer)
+ {
note_vibrato_init(layer->note);
}
return 0;
}
-s32 seq_channel_layer_process_script_part2(struct SequenceChannelLayer *layer) {
+s32 seq_channel_layer_process_script_part2(struct SequenceChannelLayer *layer)
+{
struct SequenceChannel *seqChannel = layer->seqChannel;
struct SequencePlayer *seqPlayer = seqChannel->seqPlayer;
struct M64ScriptState *state;
@@ -1020,17 +1111,21 @@ s32 seq_channel_layer_process_script_part2(struct SequenceChannelLayer *layer) {
u16 sp3A;
u8 cmd;
- for (;;) {
+ for (;;)
+ {
state = &layer->scriptState;
cmd = m64_read_u8(state);
- if (cmd <= 0xc0) {
+ if (cmd <= 0xc0)
+ {
return cmd;
}
- switch (cmd) {
+ switch (cmd)
+ {
case 0xff: // layer_end; function return or end of script
- if (state->depth == 0) {
+ if (state->depth == 0)
+ {
// N.B. this function call is *not* inlined even though it's
// within the same file, unlike in the rest of this function.
seq_channel_layer_disable(layer);
@@ -1040,7 +1135,8 @@ s32 seq_channel_layer_process_script_part2(struct SequenceChannelLayer *layer) {
break;
case 0xfc: // layer_call
- if (0 && state->depth >= 4) {
+ if (0 && state->depth >= 4)
+ {
eu_stubbed_printf_0("Macro Level Over Error!\n");
}
sp3A = m64_read_s16(state);
@@ -1049,7 +1145,8 @@ s32 seq_channel_layer_process_script_part2(struct SequenceChannelLayer *layer) {
break;
case 0xf8: // layer_loop; loop start, N iterations (or 256 if N = 0)
- if (0 && state->depth >= 4) {
+ if (0 && state->depth >= 4)
+ {
eu_stubbed_printf_0("Macro Level Over Error!\n");
}
state->remLoopIters[state->depth] = m64_read_u8(state);
@@ -1057,9 +1154,12 @@ s32 seq_channel_layer_process_script_part2(struct SequenceChannelLayer *layer) {
break;
case 0xf7: // layer_loopend
- if (--state->remLoopIters[state->depth - 1] != 0) {
+ if (--state->remLoopIters[state->depth - 1] != 0)
+ {
state->pc = state->stack[state->depth - 1];
- } else {
+ }
+ else
+ {
state->depth--;
}
break;
@@ -1076,9 +1176,12 @@ s32 seq_channel_layer_process_script_part2(struct SequenceChannelLayer *layer) {
case 0xc1: // layer_setshortnotevelocity
case 0xca: // layer_setpan
temp_a0_5 = *(state->pc++);
- if (cmd == 0xc1) {
- layer->velocitySquare = (f32) (temp_a0_5 * temp_a0_5) / (f32) (127 * 127);
- } else {
+ if (cmd == 0xc1)
+ {
+ layer->velocitySquare = (f32)(temp_a0_5 * temp_a0_5) / (f32)(127 * 127);
+ }
+ else
+ {
layer->pan = temp_a0_5;
}
break;
@@ -1086,18 +1189,24 @@ s32 seq_channel_layer_process_script_part2(struct SequenceChannelLayer *layer) {
case 0xc2: // layer_transpose; set transposition in semitones
case 0xc9: // layer_setshortnoteduration
temp_a0_5 = *(state->pc++);
- if (cmd == 0xc9) {
+ if (cmd == 0xc9)
+ {
layer->noteDuration = temp_a0_5;
- } else {
+ }
+ else
+ {
layer->transposition = temp_a0_5;
}
break;
case 0xc4: // layer_somethingon
case 0xc5: // layer_somethingoff
- if (cmd == 0xc4) {
+ if (cmd == 0xc4)
+ {
layer->continuousNotes = TRUE;
- } else {
+ }
+ else
+ {
layer->continuousNotes = FALSE;
}
seq_channel_layer_note_decay(layer);
@@ -1109,29 +1218,36 @@ s32 seq_channel_layer_process_script_part2(struct SequenceChannelLayer *layer) {
break;
case 0xc6: // layer_setinstr
- DEBUG_PRINT(" - cmd 0xc6, setinstr");
-
- cmd = m64_read_u8(state);
- DEBUG_PRINT(" - read %d from state", cmd);
+ DEBUG_PRINT(" - cmd 0xc6, setinstr");
- if (cmd >= 0x7f) {
- if (cmd == 0x7f) {
+ cmd = m64_read_u8(state);
+ DEBUG_PRINT(" - read %d from state", cmd);
+
+ if (cmd >= 0x7f)
+ {
+ if (cmd == 0x7f)
+ {
layer->instOrWave = 0;
- } else {
+ }
+ else
+ {
layer->instOrWave = cmd;
layer->instrument = NULL;
}
- if (1) {
+ if (1)
+ {
}
- if (cmd == 0xff) {
+ if (cmd == 0xff)
+ {
layer->adsr.releaseRate = 0;
}
break;
}
- if ((layer->instOrWave = get_instrument(seqChannel, cmd, &layer->instrument, &layer->adsr)) == 0) {
+ if ((layer->instOrWave = get_instrument(seqChannel, cmd, &layer->instrument, &layer->adsr)) == 0)
+ {
eu_stubbed_printf_1("WARNING: NPRG: cannot change %d\n", cmd);
layer->instOrWave = 0xff;
}
@@ -1142,16 +1258,18 @@ s32 seq_channel_layer_process_script_part2(struct SequenceChannelLayer *layer) {
// cmd is reused for the portamento's semitone
cmd = m64_read_u8(state) + seqChannel->transposition +
- layer->transposition + seqPlayer->transposition;
+ layer->transposition + seqPlayer->transposition;
- if (cmd >= 0x80) {
+ if (cmd >= 0x80)
+ {
cmd = 0;
}
layer->portamentoTargetNote = cmd;
// If special, the next param is u8 instead of var
- if (PORTAMENTO_IS_SPECIAL(layer->portamento)) {
+ if (PORTAMENTO_IS_SPECIAL(layer->portamento))
+ {
layer->portamentoTime = *((state)->pc++);
break;
}
@@ -1166,7 +1284,7 @@ s32 seq_channel_layer_process_script_part2(struct SequenceChannelLayer *layer) {
case 0xcb:
sp3A = m64_read_s16(state);
- layer->adsr.envelope = (struct AdsrEnvelope *) (seqPlayer->seqData + sp3A);
+ layer->adsr.envelope = (struct AdsrEnvelope *)(seqPlayer->seqData + sp3A);
layer->adsr.releaseRate = m64_read_u8(state);
break;
@@ -1181,13 +1299,14 @@ s32 seq_channel_layer_process_script_part2(struct SequenceChannelLayer *layer) {
case 0xce:
cmd = m64_read_u8(state) + 0x80;
layer->freqScaleMultiplier = unk_sh_data_1[cmd];
- // missing break :)
+ // missing break :)
default:
- switch (cmd & 0xf0) {
+ switch (cmd & 0xf0)
+ {
case 0xd0: // layer_setshortnotevelocityfromtable
sp3A = seqPlayer->shortNoteVelocityTable[cmd & 0xf];
- layer->velocitySquare = (f32) (sp3A * sp3A) / (f32) (127 * 127);
+ layer->velocitySquare = (f32)(sp3A * sp3A) / (f32)(127 * 127);
break;
case 0xe0: // layer_setshortnotedurationfromtable
layer->noteDuration = seqPlayer->shortNoteDurationTable[cmd & 0xf];
@@ -1201,7 +1320,8 @@ s32 seq_channel_layer_process_script_part2(struct SequenceChannelLayer *layer) {
return cmd;
}
-s32 seq_channel_layer_process_script_part4(struct SequenceChannelLayer *layer, s32 cmd1) {
+s32 seq_channel_layer_process_script_part4(struct SequenceChannelLayer *layer, s32 cmd1)
+{
s32 sameSound = TRUE;
struct SequenceChannel *seqChannel = layer->seqChannel;
struct Portamento *portamento;
@@ -1219,57 +1339,79 @@ s32 seq_channel_layer_process_script_part4(struct SequenceChannelLayer *layer, s
f32 temp_f2;
s32 temp = layer->instOrWave;
- if (temp == 0xff) {
- if (!seqChannel->hasInstrument) {
+ if (temp == 0xff)
+ {
+ if (!seqChannel->hasInstrument)
+ {
return -1;
}
temp = seqChannel->instOrWave;
}
- if (temp == 0) { // drum
+ if (temp == 0)
+ { // drum
// cmd is reused for the drum semitone
cmd += seqChannel->transposition + layer->transposition;
drum = get_drum(seqChannel->bankId, cmd);
- if (drum == NULL) {
+ if (drum == NULL)
+ {
layer->stopSomething = TRUE;
layer->delayUnused = layer->delay;
return -1;
- } else {
+ }
+ else
+ {
layer->adsr.envelope = drum->envelope;
layer->adsr.releaseRate = drum->releaseRate;
- if (!layer->ignoreDrumPan) {
+ if (!layer->ignoreDrumPan)
+ {
layer->pan = drum->pan;
}
layer->sound = &drum->sound;
layer->freqScale = layer->sound->tuning;
}
- } else { // instrument
+ }
+ else
+ { // instrument
// cmd is reused for the instrument semitone
cmd += seqPlayer->transposition + seqChannel->transposition + layer->transposition;
- if (cmd >= 0x80) {
+ if (cmd >= 0x80)
+ {
layer->stopSomething = TRUE;
return -1;
- } else {
- if (layer->instOrWave == 0xff) {
+ }
+ else
+ {
+ if (layer->instOrWave == 0xff)
+ {
instrument = seqChannel->instrument;
- } else {
+ }
+ else
+ {
instrument = layer->instrument;
}
- if (layer->portamento.mode != 0) {
- if (layer->portamentoTargetNote < cmd) {
+ if (layer->portamento.mode != 0)
+ {
+ if (layer->portamentoTargetNote < cmd)
+ {
vel = cmd;
- } else {
+ }
+ else
+ {
vel = layer->portamentoTargetNote;
}
- if (instrument != NULL) {
+ if (instrument != NULL)
+ {
sound = instrument_get_audio_bank_sound(instrument, vel);
sameSound = (sound == layer->sound);
layer->sound = sound;
tuning = sound->tuning;
- } else {
+ }
+ else
+ {
layer->sound = NULL;
tuning = 1.0f;
}
@@ -1278,7 +1420,8 @@ s32 seq_channel_layer_process_script_part4(struct SequenceChannelLayer *layer, s
temp_f12 = gNoteFrequencies[layer->portamentoTargetNote] * tuning;
portamento = &layer->portamento;
- switch (PORTAMENTO_MODE(layer->portamento)) {
+ switch (PORTAMENTO_MODE(layer->portamento))
+ {
case PORTAMENTO_MODE_1:
case PORTAMENTO_MODE_3:
case PORTAMENTO_MODE_5:
@@ -1300,24 +1443,32 @@ s32 seq_channel_layer_process_script_part4(struct SequenceChannelLayer *layer, s
portamento->extent = sp24 / freqScale - 1.0f;
- if (PORTAMENTO_IS_SPECIAL(layer->portamento)) {
+ if (PORTAMENTO_IS_SPECIAL(layer->portamento))
+ {
portamento->speed = US_FLOAT(32512.0) * FLOAT_CAST(seqPlayer->tempo)
- / ((f32) layer->delay * (f32) gTempoInternalToExternal
- * FLOAT_CAST(layer->portamentoTime));
- } else {
+ / ((f32)layer->delay * (f32)gTempoInternalToExternal
+ * FLOAT_CAST(layer->portamentoTime));
+ }
+ else
+ {
portamento->speed = US_FLOAT(127.0) / FLOAT_CAST(layer->portamentoTime);
}
portamento->cur = 0.0f;
layer->freqScale = freqScale;
- if (PORTAMENTO_MODE(layer->portamento) == PORTAMENTO_MODE_5) {
+ if (PORTAMENTO_MODE(layer->portamento) == PORTAMENTO_MODE_5)
+ {
layer->portamentoTargetNote = cmd;
}
- } else if (instrument != NULL) {
+ }
+ else if (instrument != NULL)
+ {
sound = instrument_get_audio_bank_sound(instrument, cmd);
sameSound = (sound == layer->sound);
layer->sound = sound;
layer->freqScale = gNoteFrequencies[cmd] * sound->tuning;
- } else {
+ }
+ else
+ {
layer->sound = NULL;
layer->freqScale = gNoteFrequencies[cmd];
}
@@ -1328,14 +1479,16 @@ s32 seq_channel_layer_process_script_part4(struct SequenceChannelLayer *layer, s
return sameSound;
}
-s32 seq_channel_layer_process_script_part3(struct SequenceChannelLayer *layer, s32 cmd) {
+s32 seq_channel_layer_process_script_part3(struct SequenceChannelLayer *layer, s32 cmd)
+{
struct M64ScriptState *state = &layer->scriptState;
u16 sp3A;
s32 vel;
struct SequenceChannel *seqChannel = layer->seqChannel;
struct SequencePlayer *seqPlayer = seqChannel->seqPlayer;
- if (cmd == 0xc0) { // layer_delay
+ if (cmd == 0xc0)
+ { // layer_delay
layer->delay = m64_read_compressed_u16(state);
layer->stopSomething = TRUE;
return -1;
@@ -1343,8 +1496,10 @@ s32 seq_channel_layer_process_script_part3(struct SequenceChannelLayer *layer, s
layer->stopSomething = FALSE;
- if (seqChannel->largeNotes == TRUE) {
- switch (cmd & 0xc0) {
+ if (seqChannel->largeNotes == TRUE)
+ {
+ switch (cmd & 0xc0)
+ {
case 0x00: // layer_note0 (play percentage, velocity, duration)
sp3A = m64_read_compressed_u16(state);
vel = *(state->pc++);
@@ -1365,14 +1520,18 @@ s32 seq_channel_layer_process_script_part3(struct SequenceChannelLayer *layer, s
layer->noteDuration = *(state->pc++);
break;
}
- if (vel >= 0x80 || vel < 0) {
+ if (vel >= 0x80 || vel < 0)
+ {
vel = 0x7f;
}
- layer->velocitySquare = ((f32) vel * (f32) vel) / (f32) (0x7f * 0x7f);
+ layer->velocitySquare = ((f32)vel * (f32)vel) / (f32)(0x7f * 0x7f);
// the remaining bits are used for the semitone
cmd -= (cmd & 0xc0);
- } else {
- switch (cmd & 0xc0) {
+ }
+ else
+ {
+ switch (cmd & 0xc0)
+ {
case 0x00: // play note, type 0 (play percentage)
sp3A = m64_read_compressed_u16(state);
layer->playPercentage = sp3A;
@@ -1404,12 +1563,13 @@ s32 seq_channel_layer_process_script_part3(struct SequenceChannelLayer *layer, s
}
#endif
-u8 get_instrument(struct SequenceChannel *seqChannel, u8 instId, struct Instrument **instOut, struct AdsrSettings *adsr) {
- DEBUG_PRINT("@ get_instrument()");
- DEBUG_PRINT("- instrument id: %d", instId);
-
+u8 get_instrument(struct SequenceChannel *seqChannel, u8 instId, struct Instrument **instOut, struct AdsrSettings *adsr)
+{
+ DEBUG_PRINT("@ get_instrument()");
+ DEBUG_PRINT("- instrument id: %d", instId);
+
struct Instrument *inst;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
inst = get_instrument_inner(seqChannel->bankId, instId);
if (inst == NULL)
{
@@ -1421,36 +1581,42 @@ u8 get_instrument(struct SequenceChannel *seqChannel, u8 instId, struct Instrume
*instOut = inst;
instId++;
return instId;
-#else
+ #else
UNUSED u32 pad;
- if (instId >= gCtlEntries[seqChannel->bankId].numInstruments) {
+ if (instId >= gCtlEntries[seqChannel->bankId].numInstruments)
+ {
instId = gCtlEntries[seqChannel->bankId].numInstruments;
- if (instId == 0) {
+ if (instId == 0)
+ {
return 0;
}
instId--;
}
inst = gCtlEntries[seqChannel->bankId].instruments[instId];
- if (inst == NULL) {
+ if (inst == NULL)
+ {
struct SequenceChannel seqChannelCpy = *seqChannel;
- while (instId != 0xff) {
+ while (instId != 0xff)
+ {
inst = gCtlEntries[seqChannelCpy.bankId].instruments[instId];
- if (inst != NULL) {
+ if (inst != NULL)
+ {
break;
}
instId--;
}
}
- if (((uintptr_t) gBankLoadedPool.persistent.pool.start <= (uintptr_t) inst
- && (uintptr_t) inst <= (uintptr_t)(gBankLoadedPool.persistent.pool.start
- + gBankLoadedPool.persistent.pool.size))
- || ((uintptr_t) gBankLoadedPool.temporary.pool.start <= (uintptr_t) inst
- && (uintptr_t) inst <= (uintptr_t)(gBankLoadedPool.temporary.pool.start
- + gBankLoadedPool.temporary.pool.size))) {
+ if (((uintptr_t)gBankLoadedPool.persistent.pool.start <= (uintptr_t)inst
+ && (uintptr_t)inst <= (uintptr_t)(gBankLoadedPool.persistent.pool.start
+ + gBankLoadedPool.persistent.pool.size))
+ || ((uintptr_t)gBankLoadedPool.temporary.pool.start <= (uintptr_t)inst
+ && (uintptr_t)inst <= (uintptr_t)(gBankLoadedPool.temporary.pool.start
+ + gBankLoadedPool.temporary.pool.size)))
+ {
adsr->envelope = inst->envelope;
adsr->releaseRate = inst->releaseRate;
*instOut = inst;
@@ -1461,29 +1627,35 @@ u8 get_instrument(struct SequenceChannel *seqChannel, u8 instId, struct Instrume
gAudioErrorFlags = instId + 0x20000;
*instOut = NULL;
return 0;
-#endif
+ #endif
}
-void set_instrument(struct SequenceChannel *seqChannel, u8 instId) {
- DEBUG_PRINT("@ set_instrument()");
- DEBUG_PRINT("- bank id: %d", seqChannel->bankId);
- DEBUG_PRINT("- instrument id: %d", instId);
+void set_instrument(struct SequenceChannel *seqChannel, u8 instId)
+{
+ DEBUG_PRINT("@ set_instrument()");
+ DEBUG_PRINT("- bank id: %d", seqChannel->bankId);
+ DEBUG_PRINT("- instrument id: %d", instId);
- if (instId >= 0x80) {
+ if (instId >= 0x80)
+ {
seqChannel->instOrWave = instId;
seqChannel->instrument = NULL;
- } else if (instId == 0x7f) {
+ }
+ else if (instId == 0x7f)
+ {
seqChannel->instOrWave = 0;
- seqChannel->instrument = (struct Instrument *) 1;
- } else {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ seqChannel->instrument = (struct Instrument *)1;
+ }
+ else
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
if ((seqChannel->instOrWave =
- get_instrument(seqChannel, instId, &seqChannel->instrument, &seqChannel->adsr)) == 0)
-#else
+ get_instrument(seqChannel, instId, &seqChannel->instrument, &seqChannel->adsr)) == 0)
+ #else
seqChannel->instOrWave =
- get_instrument(seqChannel, instId, &seqChannel->instrument, &seqChannel->adsr);
+ get_instrument(seqChannel, instId, &seqChannel->instrument, &seqChannel->adsr);
if (seqChannel->instOrWave == 0)
-#endif
+ #endif
{
seqChannel->hasInstrument = FALSE;
return;
@@ -1492,12 +1664,14 @@ void set_instrument(struct SequenceChannel *seqChannel, u8 instId) {
seqChannel->hasInstrument = TRUE;
}
-void sequence_channel_set_volume(struct SequenceChannel *seqChannel, u8 volume) {
+void sequence_channel_set_volume(struct SequenceChannel *seqChannel, u8 volume)
+{
seqChannel->volume = FLOAT_CAST(volume) / US_FLOAT(127.0);
}
-void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
- DEBUG_PRINT("sequence_channel_process_script()");
+void sequence_channel_process_script(struct SequenceChannel *seqChannel)
+{
+ DEBUG_PRINT("sequence_channel_process_script()");
struct M64ScriptState *state;
struct SequencePlayer *seqPlayer;
@@ -1510,13 +1684,17 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
s32 i;
u8 *seqData;
- if (!seqChannel->enabled) {
+ if (!seqChannel->enabled)
+ {
return;
}
- if (seqChannel->stopScript) {
- for (i = 0; i < LAYERS_MAX; i++) {
- if (seqChannel->layers[i] != NULL) {
+ if (seqChannel->stopScript)
+ {
+ for (i = 0; i < LAYERS_MAX; i++)
+ {
+ if (seqChannel->layers[i] != NULL)
+ {
seq_channel_layer_process_script(seqChannel->layers[i]);
}
}
@@ -1524,24 +1702,29 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
}
seqPlayer = seqChannel->seqPlayer;
- if (seqPlayer->muted && (seqChannel->muteBehavior & MUTE_BEHAVIOR_STOP_SCRIPT) != 0) {
+ if (seqPlayer->muted && (seqChannel->muteBehavior & MUTE_BEHAVIOR_STOP_SCRIPT) != 0)
+ {
return;
}
- if (seqChannel->delay != 0) {
+ if (seqChannel->delay != 0)
+ {
seqChannel->delay--;
}
state = &seqChannel->scriptState;
- if (seqChannel->delay == 0) {
- for (;;) {
+ if (seqChannel->delay == 0)
+ {
+ for (;;)
+ {
cmd = m64_read_u8(state);
- DEBUG_PRINT("- handling command: %x", cmd);
-
-#if !defined(VERSION_EU) && !defined(VERSION_SH)
+ DEBUG_PRINT("- handling command: %x", cmd);
+
+ #if !defined(VERSION_EU) && !defined(VERSION_SH)
if (cmd == 0xff) // chan_end
{
- if (state->depth == 0) {
+ if (state->depth == 0)
+ {
sequence_channel_disable(seqChannel);
break;
}
@@ -1561,27 +1744,31 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
seqChannel->stopScript = TRUE;
break;
}
-#endif
+ #endif
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
if (cmd >= 0xb0)
-#else
+ #else
if (cmd > 0xc0)
-#endif
+ #endif
{
- switch (cmd) {
+ switch (cmd)
+ {
case 0xff: // chan_end
-#if defined(VERSION_EU) || defined(VERSION_SH)
- if (state->depth == 0) {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ if (state->depth == 0)
+ {
sequence_channel_disable(seqChannel);
goto out;
- } else {
+ }
+ else
+ {
state->pc = state->stack[--state->depth];
}
-#endif
+ #endif
break;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
case 0xfe: // chan_delay1
goto out;
@@ -1592,37 +1779,42 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
case 0xea:
seqChannel->stopScript = TRUE;
goto out;
-#endif
+ #endif
case 0xfc: // chan_call
- if (0 && state->depth >= 4) {
+ if (0 && state->depth >= 4)
+ {
eu_stubbed_printf_0("Audio:Track :Call Macro Level Over Error!\n");
}
sp5A = m64_read_s16(state);
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
state->stack[state->depth++] = state->pc;
-#else
+ #else
state->depth++, state->stack[state->depth - 1] = state->pc;
-#endif
+ #endif
state->pc = seqPlayer->seqData + sp5A;
break;
case 0xf8: // chan_loop; loop start, N iterations (or 256 if N = 0)
- if (0 && state->depth >= 4) {
+ if (0 && state->depth >= 4)
+ {
eu_stubbed_printf_0("Audio:Track :Loops Macro Level Over Error!\n");
}
state->remLoopIters[state->depth] = m64_read_u8(state);
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
state->stack[state->depth++] = state->pc;
-#else
+ #else
state->depth++, state->stack[state->depth - 1] = state->pc;
-#endif
+ #endif
break;
case 0xf7: // chan_loopend
state->remLoopIters[state->depth - 1]--;
- if (state->remLoopIters[state->depth - 1] != 0) {
+ if (state->remLoopIters[state->depth - 1] != 0)
+ {
state->pc = state->stack[state->depth - 1];
- } else {
+ }
+ else
+ {
state->depth--;
}
break;
@@ -1645,7 +1837,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
state->pc = seqPlayer->seqData + sp5A;
break;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
case 0xf4: // chan_jump_rel
case 0xf3: // chan_beqz_rel
case 0xf2: // chan_bltz_rel
@@ -1656,73 +1848,74 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
break;
state->pc += temp;
break;
-#endif
+ #endif
-#if defined(VERSION_EU) || defined(VERSION_SH)
- case 0xf1: // chan_reservenotes
-#else
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ case 0xf1: // chan_reservenotes
+ #else
case 0xf2: // chan_reservenotes
-#endif
+ #endif
note_pool_clear(&seqChannel->notePool);
note_pool_fill(&seqChannel->notePool, m64_read_u8(state));
break;
-#if defined(VERSION_EU) || defined(VERSION_SH)
- case 0xf0: // chan_unreservenotes
-#else
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ case 0xf0: // chan_unreservenotes
+ #else
case 0xf1: // chan_unreservenotes
-#endif
+ #endif
note_pool_clear(&seqChannel->notePool);
break;
case 0xc2: // chan_setdyntable
sp5A = m64_read_s16(state);
- seqChannel->dynTable = (void *) (seqPlayer->seqData + sp5A);
+ seqChannel->dynTable = (void *)(seqPlayer->seqData + sp5A);
break;
case 0xc5: // chan_dynsetdyntable
- if (value != -1) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ if (value != -1)
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
seqData = (*seqChannel->dynTable)[value];
sp38 = (u16)((seqData[0] << 8) + seqData[1]);
- seqChannel->dynTable = (void *) (seqPlayer->seqData + sp38);
-#else
- sp5A = (u16)((((*seqChannel->dynTable)[value])[0] << 8) + (((*seqChannel->dynTable)[value])[1]));
- seqChannel->dynTable = (void *) (seqPlayer->seqData + sp5A);
-#endif
+ seqChannel->dynTable = (void *)(seqPlayer->seqData + sp38);
+ #else
+ sp5A = (u16)(((*seqChannel->dynTable)[value][0] << 8) + (*seqChannel->dynTable)[value][1]);
+ seqChannel->dynTable = (void *)(seqPlayer->seqData + sp5A);
+ #endif
}
break;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
case 0xeb: // chan_setbankandinstr
cmd = m64_read_u8(state);
// Switch to the cmd's (0-indexed) bank in this sequence's
// bank set. Note that in the binary format (not in the JSON!)
// the banks are listed backwards, so we counts from the back.
// (gAlBankSets[offset] is number of banks)
- sp38 = ((u16 *) gAlBankSets)[seqPlayer->seqId];
+ sp38 = ((u16 *)gAlBankSets)[seqPlayer->seqId];
loBits = *(sp38 + gAlBankSets);
cmd = gAlBankSets[(s32)sp38 + loBits - cmd];
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
if (get_bank_or_seq(1, 2, cmd) != NULL)
-#else
+ #else
if (get_bank_or_seq(&gBankLoadedPool, 2, cmd) != NULL)
-#endif
+ #endif
{
seqChannel->bankId = cmd;
} else {
eu_stubbed_printf_1("SUB:ERR:BANK %d NOT CACHED.\n", cmd);
}
// fallthrough
-#endif
+ #endif
case 0xc1: // chan_setinstr ("set program"?)
- DEBUG_PRINT(" - cmd 0xc1, setinstr");
-
- u8 instrId = m64_read_u8(state);
- DEBUG_PRINT(" - read %d from state", instrId);
-
+ DEBUG_PRINT(" - cmd 0xc1, setinstr");
+
+ u8 instrId = m64_read_u8(state);
+ DEBUG_PRINT(" - read %d from state", instrId);
+
set_instrument(seqChannel, instrId);
break;
@@ -1736,63 +1929,63 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
case 0xdf: // chan_setvol
sequence_channel_set_volume(seqChannel, m64_read_u8(state));
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
seqChannel->changes.as_bitfields.volume = TRUE;
-#endif
+ #endif
break;
case 0xe0: // chan_setvolscale
seqChannel->volumeScale = FLOAT_CAST(m64_read_u8(state)) / US_FLOAT(128.0);
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
seqChannel->changes.as_bitfields.volume = TRUE;
-#endif
+ #endif
break;
case 0xde: // chan_freqscale; pitch bend using raw frequency multiplier N/2^15 (N is u16)
sp5A = m64_read_s16(state);
seqChannel->freqScale = FLOAT_CAST(sp5A) / US_FLOAT(32768.0);
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
seqChannel->changes.as_bitfields.freqScale = TRUE;
-#endif
+ #endif
break;
case 0xd3: // chan_pitchbend; pitch bend by <= 1 octave in either direction (-127..127)
// (m64_read_u8(state) is really s8 here)
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
cmd = m64_read_u8(state) + 128;
-#else
+ #else
cmd = m64_read_u8(state) + 127;
-#endif
+ #endif
seqChannel->freqScale = gPitchBendFrequencyScale[cmd];
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
seqChannel->changes.as_bitfields.freqScale = TRUE;
-#endif
+ #endif
break;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
case 0xee:
cmd = m64_read_u8(state) + 0x80;
seqChannel->freqScale = unk_sh_data_1[cmd];
seqChannel->changes.as_bitfields.freqScale = TRUE;
break;
-#endif
+ #endif
case 0xdd: // chan_setpan
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
seqChannel->newPan = m64_read_u8(state);
seqChannel->changes.as_bitfields.pan = TRUE;
-#else
+ #else
seqChannel->pan = FLOAT_CAST(m64_read_u8(state)) / US_FLOAT(128.0);
-#endif
+ #endif
break;
case 0xdc: // chan_setpanmix; set proportion of pan to come from channel (0..128)
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
seqChannel->panChannelWeight = m64_read_u8(state);
seqChannel->changes.as_bitfields.pan = TRUE;
-#else
+ #else
seqChannel->panChannelWeight = FLOAT_CAST(m64_read_u8(state)) / US_FLOAT(128.0);
-#endif
+ #endif
break;
case 0xdb: // chan_transpose; set transposition in semitones
@@ -1802,7 +1995,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
case 0xda: // chan_setenvelope
sp5A = m64_read_s16(state);
- seqChannel->adsr.envelope = (struct AdsrEnvelope *) (seqPlayer->seqData + sp5A);
+ seqChannel->adsr.envelope = (struct AdsrEnvelope *)(seqPlayer->seqData + sp5A);
break;
case 0xd9: // chan_setdecayrelease
@@ -1817,7 +2010,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
case 0xd7: // chan_setvibratorate
seqChannel->vibratoRateStart = seqChannel->vibratoRateTarget =
- m64_read_u8(state) * 32;
+ m64_read_u8(state) * 32;
seqChannel->vibratoRateChangeDelay = 0;
break;
@@ -1837,79 +2030,87 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
seqChannel->vibratoDelay = m64_read_u8(state) * 16;
break;
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #if defined(VERSION_JP) || defined(VERSION_US)
case 0xd6: // chan_setupdatesperframe_unimplemented
cmd = m64_read_u8(state);
- if (cmd == 0) {
+ if (cmd == 0)
+ {
cmd = gAudioUpdatesPerFrame;
}
seqChannel->updatesPerFrameUnused = cmd;
break;
-#endif
+ #endif
case 0xd4: // chan_setreverb
seqChannel->reverbVol = m64_read_u8(state);
break;
case 0xc6: // chan_setbank; switch bank within set
- DEBUG_PRINT(" - case 0xc6 - switch bank");
-
- DEBUG_PRINT(" - seq id %d", seqPlayer->seqId);
+ DEBUG_PRINT(" - case 0xc6 - switch bank");
+
+ DEBUG_PRINT(" - seq id %d", seqPlayer->seqId);
cmd = m64_read_u8(state);
- DEBUG_PRINT(" - backwards bank id %d", cmd);
+ DEBUG_PRINT(" - backwards bank id %d", cmd);
// Switch to the temp's (0-indexed) bank in this sequence's
// bank set. Note that in the binary format (not in the JSON!)
// the banks are listed backwards, so we counts from the back.
// (gAlBankSets[offset] is number of banks)
- sp5A = ((u16 *) gAlBankSets)[seqPlayer->seqId];
+ sp5A = ((u16 *)gAlBankSets)[seqPlayer->seqId];
loBits = *(sp5A + gAlBankSets);
cmd = gAlBankSets[sp5A + loBits - cmd];
if (get_bank_or_seq(&gBankLoadedPool, 2, cmd) != NULL)
{
seqChannel->bankId = cmd;
- } else {
+ }
+ else
+ {
eu_stubbed_printf_1("SUB:ERR:BANK %d NOT CACHED.\n", cmd);
}
break;
case 0xc7: // chan_writeseq; write to sequence data (!)
- {
-#if !defined(VERSION_EU) && !defined(VERSION_SH)
- u8 *seqData;
-#endif
- cmd = m64_read_u8(state);
- sp5A = m64_read_s16(state);
- seqData = seqPlayer->seqData + sp5A;
- *seqData = (u8)value + cmd;
- }
- break;
+ {
+ #if !defined(VERSION_EU) && !defined(VERSION_SH)
+ u8 *seqData;
+ #endif
+ cmd = m64_read_u8(state);
+ sp5A = m64_read_s16(state);
+ seqData = seqPlayer->seqData + sp5A;
+ *seqData = (u8)value + cmd;
+ }
+ break;
case 0xc8: // chan_subtract
case 0xc9: // chan_bitand
case 0xcc: // chan_setval
temp = m64_read_u8(state);
- if (cmd == 0xc8) {
+ if (cmd == 0xc8)
+ {
value -= temp;
- } else if (cmd == 0xcc) {
+ }
+ else if (cmd == 0xcc)
+ {
value = temp;
- } else {
+ }
+ else
+ {
value &= temp;
}
break;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
case 0xcd:
sequence_channel_disable(seqPlayer->channels[m64_read_u8(state)]);
break;
-#endif
+ #endif
case 0xca: // chan_setmutebhv
seqChannel->muteBehavior = m64_read_u8(state);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
seqChannel->changes.as_bitfields.volume = TRUE;
-#endif
+ #endif
break;
case 0xcb: // chan_readseq
@@ -1917,7 +2118,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
value = seqPlayer->seqData[sp38];
break;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
case 0xce:
seqChannel->unkC8 = m64_read_s16(state);
break;
@@ -1928,7 +2129,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
seqData[0] = (seqChannel->unkC8 >> 8) & 0xffff;
seqData[1] = (seqChannel->unkC8) & 0xffff;
break;
-#endif
+ #endif
case 0xd0: // chan_stereoheadseteffects
seqChannel->stereoHeadsetEffects = m64_read_u8(state);
@@ -1939,42 +2140,45 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
break;
case 0xd2: // chan_setsustain
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
seqChannel->adsr.sustain = m64_read_u8(state);
-#else
+ #else
seqChannel->adsr.sustain = m64_read_u8(state) << 8;
-#endif
+ #endif
break;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
case 0xe5:
seqChannel->reverbIndex = m64_read_u8(state);
break;
-#endif
+ #endif
case 0xe4: // chan_dyncall
- if (value != -1) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
- if (state->depth >= 4) {
+ if (value != -1)
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ if (state->depth >= 4)
+ {
eu_stubbed_printf_0("Audio:Track: CTBLCALL Macro Level Over Error!\n");
}
-#endif
+ #endif
seqData = (*seqChannel->dynTable)[value];
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
state->stack[state->depth++] = state->pc;
sp38 = (u16)((seqData[0] << 8) + seqData[1]);
state->pc = seqPlayer->seqData + sp38;
- if (0 && sp38 >= gSeqFileHeader->seqArray[seqPlayer->seqId].len) {
+ if (0 && sp38 >= gSeqFileHeader->seqArray[seqPlayer->seqId].len)
+ {
eu_stubbed_printf_3("Err :Sub %x ,address %x:Undefined SubTrack Function %x", seqChannel, state->pc, sp38);
}
-#else
+ #else
state->depth++, state->stack[state->depth - 1] = state->pc;
- sp5A = ((seqData[0] << 8) + seqData[1]);
+ sp5A = (seqData[0] << 8) + seqData[1];
state->pc = seqPlayer->seqData + sp5A;
-#endif
+ #endif
}
break;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
case 0xe6:
seqChannel->bookOffset = m64_read_u8(state);
break;
@@ -1985,7 +2189,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
seqChannel->muteBehavior = *seqData++;
seqChannel->noteAllocPolicy = *seqData++;
seqChannel->notePriority = *seqData++;
- seqChannel->transposition = (s8) *seqData++;
+ seqChannel->transposition = (s8) * seqData++;
seqChannel->newPan = *seqData++;
seqChannel->panChannelWeight = *seqData++;
seqChannel->reverbVol = *seqData++;
@@ -1997,7 +2201,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
seqChannel->muteBehavior = m64_read_u8(state);
seqChannel->noteAllocPolicy = m64_read_u8(state);
seqChannel->notePriority = m64_read_u8(state);
- seqChannel->transposition = (s8) m64_read_u8(state);
+ seqChannel->transposition = (s8)m64_read_u8(state);
seqChannel->newPan = m64_read_u8(state);
seqChannel->panChannelWeight = m64_read_u8(state);
seqChannel->reverbVol = m64_read_u8(state);
@@ -2015,22 +2219,24 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
seqChannel->freqScale = 1.0f;
break;
- case 0xe9: // chan_setnotepriority
-#ifdef VERSION_SH
+ case 0xe9: // chan_setnotepriority
+ #ifdef VERSION_SH
cmd = m64_read_u8(state);
- if ((cmd & 0xf) != 0) {
+ if ((cmd & 0xf) != 0)
+ {
seqChannel->notePriority = cmd & 0xf;
}
cmd = cmd >> 4;
- if (cmd != 0) {
+ if (cmd != 0)
+ {
seqChannel->unkSH06 = cmd;
}
-#else
+ #else
seqChannel->notePriority = m64_read_u8(state);
-#endif
+ #endif
break;
-#endif
-#ifdef VERSION_SH
+ #endif
+ #ifdef VERSION_SH
case 0xed:
seqChannel->synthesisVolume = m64_read_u8(state);
break;
@@ -2043,7 +2249,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
case 0xb0:
sp5A = m64_read_s16(state);
seqData = seqPlayer->seqData + sp5A;
- seqChannel->filter = (s16 *) (seqData);
+ seqChannel->filter = (s16 *)(seqData);
break;
case 0xb1:
@@ -2051,11 +2257,15 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
break;
case 0xb3:
- if (seqChannel->filter != NULL) {
+ if (seqChannel->filter != NULL)
+ {
cmd = m64_read_u8(state);
- if (cmd == 0) {
+ if (cmd == 0)
+ {
seqChannel->filter = NULL;
- } else {
+ }
+ else
+ {
loBits = (cmd >> 4) & 0xf;
cmd &= 0xf;
fill_filter(seqChannel->filter, loBits, cmd);
@@ -2067,39 +2277,49 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
i = (value * 2);
sp5A = m64_read_s16(state);
sp38 = sp5A + i;
- seqChannel->unkC8 = *(u16 *) (seqPlayer->seqData + sp38);
+ seqChannel->unkC8 = *(u16 *)(seqPlayer->seqData + sp38);
break;
case 0xb4:
- seqChannel->dynTable = (void *) (seqPlayer->seqData + seqChannel->unkC8);
+ seqChannel->dynTable = (void *)(seqPlayer->seqData + seqChannel->unkC8);
break;
case 0xb5:
- seqChannel->unkC8 = *(u16 *) (*seqChannel->dynTable)[value];
+ seqChannel->unkC8 = *(u16 *)(*seqChannel->dynTable)[value];
break;
case 0xb6:
value = (*seqChannel->dynTable)[0][value];
break;
-#endif
+ #endif
}
- } else {
-#ifdef VERSION_SH
- if (cmd >= 0x80) {
+ }
+ else
+ {
+ #ifdef VERSION_SH
+ if (cmd >= 0x80)
+ {
loBits = cmd & 7;
- switch (cmd & 0xf8) {
+ switch (cmd & 0xf8)
+ {
case 0x80:
- if (seqChannel->layers[loBits] != NULL) {
+ if (seqChannel->layers[loBits] != NULL)
+ {
value = seqChannel->layers[loBits]->finished;
- } else {
+ }
+ else
+ {
value = -1;
}
break;
case 0x88:
sp5A = m64_read_s16(state);
- if (seq_channel_set_layer(seqChannel, loBits) == 0) {
- if (1) {}
+ if (seq_channel_set_layer(seqChannel, loBits) == 0)
+ {
+ if (1)
+ {
+ }
seqChannel->layers[loBits]->scriptState.pc = seqPlayer->seqData + sp5A;
}
break;
@@ -2109,55 +2329,61 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
break;
case 0x98:
- if (value != -1 && seq_channel_set_layer(seqChannel, loBits) != -1) {
+ if (value != -1 && seq_channel_set_layer(seqChannel, loBits) != -1)
+ {
seqData = (*seqChannel->dynTable)[value];
sp5A = ((seqData[0] << 8) + seqData[1]);
seqChannel->layers[loBits]->scriptState.pc = seqPlayer->seqData + sp5A;
}
break;
}
- } else {
-#endif
+ }
+ else {
+ #endif
loBits = cmd & 0xf;
- switch (cmd & 0xf0) {
-#ifdef VERSION_SH
+ switch (cmd & 0xf0)
+ {
+ #ifdef VERSION_SH
case 0x00:
seqChannel->delay = loBits;
goto out;
case 0x10:
seqChannel->soundScriptIO[loBits] = -1;
- if (func_sh_802f47c8(seqChannel->bankId, (u8)value, &seqChannel->soundScriptIO[loBits]) == -1) {
+ if (func_sh_802f47c8(seqChannel->bankId, (u8)value, &seqChannel->soundScriptIO[loBits]) == -1)
+ {
}
break;
-#else
+ #else
case 0x00: // chan_testlayerfinished
- if (seqChannel->layers[loBits] != NULL) {
+ if (seqChannel->layers[loBits] != NULL)
+ {
value = seqChannel->layers[loBits]->finished;
}
-#ifdef VERSION_EU
+ #ifdef VERSION_EU
else {
value = -1;
}
-#endif
+ #endif
break;
-#endif
+ #endif
// sh: 0x70
case 0x70: // chan_iowriteval; write data back to audio lib
seqChannel->soundScriptIO[loBits] = value;
break;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
case 0x60:
-#else
+ #else
case 0x80: // chan_ioreadval; read data from audio lib
-#endif
- DEBUG_PRINT("- cmd 0x80, read data from audio lib");
- DEBUG_PRINT(" - reading index: %d", loBits);
+ #endif
+ DEBUG_PRINT("- cmd 0x80, read data from audio lib");
+ DEBUG_PRINT(" - reading index: %d", loBits);
value = seqChannel->soundScriptIO[loBits];
- if (loBits < 4) {
+ if (loBits < 4)
+ {
seqChannel->soundScriptIO[loBits] = -1;
}
break;
@@ -2167,20 +2393,23 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
value -= seqChannel->soundScriptIO[loBits];
break;
-#ifndef VERSION_SH
-#ifdef VERSION_EU
- // sh: 0x00
+ #ifndef VERSION_SH
+ #ifdef VERSION_EU
+ // sh: 0x00
case 0x60: // chan_delayshort
seqChannel->delay = loBits;
goto out;
-#endif
+ #endif
case 0x90: // chan_setlayer
sp5A = m64_read_s16(state);
- if (seq_channel_set_layer(seqChannel, loBits) == 0) {
-#ifdef VERSION_EU
- if (1) {}
-#endif
+ if (seq_channel_set_layer(seqChannel, loBits) == 0)
+ {
+ #ifdef VERSION_EU
+ if (1)
+ {
+ }
+ #endif
seqChannel->layers[loBits]->scriptState.pc = seqPlayer->seqData + sp5A;
}
break;
@@ -2190,34 +2419,35 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
break;
case 0xb0: // chan_dynsetlayer
- if (value != -1 && seq_channel_set_layer(seqChannel, loBits) != -1) {
+ if (value != -1 && seq_channel_set_layer(seqChannel, loBits) != -1)
+ {
seqData = (*seqChannel->dynTable)[value];
- sp5A = ((seqData[0] << 8) + seqData[1]);
+ sp5A = (seqData[0] << 8) + seqData[1];
seqChannel->layers[loBits]->scriptState.pc = seqPlayer->seqData + sp5A;
}
break;
-#ifndef VERSION_EU
+ #ifndef VERSION_EU
case 0x60: // chan_setnotepriority (arg must be >= 2)
seqChannel->notePriority = loBits;
break;
-#endif
-#endif
+ #endif
+ #endif
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
case 0x20:
-#else
+ #else
case 0x10: // chan_startchannel
-#endif
+ #endif
sp5A = m64_read_s16(state);
sequence_channel_enable(seqPlayer, loBits, seqPlayer->seqData + sp5A);
break;
-#ifndef VERSION_SH
+ #ifndef VERSION_SH
case 0x20: // chan_disablechannel
sequence_channel_disable(seqPlayer->channels[loBits]);
break;
-#endif
+ #endif
case 0x30: // chan_iowriteval2; write data back to audio lib for another channel
cmd = m64_read_u8(state);
@@ -2229,30 +2459,33 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
value = seqPlayer->channels[loBits]->soundScriptIO[cmd];
break;
}
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
}
-#endif
+ #endif
}
}
}
-#if defined(VERSION_EU) || defined(VERSION_SH)
- out:
-#endif
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+out:
+ #endif
- for (i = 0; i < LAYERS_MAX; i++) {
- if (seqChannel->layers[i] != 0) {
+ for (i = 0; i < LAYERS_MAX; i++)
+ {
+ if (seqChannel->layers[i] != 0)
+ {
seq_channel_layer_process_script(seqChannel->layers[i]);
}
}
}
-void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
- DEBUG_PRINT("sequence_player_process_sequence()");
+void sequence_player_process_sequence(struct SequencePlayer *seqPlayer)
+{
+ DEBUG_PRINT("sequence_player_process_sequence()");
- u8 cmd;
-#ifdef VERSION_SH
+ u8 cmd;
+ #ifdef VERSION_SH
UNUSED u32 pad;
-#endif
+ #endif
u8 loBits;
u8 temp;
s32 value;
@@ -2260,40 +2493,48 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
u16 u16v;
u8 *seqData;
struct M64ScriptState *state;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
s32 temp32;
-#endif
+ #endif
- if (seqPlayer->enabled == FALSE) {
+ if (seqPlayer->enabled == FALSE)
+ {
return;
}
-#ifndef VERSION_SH
- if (seqPlayer->bankDmaInProgress == TRUE) {
-#ifdef VERSION_EU
- if (osRecvMesg(&seqPlayer->bankDmaMesgQueue, NULL, 0) == -1) {
+ #ifndef VERSION_SH
+ if (seqPlayer->bankDmaInProgress == TRUE)
+ {
+ #ifdef VERSION_EU
+ if (osRecvMesg(&seqPlayer->bankDmaMesgQueue, NULL, 0) == -1)
+ {
return;
}
- if (seqPlayer->bankDmaRemaining == 0) {
+ if (seqPlayer->bankDmaRemaining == 0)
+ {
seqPlayer->bankDmaInProgress = FALSE;
patch_audio_bank(
- (struct AudioBank *) (gCtlEntries[seqPlayer->loadingBankId].instruments - 1),
+ (struct AudioBank *)(gCtlEntries[seqPlayer->loadingBankId].instruments - 1),
gAlTbl->seqArray[seqPlayer->loadingBankId].offset,
gCtlEntries[seqPlayer->loadingBankId].numInstruments,
gCtlEntries[seqPlayer->loadingBankId].numDrums);
gCtlEntries[seqPlayer->loadingBankId].drums =
- ((struct AudioBank *) (gCtlEntries[seqPlayer->loadingBankId].instruments - 1))->drums;
+ ((struct AudioBank *)(gCtlEntries[seqPlayer->loadingBankId].instruments - 1))->drums;
gBankLoadStatus[seqPlayer->loadingBankId] = SOUND_LOAD_STATUS_COMPLETE;
- } else {
+ }
+ else
+ {
audio_dma_partial_copy_async(&seqPlayer->bankDmaCurrDevAddr, &seqPlayer->bankDmaCurrMemAddr,
&seqPlayer->bankDmaRemaining, &seqPlayer->bankDmaMesgQueue,
&seqPlayer->bankDmaIoMesg);
}
-#else
- if (seqPlayer->bankDmaMesg == NULL) {
+ #else
+ if (seqPlayer->bankDmaMesg == NULL)
+ {
return;
}
- if (seqPlayer->bankDmaRemaining == 0) {
+ if (seqPlayer->bankDmaRemaining == 0)
+ {
seqPlayer->bankDmaInProgress = FALSE;
patch_audio_bank(seqPlayer->loadingBank, gAlTbl->seqArray[seqPlayer->loadingBankId].offset,
seqPlayer->loadingBankNumInstruments, seqPlayer->loadingBankNumDrums);
@@ -2302,97 +2543,108 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
gCtlEntries[seqPlayer->loadingBankId].instruments = seqPlayer->loadingBank->instruments;
gCtlEntries[seqPlayer->loadingBankId].drums = seqPlayer->loadingBank->drums;
gBankLoadStatus[seqPlayer->loadingBankId] = SOUND_LOAD_STATUS_COMPLETE;
- } else {
+ }
+ else
+ {
osCreateMesgQueue(&seqPlayer->bankDmaMesgQueue, &seqPlayer->bankDmaMesg, 1);
seqPlayer->bankDmaMesg = NULL;
audio_dma_partial_copy_async(&seqPlayer->bankDmaCurrDevAddr, &seqPlayer->bankDmaCurrMemAddr,
&seqPlayer->bankDmaRemaining, &seqPlayer->bankDmaMesgQueue,
&seqPlayer->bankDmaIoMesg);
}
-#endif
+ #endif
return;
}
- if (seqPlayer->seqDmaInProgress == TRUE) {
-#ifdef VERSION_EU
- if (osRecvMesg(&seqPlayer->seqDmaMesgQueue, NULL, 0) == -1) {
+ if (seqPlayer->seqDmaInProgress == TRUE)
+ {
+ #ifdef VERSION_EU
+ if (osRecvMesg(&seqPlayer->seqDmaMesgQueue, NULL, 0) == -1)
+ {
return;
}
-#ifndef AVOID_UB
- if (temp) {
+ #ifndef AVOID_UB
+ if (temp)
+ {
}
-#endif
-#else
- if (seqPlayer->seqDmaMesg == NULL) {
+ #endif
+ #else
+ if (seqPlayer->seqDmaMesg == NULL)
+ {
return;
}
-#endif
+ #endif
seqPlayer->seqDmaInProgress = FALSE;
gSeqLoadStatus[seqPlayer->seqId] = SOUND_LOAD_STATUS_COMPLETE;
}
-#endif
+ #endif
// If discarded, bail out.
if (IS_SEQ_LOAD_COMPLETE(seqPlayer->seqId) == FALSE
- || (
-#ifdef VERSION_SH
- seqPlayer->defaultBank[0] != 0xff &&
-#endif
- IS_BANK_LOAD_COMPLETE(seqPlayer->defaultBank[0]) == FALSE)) {
+ || IS_BANK_LOAD_COMPLETE(seqPlayer->defaultBank[0]) == FALSE)
+ {
eu_stubbed_printf_1("Disappear Sequence or Bank %d\n", seqPlayer->seqId);
sequence_player_disable(seqPlayer);
return;
}
// Remove possible SOUND_LOAD_STATUS_DISCARDABLE marks.
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
if (gSeqLoadStatus[seqPlayer->seqId] != 5)
-#endif
- gSeqLoadStatus[seqPlayer->seqId] = SOUND_LOAD_STATUS_COMPLETE;
+ #endif
+ gSeqLoadStatus[seqPlayer->seqId] = SOUND_LOAD_STATUS_COMPLETE;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
if (gBankLoadStatus[seqPlayer->defaultBank[0]] != 5)
-#endif
- gBankLoadStatus[seqPlayer->defaultBank[0]] = SOUND_LOAD_STATUS_COMPLETE;
+ #endif
+ gBankLoadStatus[seqPlayer->defaultBank[0]] = SOUND_LOAD_STATUS_COMPLETE;
- if (seqPlayer->muted && (seqPlayer->muteBehavior & MUTE_BEHAVIOR_STOP_SCRIPT) != 0) {
+ if (seqPlayer->muted && (seqPlayer->muteBehavior & MUTE_BEHAVIOR_STOP_SCRIPT) != 0)
+ {
return;
}
// Check if we surpass the number of ticks needed for a tatum, else stop.
seqPlayer->tempoAcc += seqPlayer->tempo;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
seqPlayer->tempoAcc += seqPlayer->tempoAdd;
-#endif
- if (seqPlayer->tempoAcc < gTempoInternalToExternal) {
+ #endif
+ if (seqPlayer->tempoAcc < gTempoInternalToExternal)
+ {
return;
}
- seqPlayer->tempoAcc -= (u16) gTempoInternalToExternal;
+ seqPlayer->tempoAcc -= (u16)gTempoInternalToExternal;
state = &seqPlayer->scriptState;
- if (seqPlayer->delay > 1) {
-#ifndef AVOID_UB
- if (temp) {
+ if (seqPlayer->delay > 1)
+ {
+ #ifndef AVOID_UB
+ if (temp)
+ {
}
-#endif
+ #endif
seqPlayer->delay--;
- } else {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ }
+ else
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
seqPlayer->recalculateVolume = 1;
-#endif
- for (;;) {
+ #endif
+ for (;;)
+ {
cmd = m64_read_u8(state);
if (cmd == 0xff) // seq_end
{
- if (state->depth == 0) {
+ if (state->depth == 0)
+ {
sequence_player_disable(seqPlayer);
break;
}
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
state->pc = state->stack[--state->depth];
-#else
+ #else
state->depth--, state->pc = state->stack[state->depth];
-#endif
+ #endif
}
if (cmd == 0xfd) // seq_delay
@@ -2407,41 +2659,48 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
break;
}
- if (cmd >= 0xc0) {
- switch (cmd) {
+ if (cmd >= 0xc0)
+ {
+ switch (cmd)
+ {
case 0xff: // seq_end
break;
case 0xfc: // seq_call
u16v = m64_read_s16(state);
- if (0 && state->depth >= 4) {
+ if (0 && state->depth >= 4)
+ {
eu_stubbed_printf_0("Macro Level Over Error!\n");
}
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
state->stack[state->depth++] = state->pc;
-#else
+ #else
state->depth++, state->stack[state->depth - 1] = state->pc;
-#endif
+ #endif
state->pc = seqPlayer->seqData + u16v;
break;
case 0xf8: // seq_loop; loop start, N iterations (or 256 if N = 0)
- if (0 && state->depth >= 4) {
+ if (0 && state->depth >= 4)
+ {
eu_stubbed_printf_0("Macro Level Over Error!\n");
}
state->remLoopIters[state->depth] = m64_read_u8(state);
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
state->stack[state->depth++] = state->pc;
-#else
+ #else
state->depth++, state->stack[state->depth - 1] = state->pc;
-#endif
+ #endif
break;
case 0xf7: // seq_loopend
state->remLoopIters[state->depth - 1]--;
- if (state->remLoopIters[state->depth - 1] != 0) {
+ if (state->remLoopIters[state->depth - 1] != 0)
+ {
state->pc = state->stack[state->depth - 1];
- } else {
+ }
+ else
+ {
state->depth--;
}
break;
@@ -2451,98 +2710,110 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
case 0xf9: // seq_bltz; jump if < 0
case 0xf5: // seq_bgez; jump if >= 0
u16v = m64_read_s16(state);
- if (cmd == 0xfa && value != 0) {
+ if (cmd == 0xfa && value != 0)
+ {
break;
}
- if (cmd == 0xf9 && value >= 0) {
+ if (cmd == 0xf9 && value >= 0)
+ {
break;
}
- if (cmd == 0xf5 && value < 0) {
+ if (cmd == 0xf5 && value < 0)
+ {
break;
}
state->pc = seqPlayer->seqData + u16v;
break;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
case 0xf4:
case 0xf3:
case 0xf2:
temp = m64_read_u8(state);
- if (cmd == 0xf3 && value != 0) {
+ if (cmd == 0xf3 && value != 0)
+ {
break;
}
- if (cmd == 0xf2 && value >= 0) {
+ if (cmd == 0xf2 && value >= 0)
+ {
break;
}
- state->pc += (s8) temp;
+ state->pc += (s8)temp;
break;
-#endif
+ #endif
-#if defined(VERSION_EU) || defined(VERSION_SH)
- case 0xf1: // seq_reservenotes
-#else
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ case 0xf1: // seq_reservenotes
+ #else
case 0xf2: // seq_reservenotes
-#endif
+ #endif
note_pool_clear(&seqPlayer->notePool);
note_pool_fill(&seqPlayer->notePool, m64_read_u8(state));
break;
-#if defined(VERSION_EU) || defined(VERSION_SH)
- case 0xf0: // seq_unreservenotes
-#else
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ case 0xf0: // seq_unreservenotes
+ #else
case 0xf1: // seq_unreservenotes
-#endif
+ #endif
note_pool_clear(&seqPlayer->notePool);
break;
case 0xdf: // seq_transpose; set transposition in semitones
seqPlayer->transposition = 0;
- // fallthrough
+ // fallthrough
case 0xde: // seq_transposerel; add transposition
- seqPlayer->transposition += (s8) m64_read_u8(state);
+ seqPlayer->transposition += (s8)m64_read_u8(state);
break;
case 0xdd: // seq_settempo (bpm)
-#ifndef VERSION_SH
+ #ifndef VERSION_SH
case 0xdc: // seq_addtempo (bpm)
-#endif
-#ifdef VERSION_SH
+ #endif
+ #ifdef VERSION_SH
seqPlayer->tempo = m64_read_u8(state) * TEMPO_SCALE;
-#else
+ #else
temp = m64_read_u8(state);
- if (cmd == 0xdd) {
+ if (cmd == 0xdd)
+ {
seqPlayer->tempo = temp * TEMPO_SCALE;
- } else {
- seqPlayer->tempo += (s8) temp * TEMPO_SCALE;
}
-#endif
+ else
+ {
+ seqPlayer->tempo += (s8)temp * TEMPO_SCALE;
+ }
+ #endif
- if (seqPlayer->tempo > gTempoInternalToExternal) {
+ if (seqPlayer->tempo > gTempoInternalToExternal)
+ {
seqPlayer->tempo = gTempoInternalToExternal;
}
//if (cmd){}
- if ((s16) seqPlayer->tempo <= 0) {
+ if ((s16)seqPlayer->tempo <= 0)
+ {
seqPlayer->tempo = 1;
}
break;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
case 0xdc: // seq_addtempo (bpm)
- seqPlayer->tempoAdd = (s8) m64_read_u8(state) * TEMPO_SCALE;
+ seqPlayer->tempoAdd = (s8)m64_read_u8(state) * TEMPO_SCALE;
break;
-#endif
+ #endif
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
case 0xda:
cmd = m64_read_u8(state);
u16v = m64_read_s16(state);
- switch (cmd) {
+ switch (cmd)
+ {
case SEQUENCE_PLAYER_STATE_0:
case SEQUENCE_PLAYER_STATE_FADE_OUT:
- if (seqPlayer->state != SEQUENCE_PLAYER_STATE_2) {
+ if (seqPlayer->state != SEQUENCE_PLAYER_STATE_2)
+ {
seqPlayer->fadeTimerUnkEu = u16v;
seqPlayer->state = cmd;
}
@@ -2551,41 +2822,47 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
seqPlayer->fadeRemainingFrames = u16v;
seqPlayer->state = cmd;
seqPlayer->fadeVelocity =
- (0.0f - seqPlayer->fadeVolume) / (s32)(u16v & 0xFFFFu);
+ (0.0f - seqPlayer->fadeVolume) / (s32)(u16v & 0xFFFFu);
break;
}
break;
case 0xdb:
temp32 = m64_read_u8(state);
- switch (seqPlayer->state) {
+ switch (seqPlayer->state)
+ {
case SEQUENCE_PLAYER_STATE_2:
break;
case SEQUENCE_PLAYER_STATE_FADE_OUT:
seqPlayer->state = SEQUENCE_PLAYER_STATE_0;
seqPlayer->fadeVolume = 0.0f;
- // fallthrough
+ // fallthrough
case SEQUENCE_PLAYER_STATE_0:
seqPlayer->fadeRemainingFrames = seqPlayer->fadeTimerUnkEu;
- if (seqPlayer->fadeTimerUnkEu != 0) {
+ if (seqPlayer->fadeTimerUnkEu != 0)
+ {
seqPlayer->fadeVelocity = (temp32 / 127.0f - seqPlayer->fadeVolume) / FLOAT_CAST(seqPlayer->fadeRemainingFrames);
- } else {
+ }
+ else
+ {
seqPlayer->fadeVolume = temp32 / 127.0f;
}
}
break;
-#else
+ #else
case 0xdb: // seq_setvol
cmd = m64_read_u8(state);
- switch (seqPlayer->state) {
+ switch (seqPlayer->state)
+ {
case SEQUENCE_PLAYER_STATE_2:
- if (seqPlayer->fadeRemainingFrames != 0) {
+ if (seqPlayer->fadeRemainingFrames != 0)
+ {
f32 targetVolume = FLOAT_CAST(cmd) / US_FLOAT(127.0);
seqPlayer->fadeVelocity = (targetVolume - seqPlayer->fadeVolume)
/ FLOAT_CAST(seqPlayer->fadeRemainingFrames);
break;
}
- // fallthrough
+ // fallthrough
case SEQUENCE_PLAYER_STATE_0:
seqPlayer->fadeVolume = FLOAT_CAST(cmd) / US_FLOAT(127.0);
break;
@@ -2599,16 +2876,17 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
case 0xda: // seq_changevol
temp = m64_read_u8(state);
seqPlayer->fadeVolume =
- seqPlayer->fadeVolume + (f32)(s8) temp / US_FLOAT(127.0);
+ seqPlayer->fadeVolume + (f32)(s8)
+ temp / US_FLOAT(127.0);
break;
-#endif
+ #endif
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
case 0xd9:
temp = m64_read_u8(state);
- seqPlayer->fadeVolumeScale = (s8) temp / 127.0f;
+ seqPlayer->fadeVolumeScale = (s8)temp / 127.0f;
break;
-#endif
+ #endif
case 0xd7: // seq_initchannels
u16v = m64_read_s16(state);
@@ -2622,7 +2900,8 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
case 0xd5: // seq_setmutescale
temp = m64_read_u8(state);
- seqPlayer->muteVolumeScale = (f32)(s8) temp / US_FLOAT(127.0);
+ seqPlayer->muteVolumeScale = (f32)(s8)
+ temp / US_FLOAT(127.0);
break;
case 0xd4: // seq_mute
@@ -2637,9 +2916,12 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
case 0xd1: // seq_setshortnotedurationtable
u16v = m64_read_s16(state);
seqData = seqPlayer->seqData + u16v;
- if (cmd == 0xd2) {
+ if (cmd == 0xd2)
+ {
seqPlayer->shortNoteVelocityTable = seqData;
- } else {
+ }
+ else
+ {
seqPlayer->shortNoteDurationTable = seqData;
}
break;
@@ -2653,18 +2935,18 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
break;
case 0xc9: // seq_bitand
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
value &= m64_read_u8(state);
-#else
+ #else
value = m64_read_u8(state) & value;
-#endif
+ #endif
break;
case 0xc8: // seq_subtract
value = value - m64_read_u8(state);
break;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
case 0xc7:
cmd = m64_read_u8(state);
u16v = m64_read_s16(state);
@@ -2675,23 +2957,27 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
case 0xc6:
seqPlayer->unkSh = TRUE;
return;
-#endif
+ #endif
default:
eu_stubbed_printf_1("Group:Undefine upper C0h command (%x)\n", cmd);
break;
}
- } else {
+ }
+ else
+ {
loBits = cmd & 0xf;
- switch (cmd & 0xf0) {
+ switch (cmd & 0xf0)
+ {
case 0x00: // seq_testchdisabled
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
value = seqPlayer->channels[loBits]->finished;
-#else
- if (IS_SEQUENCE_CHANNEL_VALID(seqPlayer->channels[loBits]) == TRUE) {
+ #else
+ if (IS_SEQUENCE_CHANNEL_VALID(seqPlayer->channels[loBits]) == TRUE)
+ {
value = seqPlayer->channels[loBits]->finished;
}
-#endif
+ #endif
break;
case 0x10:
break;
@@ -2700,27 +2986,27 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
case 0x40:
break;
case 0x50: // seq_subvariation
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
value -= seqPlayer->seqVariationEu[0];
-#else
+ #else
value -= seqPlayer->seqVariation;
-#endif
+ #endif
break;
case 0x60:
break;
case 0x70: // seq_setvariation
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
seqPlayer->seqVariationEu[0] = value;
-#else
+ #else
seqPlayer->seqVariation = value;
-#endif
+ #endif
break;
case 0x80: // seq_getvariation
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
value = seqPlayer->seqVariationEu[0];
-#else
+ #else
value = seqPlayer->seqVariation;
-#endif
+ #endif
break;
case 0x90: // seq_startchannel
u16v = m64_read_s16(state);
@@ -2728,12 +3014,12 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
break;
case 0xa0:
break;
-#if !defined(VERSION_EU) && !defined(VERSION_SH)
+ #if !defined(VERSION_EU) && !defined(VERSION_SH)
case 0xd8: // (this makes no sense)
break;
case 0xd9:
break;
-#endif
+ #endif
default:
eu_stubbed_printf_0("Group:Undefined Command\n");
@@ -2743,127 +3029,140 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
}
}
- for (i = 0; i < CHANNELS_MAX; i++) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
- if (IS_SEQUENCE_CHANNEL_VALID(seqPlayer->channels[i]) == TRUE) {
+ for (i = 0; i < CHANNELS_MAX; i++)
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ if (IS_SEQUENCE_CHANNEL_VALID(seqPlayer->channels[i]) == TRUE)
+ {
sequence_channel_process_script(seqPlayer->channels[i]);
}
-#else
- if (seqPlayer->channels[i] != &gSequenceChannelNone) {
+ #else
+ if (seqPlayer->channels[i] != &gSequenceChannelNone)
+ {
sequence_channel_process_script(seqPlayer->channels[i]);
}
-#endif
+ #endif
}
}
// This runs 240 times per second.
-void process_sequences(UNUSED s32 iterationsRemaining) {
+void process_sequences(UNUSED s32 iterationsRemaining)
+{
s32 i;
- for (i = 0; i < SEQUENCE_PLAYERS; i++) {
- if (gSequencePlayers[i].enabled == TRUE) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ for (i = 0; i < SEQUENCE_PLAYERS; i++)
+ {
+ if (gSequencePlayers[i].enabled == TRUE)
+ {
+ #if defined(VERSION_EU) || defined(VERSION_SH)
sequence_player_process_sequence(&gSequencePlayers[i]);
sequence_player_process_sound(&gSequencePlayers[i]);
-#else
+ #else
sequence_player_process_sequence(gSequencePlayers + i);
sequence_player_process_sound(gSequencePlayers + i);
-#endif
+ #endif
}
}
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #if defined(VERSION_JP) || defined(VERSION_US)
reclaim_notes();
-#endif
+ #endif
process_notes();
}
-void init_sequence_player(u32 player) {
+void init_sequence_player(u32 player)
+{
struct SequencePlayer *seqPlayer = &gSequencePlayers[player];
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
sequence_player_disable(seqPlayer);
-#endif
-#ifdef VERSION_SH
+ #endif
+ #ifdef VERSION_SH
seqPlayer->unkSh = FALSE;
-#else
+ #else
seqPlayer->muted = FALSE;
-#endif
+ #endif
seqPlayer->delay = 0;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
seqPlayer->state = 1;
-#else
+ #else
seqPlayer->state = SEQUENCE_PLAYER_STATE_0;
-#endif
+ #endif
seqPlayer->fadeRemainingFrames = 0;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
seqPlayer->fadeTimerUnkEu = 0;
-#endif
+ #endif
seqPlayer->tempoAcc = 0;
seqPlayer->tempo = 120 * TEMPO_SCALE; // 120 BPM
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
seqPlayer->tempoAdd = 0;
-#endif
+ #endif
seqPlayer->transposition = 0;
-#ifndef VERSION_SH
+ #ifndef VERSION_SH
seqPlayer->muteBehavior = MUTE_BEHAVIOR_STOP_SCRIPT | MUTE_BEHAVIOR_STOP_NOTES | MUTE_BEHAVIOR_SOFTEN;
-#endif
+ #endif
seqPlayer->noteAllocPolicy = 0;
seqPlayer->shortNoteVelocityTable = gDefaultShortNoteVelocityTable;
seqPlayer->shortNoteDurationTable = gDefaultShortNoteDurationTable;
seqPlayer->fadeVolume = 1.0f;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
seqPlayer->fadeVolumeScale = 1.0f;
-#endif
+ #endif
seqPlayer->fadeVelocity = 0.0f;
seqPlayer->volume = 0.0f;
seqPlayer->muteVolumeScale = 0.5f;
}
-void init_sequence_players(void) {
+void init_sequence_players(void)
+{
// Initialization function, called from audio_init
s32 i, j;
- for (i = 0; i < ARRAY_COUNT(gSequenceChannels); i++) {
+ for (i = 0; i < ARRAY_COUNT(gSequenceChannels); i++)
+ {
gSequenceChannels[i].seqPlayer = NULL;
gSequenceChannels[i].enabled = FALSE;
-#if defined(VERSION_JP) || defined(VERSION_US)
+ #if defined(VERSION_JP) || defined(VERSION_US)
}
- for (i = 0; i < ARRAY_COUNT(gSequenceChannels); i++) {
-#endif
+ for (i = 0; i < ARRAY_COUNT(gSequenceChannels); i++) {
+ #endif
// @bug Size of wrong array. Zeroes out second half of gSequenceChannels[0],
// all of gSequenceChannels[1..31], and part of gSequenceLayers[0].
// However, this is only called at startup, so it's harmless.
-#ifdef AVOID_UB
-#define LAYERS_SIZE LAYERS_MAX
-#else
-#define LAYERS_SIZE ARRAY_COUNT(gSequenceLayers)
-#endif
- for (j = 0; j < LAYERS_SIZE; j++) {
+ #ifdef AVOID_UB
+ #define LAYERS_SIZE LAYERS_MAX
+ #else
+ #define LAYERS_SIZE ARRAY_COUNT(gSequenceLayers)
+ #endif
+ for (j = 0; j < LAYERS_SIZE; j++)
+ {
gSequenceChannels[i].layers[j] = NULL;
}
}
init_layer_freelist();
- for (i = 0; i < ARRAY_COUNT(gSequenceLayers); i++) {
+ for (i = 0; i < ARRAY_COUNT(gSequenceLayers); i++)
+ {
gSequenceLayers[i].seqChannel = NULL;
gSequenceLayers[i].enabled = FALSE;
}
- for (i = 0; i < SEQUENCE_PLAYERS; i++) {
- for (j = 0; j < CHANNELS_MAX; j++) {
+ for (i = 0; i < SEQUENCE_PLAYERS; i++)
+ {
+ for (j = 0; j < CHANNELS_MAX; j++)
+ {
gSequencePlayers[i].channels[j] = &gSequenceChannelNone;
}
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ #if defined(VERSION_EU) || defined(VERSION_SH)
gSequencePlayers[i].seqVariationEu[0] = -1;
-#else
+ #else
gSequencePlayers[i].seqVariation = -1;
-#endif
-#ifdef VERSION_SH
+ #endif
+ #ifdef VERSION_SH
gSequencePlayers[i].muteBehavior = MUTE_BEHAVIOR_STOP_SCRIPT | MUTE_BEHAVIOR_STOP_NOTES | MUTE_BEHAVIOR_SOFTEN;
gSequencePlayers[i].enabled = FALSE;
gSequencePlayers[i].muted = FALSE;
-#endif
+ #endif
gSequencePlayers[i].bankDmaInProgress = FALSE;
gSequencePlayers[i].seqDmaInProgress = FALSE;
init_note_lists(&gSequencePlayers[i].notePool);
diff --git a/src/decomp/audio/seqplayer.h b/src/decomp/audio/seqplayer.h
index d2fc134..2d2ba7e 100644
--- a/src/decomp/audio/seqplayer.h
+++ b/src/decomp/audio/seqplayer.h
@@ -7,12 +7,19 @@
#include "playback.h"
void seq_channel_layer_disable(struct SequenceChannelLayer *seqPlayer);
+
void sequence_channel_disable(struct SequenceChannel *seqPlayer);
-void sequence_player_disable(struct SequencePlayer* seqPlayer);
+
+void sequence_player_disable(struct SequencePlayer *seqPlayer);
+
void audio_list_push_back(struct AudioListItem *list, struct AudioListItem *item);
+
void *audio_list_pop_back(struct AudioListItem *list);
+
void process_sequences(s32 iterationsRemaining);
+
void init_sequence_player(u32 player);
+
void init_sequence_players(void);
#endif // AUDIO_SEQPLAYER_H
diff --git a/src/decomp/audio/shindou_debug_prints.c b/src/decomp/audio/shindou_debug_prints.c
index 261d452..34108c0 100644
--- a/src/decomp/audio/shindou_debug_prints.c
+++ b/src/decomp/audio/shindou_debug_prints.c
@@ -6,7 +6,7 @@ char shindouDebugPrint1[] = "Terminate-Canceled Channel %d,Phase %d\n";
char shindouDebugPrint2[] = "S->W\n";
char shindouDebugPrint3[] = "W->S\n";
char shindouDebugPrint4[] = "S-Resample Pitch %x (old %d -> delay %d)\n";
-s32 shindouDebugPrintPadding1[] = {0,0,0};
+s32 shindouDebugPrintPadding1[] = {0, 0, 0};
// heap.c
char shindouDebugPrint5[] = "Warning:Kill Note %x \n";
diff --git a/src/decomp/audio/synthesis.c b/src/decomp/audio/synthesis.c
index d673171..f541030 100644
--- a/src/decomp/audio/synthesis.c
+++ b/src/decomp/audio/synthesis.c
@@ -45,7 +45,8 @@
#define ALIGN(val, amnt) (((val) + (1 << amnt) - 1) & ~((1 << amnt) - 1))
-struct VolumeChange {
+struct VolumeChange
+{
u16 sourceLeft;
u16 sourceRight;
u16 targetLeft;
@@ -61,12 +62,19 @@ u64 *process_envelope(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesi
u64 *note_apply_headset_pan_effects(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *note, s32 bufLen, s32 flags, s32 leftRight);
#else
u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd);
+
u64 *load_wave_samples(u64 *cmd, struct Note *note, s32 nSamplesToLoad);
+
u64 *final_resample(u64 *cmd, struct Note *note, s32 count, u16 pitch, u16 dmemIn, u32 flags);
-u64 *process_envelope(u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf, s32 headsetPanSettings,
- u32 flags);
-u64 *process_envelope_inner(u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf,
- s32 headsetPanSettings, struct VolumeChange *vol);
+
+u64 *process_envelope(
+ u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf, s32 headsetPanSettings,
+ u32 flags);
+
+u64 *process_envelope_inner(
+ u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf,
+ s32 headsetPanSettings, struct VolumeChange *vol);
+
u64 *note_apply_headset_pan_effects(u64 *cmd, struct Note *note, s32 bufLen, s32 flags, s32 leftRight);
#endif
@@ -98,7 +106,8 @@ u8 audioString2[] = "cont %x: delaybytes %d : olddelay %d\n";
#ifdef VERSION_EU
// Equivalent functionality as the US/JP version,
// just that the reverb structure is chosen from an array with index
-void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex) {
+void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex)
+{
struct ReverbRingBufferItem *item;
struct SynthesisReverb *reverb = &gSynthesisReverbs[reverbIndex];
s32 srcPos;
@@ -106,8 +115,10 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex)
s32 nSamples;
s32 excessiveSamples;
s32 UNUSED pad[3];
- if (reverb->downsampleRate != 1) {
- if (reverb->framesLeftToIgnore == 0) {
+ if (reverb->downsampleRate != 1)
+ {
+ if (reverb->framesLeftToIgnore == 0)
+ {
// Now that the RSP has finished, downsample the samples produced two frames ago by skipping
// samples.
item = &reverb->items[reverb->curFrame][updateIndex];
@@ -116,13 +127,15 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex)
osInvalDCache(item->toDownsampleLeft, DEFAULT_LEN_2CH);
for (srcPos = 0, dstPos = 0; dstPos < item->lengthA / 2;
- srcPos += reverb->downsampleRate, dstPos++) {
+ srcPos += reverb->downsampleRate, dstPos++)
+ {
reverb->ringBuffer.left[item->startPos + dstPos] =
- item->toDownsampleLeft[srcPos];
+ item->toDownsampleLeft[srcPos];
reverb->ringBuffer.right[item->startPos + dstPos] =
- item->toDownsampleRight[srcPos];
+ item->toDownsampleRight[srcPos];
}
- for (dstPos = 0; dstPos < item->lengthB / 2; srcPos += reverb->downsampleRate, dstPos++) {
+ for (dstPos = 0; dstPos < item->lengthB / 2; srcPos += reverb->downsampleRate, dstPos++)
+ {
reverb->ringBuffer.left[dstPos] = item->toDownsampleLeft[srcPos];
reverb->ringBuffer.right[dstPos] = item->toDownsampleRight[srcPos];
}
@@ -132,13 +145,16 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex)
item = &reverb->items[reverb->curFrame][updateIndex];
nSamples = chunkLen / reverb->downsampleRate;
excessiveSamples = (nSamples + reverb->nextRingBufferPos) - reverb->bufSizePerChannel;
- if (excessiveSamples < 0) {
+ if (excessiveSamples < 0)
+ {
// There is space in the ring buffer before it wraps around
item->lengthA = nSamples * 2;
item->lengthB = 0;
- item->startPos = (s32) reverb->nextRingBufferPos;
+ item->startPos = (s32)reverb->nextRingBufferPos;
reverb->nextRingBufferPos += nSamples;
- } else {
+ }
+ else
+ {
// Ring buffer wrapped around
item->lengthA = (nSamples - excessiveSamples) * 2;
item->lengthB = excessiveSamples * 2;
@@ -150,15 +166,18 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex)
item->chunkLen = chunkLen;
}
#else
-void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex) {
+void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex)
+{
struct ReverbRingBufferItem *item;
s32 srcPos;
s32 dstPos;
s32 nSamples;
s32 numSamplesAfterDownsampling;
s32 excessiveSamples;
- if (gReverbDownsampleRate != 1) {
- if (gSynthesisReverb.framesLeftToIgnore == 0) {
+ if (gReverbDownsampleRate != 1)
+ {
+ if (gSynthesisReverb.framesLeftToIgnore == 0)
+ {
// Now that the RSP has finished, downsample the samples produced two frames ago by skipping
// samples.
item = &gSynthesisReverb.items[gSynthesisReverb.curFrame][updateIndex];
@@ -167,13 +186,15 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex) {
osInvalDCache(item->toDownsampleLeft, DEFAULT_LEN_2CH);
for (srcPos = 0, dstPos = 0; dstPos < item->lengthA / 2;
- srcPos += gReverbDownsampleRate, dstPos++) {
+ srcPos += gReverbDownsampleRate, dstPos++)
+ {
gSynthesisReverb.ringBuffer.left[dstPos + item->startPos] =
- item->toDownsampleLeft[srcPos];
+ item->toDownsampleLeft[srcPos];
gSynthesisReverb.ringBuffer.right[dstPos + item->startPos] =
- item->toDownsampleRight[srcPos];
+ item->toDownsampleRight[srcPos];
}
- for (dstPos = 0; dstPos < item->lengthB / 2; srcPos += gReverbDownsampleRate, dstPos++) {
+ for (dstPos = 0; dstPos < item->lengthB / 2; srcPos += gReverbDownsampleRate, dstPos++)
+ {
gSynthesisReverb.ringBuffer.left[dstPos] = item->toDownsampleLeft[srcPos];
gSynthesisReverb.ringBuffer.right[dstPos] = item->toDownsampleRight[srcPos];
}
@@ -182,16 +203,19 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex) {
item = &gSynthesisReverb.items[gSynthesisReverb.curFrame][updateIndex];
numSamplesAfterDownsampling = chunkLen / gReverbDownsampleRate;
- if (((numSamplesAfterDownsampling + gSynthesisReverb.nextRingBufferPos) - gSynthesisReverb.bufSizePerChannel) < 0) {
+ if (numSamplesAfterDownsampling + gSynthesisReverb.nextRingBufferPos - gSynthesisReverb.bufSizePerChannel < 0)
+ {
// There is space in the ring buffer before it wraps around
item->lengthA = numSamplesAfterDownsampling * 2;
item->lengthB = 0;
- item->startPos = (s32) gSynthesisReverb.nextRingBufferPos;
+ item->startPos = gSynthesisReverb.nextRingBufferPos;
gSynthesisReverb.nextRingBufferPos += numSamplesAfterDownsampling;
- } else {
+ }
+ else
+ {
// Ring buffer wrapped around
excessiveSamples =
- (numSamplesAfterDownsampling + gSynthesisReverb.nextRingBufferPos) - gSynthesisReverb.bufSizePerChannel;
+ numSamplesAfterDownsampling + gSynthesisReverb.nextRingBufferPos - gSynthesisReverb.bufSizePerChannel;
nSamples = numSamplesAfterDownsampling - excessiveSamples;
item->lengthA = nSamples * 2;
item->lengthB = excessiveSamples * 2;
@@ -205,7 +229,8 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex) {
#endif
#ifdef VERSION_EU
-u64 *synthesis_load_reverb_ring_buffer(u64 *cmd, u16 addr, u16 srcOffset, s32 len, s32 reverbIndex) {
+u64 *synthesis_load_reverb_ring_buffer(u64 *cmd, u16 addr, u16 srcOffset, s32 len, s32 reverbIndex)
+{
aSetBuffer(cmd++, 0, addr, 0, len);
aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.left[srcOffset]));
@@ -217,7 +242,8 @@ u64 *synthesis_load_reverb_ring_buffer(u64 *cmd, u16 addr, u16 srcOffset, s32 le
#endif
#ifdef VERSION_EU
-u64 *synthesis_save_reverb_ring_buffer(u64 *cmd, u16 addr, u16 destOffset, s32 len, s32 reverbIndex) {
+u64 *synthesis_save_reverb_ring_buffer(u64 *cmd, u16 addr, u16 destOffset, s32 len, s32 reverbIndex)
+{
aSetBuffer(cmd++, 0, 0, addr, len);
aSaveBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.left[destOffset]));
@@ -229,18 +255,23 @@ u64 *synthesis_save_reverb_ring_buffer(u64 *cmd, u16 addr, u16 destOffset, s32 l
#endif
#ifdef VERSION_EU
-void synthesis_load_note_subs_eu(s32 updateIndex) {
+void synthesis_load_note_subs_eu(s32 updateIndex)
+{
struct NoteSubEu *src;
struct NoteSubEu *dest;
s32 i;
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
src = &gNotes[i].noteSubEu;
dest = &gNoteSubsEu[gMaxSimultaneousNotes * updateIndex + i];
- if (src->enabled) {
+ if (src->enabled)
+ {
*dest = *src;
src->needsInit = FALSE;
- } else {
+ }
+ else
+ {
dest->enabled = FALSE;
}
}
@@ -248,11 +279,13 @@ void synthesis_load_note_subs_eu(s32 updateIndex) {
#endif
#ifndef VERSION_EU
-s32 get_volume_ramping(u16 sourceVol, u16 targetVol, s32 arg2) {
+s32 get_volume_ramping(u16 sourceVol, u16 targetVol, s32 arg2)
+{
// This roughly computes 2^16 * (targetVol / sourceVol) ^ (8 / arg2),
// but with discretizations of targetVol, sourceVol and arg2.
f32 ret;
- switch (arg2) {
+ switch (arg2)
+ {
default:
ret = gVolRampingLhs136[targetVol >> 8] * gVolRampingRhs136[sourceVol >> 8];
break;
@@ -272,7 +305,8 @@ s32 get_volume_ramping(u16 sourceVol, u16 targetVol, s32 arg2) {
#ifdef VERSION_EU
// TODO: (Scrub C) pointless mask and whitespace
-u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) {
+u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen)
+{
s32 i, j;
f32 *leftVolRamp;
f32 *rightVolRamp;
@@ -281,20 +315,22 @@ u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) {
s32 chunkLen;
s32 nextVolRampTable;
- for (i = gAudioBufferParameters.updatesPerFrame; i > 0; i--) {
+ for (i = gAudioBufferParameters.updatesPerFrame; i > 0; i--)
+ {
process_sequences(i - 1);
synthesis_load_note_subs_eu(gAudioBufferParameters.updatesPerFrame - i);
}
aSegment(cmd++, 0, 0);
- aiBufPtr = (u32 *) aiBuf;
- for (i = gAudioBufferParameters.updatesPerFrame; i > 0; i--) {
+ aiBufPtr = (u32 *)aiBuf;
+ for (i = gAudioBufferParameters.updatesPerFrame; i > 0; i--)
+ {
if (i == 1) {
#pragma GCC diagnostic push
#if defined(__clang__)
#pragma GCC diagnostic ignored "-Wself-assign"
#endif
- // self-assignment has no affect when added here, could possibly simplify a macro definition
- chunkLen = bufLen; nextVolRampTable = nextVolRampTable; leftVolRamp = gLeftVolRampings[nextVolRampTable]; rightVolRamp = gRightVolRampings[nextVolRampTable & 0xFFFFFFFF];
+// self-assignment has no affect when added here, could possibly simplify a macro definition
+chunkLen= bufLen; nextVolRampTable= nextVolRampTable; leftVolRamp= gLeftVolRampings[nextVolRampTable]; rightVolRamp= gRightVolRampings[nextVolRampTable & 0xFFFFFFFF];
#pragma GCC diagnostic pop
} else {
if (bufLen / i >= gAudioBufferParameters.samplesPerUpdateMax) {
@@ -305,61 +341,69 @@ u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) {
chunkLen = gAudioBufferParameters.samplesPerUpdate; nextVolRampTable = 1; leftVolRamp = gLeftVolRampings[1]; rightVolRamp = gRightVolRampings[1];
}
}
- gCurrentLeftVolRamping = leftVolRamp;
- gCurrentRightVolRamping = rightVolRamp;
- for (j = 0; j < gNumSynthesisReverbs; j++) {
+gCurrentLeftVolRamping= leftVolRamp;
+gCurrentRightVolRamping= rightVolRamp;
+ for (j =0; j 0; i--) {
- if (i == 1) {
+ for (i = gAudioUpdatesPerFrame; i > 0; i--)
+ {
+ if (i == 1)
+ {
// 'bufLen' will automatically be divisible by 8, no need to round
chunkLen = bufLen;
- } else {
+ }
+ else
+ {
v0 = bufLen / i;
// chunkLen = v0 rounded to nearest multiple of 8
chunkLen = v0 - (v0 & 7);
- if ((v0 & 7) >= 4) {
+ if ((v0 & 7) >= 4)
+ {
chunkLen += 8;
}
}
process_sequences(i - 1);
- if (gSynthesisReverb.useReverb != 0) {
+ if (gSynthesisReverb.useReverb != 0)
+ {
prepare_reverb_ring_buffer(chunkLen, gAudioUpdatesPerFrame - i);
}
- cmd = synthesis_do_one_audio_update((s16 *) aiBufPtr, chunkLen, cmd, gAudioUpdatesPerFrame - i);
+ cmd = synthesis_do_one_audio_update((s16 *)aiBufPtr, chunkLen, cmd, gAudioUpdatesPerFrame - i);
bufLen -= chunkLen;
aiBufPtr += chunkLen;
}
- if (gSynthesisReverb.framesLeftToIgnore != 0) {
+ if (gSynthesisReverb.framesLeftToIgnore != 0)
+ {
gSynthesisReverb.framesLeftToIgnore--;
}
gSynthesisReverb.curFrame ^= 1;
@@ -370,7 +414,8 @@ u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) {
#ifdef VERSION_EU
-u64 *synthesis_resample_and_mix_reverb(u64 *cmd, s32 bufLen, s16 reverbIndex, s16 updateIndex) {
+u64 *synthesis_resample_and_mix_reverb(u64 *cmd, s32 bufLen, s16 reverbIndex, s16 updateIndex)
+{
struct ReverbRingBufferItem *item;
s16 startPad;
s16 paddedLengthA;
@@ -378,20 +423,25 @@ u64 *synthesis_resample_and_mix_reverb(u64 *cmd, s32 bufLen, s16 reverbIndex, s1
item = &gSynthesisReverbs[reverbIndex].items[gSynthesisReverbs[reverbIndex].curFrame][updateIndex];
aClearBuffer(cmd++, DMEM_ADDR_WET_LEFT_CH, DEFAULT_LEN_2CH);
- if (gSynthesisReverbs[reverbIndex].downsampleRate == 1) {
+ if (gSynthesisReverbs[reverbIndex].downsampleRate == 1)
+ {
cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_WET_LEFT_CH, item->startPos, item->lengthA, reverbIndex);
- if (item->lengthB != 0) {
+ if (item->lengthB != 0)
+ {
cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_WET_LEFT_CH + item->lengthA, 0, item->lengthB, reverbIndex);
}
aSetBuffer(cmd++, 0, 0, 0, DEFAULT_LEN_2CH);
aMix(cmd++, 0, 0x7fff, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_LEFT_CH);
aMix(cmd++, 0, 0x8000 + gSynthesisReverbs[reverbIndex].reverbGain, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_WET_LEFT_CH);
- } else {
+ }
+ else
+ {
startPad = (item->startPos % 8u) * 2;
paddedLengthA = ALIGN(startPad + item->lengthA, 4);
cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED, (item->startPos - startPad / 2), DEFAULT_LEN_1CH, reverbIndex);
- if (item->lengthB != 0) {
+ if (item->lengthB != 0)
+ {
cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED + paddedLengthA, 0, DEFAULT_LEN_1CH - paddedLengthA, reverbIndex);
}
@@ -408,16 +458,20 @@ u64 *synthesis_resample_and_mix_reverb(u64 *cmd, s32 bufLen, s16 reverbIndex, s1
return cmd;
}
-u64 *synthesis_save_reverb_samples(u64 *cmd, s16 reverbIndex, s16 updateIndex) {
+u64 *synthesis_save_reverb_samples(u64 *cmd, s16 reverbIndex, s16 updateIndex)
+{
struct ReverbRingBufferItem *item;
item = &gSynthesisReverbs[reverbIndex].items[gSynthesisReverbs[reverbIndex].curFrame][updateIndex];
- if (gSynthesisReverbs[reverbIndex].useReverb != 0) {
- switch (gSynthesisReverbs[reverbIndex].downsampleRate) {
+ if (gSynthesisReverbs[reverbIndex].useReverb != 0)
+ {
+ switch (gSynthesisReverbs[reverbIndex].downsampleRate)
+ {
case 1:
// Put the oldest samples in the ring buffer into the wet channels
cmd = synthesis_save_reverb_ring_buffer(cmd, DMEM_ADDR_WET_LEFT_CH, item->startPos, item->lengthA, reverbIndex);
- if (item->lengthB != 0) {
+ if (item->lengthB != 0)
+ {
// Ring buffer wrapped
cmd = synthesis_save_reverb_ring_buffer(cmd, DMEM_ADDR_WET_LEFT_CH + item->lengthA, 0, item->lengthB, reverbIndex);
}
@@ -437,7 +491,8 @@ u64 *synthesis_save_reverb_samples(u64 *cmd, s16 reverbIndex, s16 updateIndex) {
#endif
#ifdef VERSION_EU
-u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex) {
+u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex)
+{
struct NoteSubEu *noteSubEu;
u8 noteIndices[56];
s32 temp;
@@ -445,60 +500,81 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI
s16 j;
s16 notePos = 0;
- if (gNumSynthesisReverbs == 0) {
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
- if (gNoteSubsEu[gMaxSimultaneousNotes * updateIndex + i].enabled) {
+ if (gNumSynthesisReverbs == 0)
+ {
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
+ if (gNoteSubsEu[gMaxSimultaneousNotes * updateIndex + i].enabled)
+ {
noteIndices[notePos++] = i;
}
}
- } else {
- for (j = 0; j < gNumSynthesisReverbs; j++) {
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
+ }
+ else
+ {
+ for (j = 0; j < gNumSynthesisReverbs; j++)
+ {
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
noteSubEu = &gNoteSubsEu[gMaxSimultaneousNotes * updateIndex + i];
- if (noteSubEu->enabled && j == noteSubEu->reverbIndex) {
+ if (noteSubEu->enabled && j == noteSubEu->reverbIndex)
+ {
noteIndices[notePos++] = i;
}
}
}
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
noteSubEu = &gNoteSubsEu[gMaxSimultaneousNotes * updateIndex + i];
- if (noteSubEu->enabled && noteSubEu->reverbIndex >= gNumSynthesisReverbs) {
+ if (noteSubEu->enabled && noteSubEu->reverbIndex >= gNumSynthesisReverbs)
+ {
noteIndices[notePos++] = i;
}
}
}
aClearBuffer(cmd++, DMEM_ADDR_LEFT_CH, DEFAULT_LEN_2CH);
i = 0;
- for (j = 0; j < gNumSynthesisReverbs; j++) {
+ for (j = 0; j < gNumSynthesisReverbs; j++)
+ {
gUseReverb = gSynthesisReverbs[j].useReverb;
- if (gUseReverb != 0) {
+ if (gUseReverb != 0)
+ {
cmd = synthesis_resample_and_mix_reverb(cmd, bufLen, j, updateIndex);
}
- for (; i < notePos; i++) {
+ for (; i < notePos; i++)
+ {
temp = updateIndex * gMaxSimultaneousNotes;
- if (j == gNoteSubsEu[temp + noteIndices[i]].reverbIndex) {
+ if (j == gNoteSubsEu[temp + noteIndices[i]].reverbIndex)
+ {
cmd = synthesis_process_note(&gNotes[noteIndices[i]],
&gNoteSubsEu[temp + noteIndices[i]],
&gNotes[noteIndices[i]].synthesisState,
aiBuf, bufLen, cmd);
continue;
- } else {
+ }
+ else
+ {
break;
}
}
- if (gSynthesisReverbs[j].useReverb != 0) {
+ if (gSynthesisReverbs[j].useReverb != 0)
+ {
cmd = synthesis_save_reverb_samples(cmd, j, updateIndex);
}
}
- for (; i < notePos; i++) {
+ for (; i < notePos; i++)
+ {
temp = updateIndex * gMaxSimultaneousNotes;
- if (IS_BANK_LOAD_COMPLETE(gNoteSubsEu[temp + noteIndices[i]].bankId) == TRUE) {
+ if (IS_BANK_LOAD_COMPLETE(gNoteSubsEu[temp + noteIndices[i]].bankId) == TRUE)
+ {
cmd = synthesis_process_note(&gNotes[noteIndices[i]],
&gNoteSubsEu[temp + noteIndices[i]],
&gNotes[noteIndices[i]].synthesisState,
aiBuf, bufLen, cmd);
- } else {
+ }
+ else
+ {
gAudioErrorFlags = (gNoteSubsEu[temp + noteIndices[i]].bankId + (i << 8)) + 0x10000000;
}
}
@@ -511,8 +587,9 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI
return cmd;
}
#else
-u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex) {
- DEBUG_PRINT("synthesis_do_one_audio_update()");
+u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex)
+{
+ DEBUG_PRINT("synthesis_do_one_audio_update()");
UNUSED s32 pad1[1];
s16 ra;
@@ -522,54 +599,62 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI
UNUSED s32 pad2[1];
s16 temp;
- DEBUG_PRINT("- curFrame: %d", gSynthesisReverb.curFrame);
- DEBUG_PRINT("- updateIndex: %d", updateIndex);
+ DEBUG_PRINT("- curFrame: %d", gSynthesisReverb.curFrame);
+ DEBUG_PRINT("- updateIndex: %d", updateIndex);
v1 = &gSynthesisReverb.items[gSynthesisReverb.curFrame][updateIndex];
- DEBUG_PRINT("- v1: %x", v1);
+ DEBUG_PRINT("- v1: %x", v1);
- if (gSynthesisReverb.useReverb == 0) {
- DEBUG_PRINT("- w/o reverb");
+ if (gSynthesisReverb.useReverb == 0)
+ {
+ DEBUG_PRINT("- w/o reverb");
aClearBuffer(cmd++, DMEM_ADDR_LEFT_CH, DEFAULT_LEN_2CH);
cmd = synthesis_process_notes(aiBuf, bufLen, cmd);
- } else {
- DEBUG_PRINT("- w/ reverb");
- if (gReverbDownsampleRate == 1) {
- DEBUG_PRINT("- w/ reverb downsample");
+ }
+ else
+ {
+ DEBUG_PRINT("- w/ reverb");
+ if (gReverbDownsampleRate == 1)
+ {
+ DEBUG_PRINT("- w/ reverb downsample");
// Put the oldest samples in the ring buffer into the wet channels
- DEBUG_PRINT("- set load buffer pair 1");
- DEBUG_PRINT("- startPos: %d", v1->startPos);
+ DEBUG_PRINT("- set load buffer pair 1");
+ DEBUG_PRINT("- startPos: %d", v1->startPos);
aSetLoadBufferPair(cmd++, 0, v1->startPos);
- if (v1->lengthB != 0) {
+ if (v1->lengthB != 0)
+ {
// Ring buffer wrapped
- DEBUG_PRINT("- set load buffer pair 2");
+ DEBUG_PRINT("- set load buffer pair 2");
aSetLoadBufferPair(cmd++, v1->lengthA, 0);
temp = 0;
}
// Use the reverb sound as initial sound for this audio update
- DEBUG_PRINT("- dmem move");
+ DEBUG_PRINT("- dmem move");
aDMEMMove(cmd++, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_LEFT_CH, DEFAULT_LEN_2CH);
// (Hopefully) lower the volume of the wet channels. New reverb will later be mixed into
// these channels.
- DEBUG_PRINT("- set buffer");
+ DEBUG_PRINT("- set buffer");
aSetBuffer(cmd++, 0, 0, 0, DEFAULT_LEN_2CH);
// 0x8000 here is -100%
- DEBUG_PRINT("- mix");
+ DEBUG_PRINT("- mix");
aMix(cmd++, 0, /*gain*/ 0x8000 + gSynthesisReverb.reverbGain, /*in*/ DMEM_ADDR_WET_LEFT_CH,
/*out*/ DMEM_ADDR_WET_LEFT_CH);
- } else {
- DEBUG_PRINT("- w/o reverb downsample");
+ }
+ else
+ {
+ DEBUG_PRINT("- w/o reverb downsample");
// Same as above but upsample the previously downsampled samples used for reverb first
temp = 0; //! jesus christ
t4 = (v1->startPos & 7) * 2;
ra = ALIGN(v1->lengthA + t4, 4);
- DEBUG_PRINT("- set load buffer pair");
+ DEBUG_PRINT("- set load buffer pair");
aSetLoadBufferPair(cmd++, 0, v1->startPos - t4 / 2);
- if (v1->lengthB != 0) {
+ if (v1->lengthB != 0)
+ {
// Ring buffer wrapped
aSetLoadBufferPair(cmd++, ra, 0);
//! We need an empty statement (even an empty ';') here to make the function match (because IDO).
@@ -578,29 +663,33 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI
//! useless assignment.
ra = ra + temp;
}
- DEBUG_PRINT("- set buffer 1");
+ DEBUG_PRINT("- set buffer 1");
aSetBuffer(cmd++, 0, t4 + DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_LEFT_CH, bufLen << 1);
- DEBUG_PRINT("- resample 1");
- aResample(cmd++, gSynthesisReverb.resampleFlags, (u16) gSynthesisReverb.resampleRate, VIRTUAL_TO_PHYSICAL2(gSynthesisReverb.resampleStateLeft));
- DEBUG_PRINT("- set buffer 2");
+ DEBUG_PRINT("- resample 1");
+ aResample(cmd++, gSynthesisReverb.resampleFlags, gSynthesisReverb.resampleRate, VIRTUAL_TO_PHYSICAL2(gSynthesisReverb.resampleStateLeft));
+ DEBUG_PRINT("- set buffer 2");
aSetBuffer(cmd++, 0, t4 + DMEM_ADDR_WET_RIGHT_CH, DMEM_ADDR_RIGHT_CH, bufLen << 1);
- DEBUG_PRINT("- resample 2");
- aResample(cmd++, gSynthesisReverb.resampleFlags, (u16) gSynthesisReverb.resampleRate, VIRTUAL_TO_PHYSICAL2(gSynthesisReverb.resampleStateRight));
- DEBUG_PRINT("- set buffer 3");
+ DEBUG_PRINT("- resample 2");
+ aResample(cmd++, gSynthesisReverb.resampleFlags, gSynthesisReverb.resampleRate, VIRTUAL_TO_PHYSICAL2(gSynthesisReverb.resampleStateRight));
+ DEBUG_PRINT("- set buffer 3");
aSetBuffer(cmd++, 0, 0, 0, DEFAULT_LEN_2CH);
- DEBUG_PRINT("- mix");
+ DEBUG_PRINT("- mix");
aMix(cmd++, 0, /*gain*/ 0x8000 + gSynthesisReverb.reverbGain, /*in*/ DMEM_ADDR_LEFT_CH, /*out*/ DMEM_ADDR_LEFT_CH);
- DEBUG_PRINT("- dmem move");
+ DEBUG_PRINT("- dmem move");
aDMEMMove(cmd++, DMEM_ADDR_LEFT_CH, DMEM_ADDR_WET_LEFT_CH, DEFAULT_LEN_2CH);
}
cmd = synthesis_process_notes(aiBuf, bufLen, cmd);
- if (gReverbDownsampleRate == 1) {
+ if (gReverbDownsampleRate == 1)
+ {
aSetSaveBufferPair(cmd++, 0, v1->lengthA, v1->startPos);
- if (v1->lengthB != 0) {
+ if (v1->lengthB != 0)
+ {
// Ring buffer wrapped
aSetSaveBufferPair(cmd++, v1->lengthA, v1->lengthB, 0);
}
- } else {
+ }
+ else
+ {
// Downsampling is done later by CPU when RSP is done, therefore we need to have double
// buffering. Left and right buffers are adjacent in memory.
aSetBuffer(cmd++, 0, 0, DMEM_ADDR_WET_LEFT_CH, DEFAULT_LEN_2CH);
@@ -614,156 +703,169 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI
#ifdef VERSION_EU
// Processes just one note, not all
-u64 *synthesis_process_note(struct Note *note, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, UNUSED s16 *aiBuf, s32 bufLen, u64 *cmd) {
+u64 *synthesis_process_note(struct Note *note, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, UNUSED s16 *aiBuf, s32 bufLen, u64 *cmd)
+{
UNUSED s32 pad0[3];
#else
-u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
- DEBUG_PRINT("synthesis_process_notes()");
+u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd)
+{
+ DEBUG_PRINT("synthesis_process_notes()");
- s32 noteIndex; // sp174
- struct Note *note; // s7
+ s32 noteIndex; // sp174
+ struct Note *note; // s7
UNUSED u8 pad0[0x08];
-#endif
+ #endif
struct AudioBankSample *audioBookSample; // sp164, sp138
- struct AdpcmLoop *loopInfo; // sp160, sp134
- s16 *curLoadedBook = NULL; // sp154, sp130
-#ifdef VERSION_EU
+ struct AdpcmLoop *loopInfo; // sp160, sp134
+ s16 *curLoadedBook = NULL; // sp154, sp130
+ #ifdef VERSION_EU
UNUSED u8 padEU[0x04];
-#endif
+ #endif
UNUSED u8 pad8[0x04];
-#ifndef VERSION_EU
- u16 resamplingRateFixedPoint; // sp5c, sp11A
-#endif
- s32 noteFinished; // 150 t2, sp124
- s32 restart; // 14c t3, sp120
- s32 flags; // sp148, sp11C
-#ifdef VERSION_EU
- u16 resamplingRateFixedPoint; // sp5c, sp11A
-#endif
- UNUSED u8 pad7[0x0c]; // sp100
+ #ifndef VERSION_EU
+ u16 resamplingRateFixedPoint; // sp5c, sp11A
+ #endif
+ s32 noteFinished; // 150 t2, sp124
+ s32 restart; // 14c t3, sp120
+ s32 flags; // sp148, sp11C
+ #ifdef VERSION_EU
+ u16 resamplingRateFixedPoint; // sp5c, sp11A
+ #endif
+ UNUSED u8 pad7[0x0c]; // sp100
UNUSED s32 tempBufLen;
-#ifdef VERSION_EU
- s32 sp130; //sp128, sp104
+ #ifdef VERSION_EU
+ s32 sp130; //sp128, sp104
UNUSED u32 pad9;
-#else
+ #else
UNUSED u32 pad9;
- s32 sp130; //sp128, sp104
-#endif
+ s32 sp130; //sp128, sp104
+ #endif
s32 nAdpcmSamplesProcessed; // signed required for US
s32 t0;
-#ifdef VERSION_EU
- u8 *sampleAddr; // sp120, spF4
+ #ifdef VERSION_EU
+ u8 *sampleAddr; // sp120, spF4
s32 s6;
-#else
+ #else
s32 s6;
- u8 *sampleAddr; // sp120, spF4
-#endif
+ u8 *sampleAddr; // sp120, spF4
+ #endif
-#ifdef VERSION_EU
+ #ifdef VERSION_EU
s32 samplesLenAdjusted; // 108, spEC
// Might have been used to store (samplesLenFixedPoint >> 0x10), but doing so causes strange
// behavior with the break near the end of the loop, causing US and JP to need a goto instead
UNUSED s32 samplesLenInt;
- s32 endPos; // sp110, spE4
- s32 nSamplesToProcess; // sp10c/a0, spE0
+ s32 endPos; // sp110, spE4
+ s32 nSamplesToProcess; // sp10c/a0, spE0
s32 s2;
-#else
+ #else
// Might have been used to store (samplesLenFixedPoint >> 0x10), but doing so causes strange
// behavior with the break near the end of the loop, causing US and JP to need a goto instead
UNUSED s32 samplesLenInt;
s32 samplesLenAdjusted; // 108
s32 s2;
- s32 endPos; // sp110, spE4
- s32 nSamplesToProcess; // sp10c/a0, spE0
-#endif
+ s32 endPos; // sp110, spE4
+ s32 nSamplesToProcess; // sp10c/a0, spE0
+ #endif
s32 leftRight;
s32 s3;
s32 s5; //s4
- u32 samplesLenFixedPoint; // v1_1
+ u32 samplesLenFixedPoint; // v1_1
s32 nSamplesInThisIteration; // v1_2
u32 a3;
-#ifndef VERSION_EU
+ #ifndef VERSION_EU
s32 t9;
-#endif
+ #endif
u8 *v0_2;
- s32 nParts; // spE8, spBC
- s32 curPart; // spE4, spB8
+ s32 nParts; // spE8, spBC
+ s32 curPart; // spE4, spB8
-#ifndef VERSION_EU
+ #ifndef VERSION_EU
f32 resamplingRate; // f12
-#endif
+ #endif
s32 temp;
-#ifdef VERSION_EU
+ #ifdef VERSION_EU
s32 s5Aligned;
-#endif
- s32 resampledTempLen; // spD8, spAC
+ #endif
+ s32 resampledTempLen; // spD8, spAC
u16 noteSamplesDmemAddrBeforeResampling; // spD6, spAA
- for (noteIndex = 0; noteIndex < gMaxSimultaneousNotes; noteIndex++) {
- DEBUG_PRINT("- for note index %d/%d", noteIndex, gMaxSimultaneousNotes);
+ for (noteIndex = 0; noteIndex < gMaxSimultaneousNotes; noteIndex++)
+ {
+ DEBUG_PRINT("- for note index %d/%d", noteIndex, gMaxSimultaneousNotes);
- DEBUG_PRINT("- getting note");
+ DEBUG_PRINT("- getting note");
note = &gNotes[noteIndex];
//! This function requires note->enabled to be volatile, but it breaks other functions like note_enable.
//! Casting to a struct with just the volatile bitfield works, but there may be a better way to match.
- DEBUG_PRINT("- if note is enabled but not loaded");
- if (((struct vNote *)note)->enabled && IS_BANK_LOAD_COMPLETE(note->bankId) == FALSE) {
- DEBUG_PRINT("- note is enabled but not loaded");
+ DEBUG_PRINT("- if note is enabled but not loaded");
+ if (((struct vNote *)note)->enabled && IS_BANK_LOAD_COMPLETE(note->bankId) == FALSE)
+ {
+ DEBUG_PRINT("- note is enabled but not loaded");
gAudioErrorFlags = (note->bankId << 8) + noteIndex + 0x1000000;
- continue;
- }
+ continue;
+ }
- DEBUG_PRINT("- if note is enabled");
- if (((struct vNote *)note)->enabled) {
- DEBUG_PRINT("$ note is enabled!");
+ DEBUG_PRINT("- if note is enabled");
+ if (((struct vNote *)note)->enabled)
+ {
+ DEBUG_PRINT("$ note is enabled!");
flags = 0;
- DEBUG_PRINT("- if note needs to be init");
- if (note->needsInit == TRUE) {
+ DEBUG_PRINT("- if note needs to be init");
+ if (note->needsInit == TRUE)
+ {
flags = A_INIT;
note->samplePosInt = 0;
note->samplePosFrac = 0;
}
- DEBUG_PRINT("- if note frequency is less than 2");
- if (note->frequency < US_FLOAT(2.0)) {
+ DEBUG_PRINT("- if note frequency is less than 2");
+ if (note->frequency < US_FLOAT(2.0))
+ {
nParts = 1;
- if (note->frequency > US_FLOAT(1.99996)) {
+ if (note->frequency > US_FLOAT(1.99996))
+ {
note->frequency = US_FLOAT(1.99996);
}
resamplingRate = note->frequency;
- } else {
+ }
+ else
+ {
// If frequency is > 2.0, the processing must be split into two parts
nParts = 2;
- if (note->frequency >= US_FLOAT(3.99993)) {
+ if (note->frequency >= US_FLOAT(3.99993))
+ {
note->frequency = US_FLOAT(3.99993);
}
resamplingRate = note->frequency * US_FLOAT(.5);
}
resamplingRateFixedPoint = (u16)(s32)(resamplingRate * 32768.0f);
- samplesLenFixedPoint = note->samplePosFrac + (resamplingRateFixedPoint * bufLen) * 2;
+ samplesLenFixedPoint = note->samplePosFrac + resamplingRateFixedPoint * bufLen * 2;
note->samplePosFrac = samplesLenFixedPoint & 0xFFFF; // 16-bit store, can't reuse
- DEBUG_PRINT("- if note sound is null");
- if (note->sound == NULL) {
+ DEBUG_PRINT("- if note sound is null");
+ if (note->sound == NULL)
+ {
// A wave synthesis note (not ADPCM)
- DEBUG_PRINT("- note is null, do wave synthesis");
+ DEBUG_PRINT("- note is null, do wave synthesis");
cmd = load_wave_samples(cmd, note, samplesLenFixedPoint >> 0x10);
noteSamplesDmemAddrBeforeResampling = DMEM_ADDR_UNCOMPRESSED_NOTE + note->samplePosInt * 2;
- note->samplePosInt += (samplesLenFixedPoint >> 0x10);
+ note->samplePosInt += samplesLenFixedPoint >> 0x10;
flags = 0;
}
- else {
+ else
+ {
// ADPCM note
- DEBUG_PRINT("- @ handle adpcm note");
+ DEBUG_PRINT("- @ handle adpcm note");
audioBookSample = note->sound->sample;
@@ -771,29 +873,36 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
endPos = loopInfo->end;
sampleAddr = audioBookSample->sampleAddr;
resampledTempLen = 0;
- for (curPart = 0; curPart < nParts; curPart++) {
- DEBUG_PRINT("- for part %d", curPart);
+ for (curPart = 0; curPart < nParts; curPart++)
+ {
+ DEBUG_PRINT("- for part %d", curPart);
nAdpcmSamplesProcessed = 0; // s8
- s5 = 0; // s4
+ s5 = 0; // s4
- if (nParts == 1) {
+ if (nParts == 1)
+ {
samplesLenAdjusted = samplesLenFixedPoint >> 0x10;
- } else if ((samplesLenFixedPoint >> 0x10) & 1) {
- samplesLenAdjusted = ((samplesLenFixedPoint >> 0x10) & ~1) + (curPart * 2);
}
- else {
- samplesLenAdjusted = (samplesLenFixedPoint >> 0x10);
+ else if (samplesLenFixedPoint >> 0x10 & 1)
+ {
+ samplesLenAdjusted = (samplesLenFixedPoint >> 0x10 & ~1) + curPart * 2;
+ }
+ else
+ {
+ samplesLenAdjusted = samplesLenFixedPoint >> 0x10;
}
- if (curLoadedBook != audioBookSample->book->book) {
+ if (curLoadedBook != audioBookSample->book->book)
+ {
u32 nEntries; // v1
curLoadedBook = audioBookSample->book->book;
nEntries = audioBookSample->book->order * audioBookSample->book->npredictors;
- DEBUG_PRINT("- loading adpcm");
+ DEBUG_PRINT("- loading adpcm");
aLoadADPCM(cmd++, nEntries * 16, VIRTUAL_TO_PHYSICAL2(curLoadedBook));
}
- while (nAdpcmSamplesProcessed != samplesLenAdjusted) {
+ while (nAdpcmSamplesProcessed != samplesLenAdjusted)
+ {
s32 samplesRemaining; // v1
s32 s0;
@@ -803,65 +912,81 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
s2 = note->samplePosInt & 0xf;
samplesRemaining = endPos - note->samplePosInt;
- if (s2 == 0 && note->restart == FALSE) {
+ if (s2 == 0 && note->restart == FALSE)
+ {
s2 = 16;
}
s6 = 16 - s2; // a1
- if (nSamplesToProcess < samplesRemaining) {
+ if (nSamplesToProcess < samplesRemaining)
+ {
t0 = (nSamplesToProcess - s6 + 0xf) / 16;
s0 = t0 * 16;
s3 = s6 + s0 - nSamplesToProcess;
- } else {
+ }
+ else
+ {
s0 = samplesRemaining + s2 - 0x10;
s3 = 0;
- if (s0 <= 0) {
+ if (s0 <= 0)
+ {
s0 = 0;
s6 = samplesRemaining;
}
t0 = (s0 + 0xf) / 16;
- if (loopInfo->count != 0) {
+ if (loopInfo->count != 0)
+ {
// Loop around and restart
restart = 1;
- } else {
+ }
+ else
+ {
noteFinished = 1;
}
}
- if (t0 != 0) {
+ if (t0 != 0)
+ {
temp = (note->samplePosInt - s2 + 0x10) / 16;
v0_2 = dma_sample_data(
- (uintptr_t) (sampleAddr + temp * 9),
+ (uintptr_t)(sampleAddr + temp * 9),
t0 * 9, flags, ¬e->sampleDmaIndex);
- a3 = (u32)((uintptr_t) v0_2 & 0xf);
+ a3 = (u32)((uintptr_t)v0_2 & 0xf);
aSetBuffer(cmd++, 0, DMEM_ADDR_COMPRESSED_ADPCM_DATA, 0, t0 * 9 + a3);
aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(v0_2 - a3));
- } else {
+ }
+ else
+ {
s0 = 0;
a3 = 0;
}
- DEBUG_PRINT("- if not note restart");
- if (note->restart != FALSE) {
+ DEBUG_PRINT("- if not note restart");
+ if (note->restart != FALSE)
+ {
aSetLoop(cmd++, VIRTUAL_TO_PHYSICAL2(audioBookSample->loop->state));
flags = A_LOOP; // = 2
note->restart = FALSE;
}
nSamplesInThisIteration = s0 + s6 - s3;
- if (nAdpcmSamplesProcessed == 0) {
+ if (nAdpcmSamplesProcessed == 0)
+ {
aSetBuffer(cmd++, 0, DMEM_ADDR_COMPRESSED_ADPCM_DATA + a3, DMEM_ADDR_UNCOMPRESSED_NOTE, s0 * 2);
aADPCMdec(cmd++, flags, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->adpcmdecState));
sp130 = s2 * 2;
- } else {
+ }
+ else
+ {
aSetBuffer(cmd++, 0, DMEM_ADDR_COMPRESSED_ADPCM_DATA + a3, DMEM_ADDR_UNCOMPRESSED_NOTE + ALIGN(s5, 5), s0 * 2);
aADPCMdec(cmd++, flags, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->adpcmdecState));
- aDMEMMove(cmd++, DMEM_ADDR_UNCOMPRESSED_NOTE + ALIGN(s5, 5) + (s2 * 2), DMEM_ADDR_UNCOMPRESSED_NOTE + s5, (nSamplesInThisIteration) * 2);
+ aDMEMMove(cmd++, DMEM_ADDR_UNCOMPRESSED_NOTE + ALIGN(s5, 5) + s2 * 2, DMEM_ADDR_UNCOMPRESSED_NOTE + s5, nSamplesInThisIteration * 2);
}
nAdpcmSamplesProcessed += nSamplesInThisIteration;
- switch (flags) {
+ switch (flags)
+ {
case A_INIT: // = 1
sp130 = 0;
s5 = s0 * 2 + s5;
@@ -872,17 +997,21 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
break;
default:
- if (s5 != 0) {
+ if (s5 != 0)
+ {
s5 = nSamplesInThisIteration * 2 + s5;
- } else {
+ }
+ else
+ {
s5 = (s2 + nSamplesInThisIteration) * 2;
}
break;
}
flags = 0;
- DEBUG_PRINT("- if note finished");
- if (noteFinished) {
+ DEBUG_PRINT("- if note finished");
+ if (noteFinished)
+ {
aClearBuffer(cmd++, DMEM_ADDR_UNCOMPRESSED_NOTE + s5,
(samplesLenAdjusted - nAdpcmSamplesProcessed) * 2);
note->samplePosInt = 0;
@@ -891,28 +1020,34 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
break;
}
- DEBUG_PRINT("- if restart");
- if (restart) {
+ DEBUG_PRINT("- if restart");
+ if (restart)
+ {
note->restart = TRUE;
note->samplePosInt = loopInfo->start;
- } else {
+ }
+ else
+ {
note->samplePosInt += nSamplesToProcess;
}
}
- switch (nParts) {
+ switch (nParts)
+ {
case 1:
noteSamplesDmemAddrBeforeResampling = DMEM_ADDR_UNCOMPRESSED_NOTE + sp130;
break;
case 2:
- switch (curPart) {
+ switch (curPart)
+ {
case 0:
aSetBuffer(cmd++, 0, DMEM_ADDR_UNCOMPRESSED_NOTE + sp130, DMEM_ADDR_RESAMPLED, samplesLenAdjusted + 4);
aResample(cmd++, A_INIT, 0xff60, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->dummyResampleState));
resampledTempLen = samplesLenAdjusted + 4;
noteSamplesDmemAddrBeforeResampling = DMEM_ADDR_RESAMPLED + 4;
- if (note->finished != FALSE) {
+ if (note->finished != FALSE)
+ {
aClearBuffer(cmd++, DMEM_ADDR_RESAMPLED + resampledTempLen, samplesLenAdjusted + 0x10);
}
break;
@@ -931,7 +1066,8 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
}
}
- if (note->finished != FALSE) {
+ if (note->finished != FALSE)
+ {
break;
}
}
@@ -939,7 +1075,8 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
flags = 0;
- if (note->needsInit == TRUE) {
+ if (note->needsInit == TRUE)
+ {
flags = A_INIT;
note->needsInit = FALSE;
}
@@ -947,65 +1084,77 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
cmd = final_resample(cmd, note, bufLen * 2, resamplingRateFixedPoint,
noteSamplesDmemAddrBeforeResampling, flags);
- if (note->headsetPanRight != 0 || note->prevHeadsetPanRight != 0) {
+ if (note->headsetPanRight != 0 || note->prevHeadsetPanRight != 0)
+ {
leftRight = 1;
- } else if (note->headsetPanLeft != 0 || note->prevHeadsetPanLeft != 0) {
+ }
+ else if (note->headsetPanLeft != 0 || note->prevHeadsetPanLeft != 0)
+ {
leftRight = 2;
- } else {
+ }
+ else
+ {
leftRight = 0;
}
cmd = process_envelope(cmd, note, bufLen, 0, leftRight, flags);
- if (note->usesHeadsetPanEffects) {
+ if (note->usesHeadsetPanEffects)
+ {
cmd = note_apply_headset_pan_effects(cmd, note, bufLen * 2, flags, leftRight);
}
}
}
- DEBUG_PRINT("- done handling notes");
+ DEBUG_PRINT("- done handling notes");
- DEBUG_PRINT("- setting buffer 1");
+ DEBUG_PRINT("- setting buffer 1");
t9 = bufLen * 2;
aSetBuffer(cmd++, 0, 0, DMEM_ADDR_TEMP, t9);
- DEBUG_PRINT("- interleaving");
+ DEBUG_PRINT("- interleaving");
aInterleave(cmd++, DMEM_ADDR_LEFT_CH, DMEM_ADDR_RIGHT_CH);
t9 *= 2;
- DEBUG_PRINT("- setting buffer 2");
+ DEBUG_PRINT("- setting buffer 2");
aSetBuffer(cmd++, 0, 0, DMEM_ADDR_TEMP, t9);
- DEBUG_PRINT("- saving buffer");
+ DEBUG_PRINT("- saving buffer");
aSaveBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(aiBuf));
- DEBUG_PRINT("- returning from process notes");
+ DEBUG_PRINT("- returning from process notes");
return cmd;
}
-u64 *load_wave_samples(u64 *cmd, struct Note *note, s32 nSamplesToLoad) {
+u64 *load_wave_samples(u64 *cmd, struct Note *note, s32 nSamplesToLoad)
+{
s32 a3;
s32 i;
aSetBuffer(cmd++, /*flags*/ 0, /*dmemin*/ DMEM_ADDR_UNCOMPRESSED_NOTE, /*dmemout*/ 0,
/*count*/ sizeof(note->synthesisBuffers->samples));
aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->samples));
- note->samplePosInt &= (note->sampleCount - 1);
+ note->samplePosInt &= note->sampleCount - 1;
a3 = 64 - note->samplePosInt;
- if (a3 < nSamplesToLoad) {
- for (i = 0; i <= (nSamplesToLoad - a3 + 63) / 64 - 1; i++) {
+ if (a3 < nSamplesToLoad)
+ {
+ for (i = 0; i <= (nSamplesToLoad - a3 + 63) / 64 - 1; i++)
+ {
aDMEMMove(cmd++, /*dmemin*/ DMEM_ADDR_UNCOMPRESSED_NOTE, /*dmemout*/ DMEM_ADDR_UNCOMPRESSED_NOTE + (1 + i) * sizeof(note->synthesisBuffers->samples), /*count*/ sizeof(note->synthesisBuffers->samples));
}
}
return cmd;
}
-u64 *final_resample(u64 *cmd, struct Note *note, s32 count, u16 pitch, u16 dmemIn, u32 flags) {
+u64 *final_resample(u64 *cmd, struct Note *note, s32 count, u16 pitch, u16 dmemIn, u32 flags)
+{
aSetBuffer(cmd++, /*flags*/ 0, dmemIn, /*dmemout*/ DMEM_ADDR_TEMP, count);
aResample(cmd++, flags, pitch, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->finalResampleState));
return cmd;
}
#ifndef VERSION_EU
-u64 *process_envelope(u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf, s32 headsetPanSettings,
- UNUSED u32 flags) {
+u64 *process_envelope(
+ u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf, s32 headsetPanSettings,
+ UNUSED u32 flags)
+{
UNUSED u8 pad[16];
struct VolumeChange vol;
vol.sourceLeft = note->curVolLeft;
@@ -1017,46 +1166,53 @@ u64 *process_envelope(u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf, s32
return process_envelope_inner(cmd, note, nSamples, inBuf, headsetPanSettings, &vol);
}
-u64 *process_envelope_inner(u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf,
- s32 headsetPanSettings, struct VolumeChange *vol) {
+u64 *process_envelope_inner(
+ u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf,
+ s32 headsetPanSettings, struct VolumeChange *vol)
+{
UNUSED u8 pad[3];
u8 mixerFlags;
UNUSED u8 pad2[8];
s32 rampLeft, rampRight;
-#elif defined(VERSION_EU)
-u64 *process_envelope(u64 *cmd, struct NoteSubEu *note, struct NoteSynthesisState *synthesisState, s32 nSamples, u16 inBuf, s32 headsetPanSettings, UNUSED u32 flags) {
- UNUSED u8 pad1[20];
- u16 sourceRight;
- u16 sourceLeft;
- UNUSED u8 pad2[4];
- u16 targetLeft;
- u16 targetRight;
- s32 mixerFlags;
- s32 rampLeft;
- s32 rampRight;
+ #elif defined(VERSION_EU)
+ u64 *process_envelope(u64 *cmd, struct NoteSubEu *note, struct NoteSynthesisState *synthesisState, s32 nSamples, u16 inBuf, s32 headsetPanSettings, UNUSED u32 flags)
+ {
+ UNUSED u8 pad1[20];
+ u16 sourceRight;
+ u16 sourceLeft;
+ UNUSED u8 pad2[4];
+ u16 targetLeft;
+ u16 targetRight;
+ s32 mixerFlags;
+ s32 rampLeft;
+ s32 rampRight;
- sourceLeft = synthesisState->curVolLeft;
- sourceRight = synthesisState->curVolRight;
- targetLeft = (note->targetVolLeft << 5);
- targetRight = (note->targetVolRight << 5);
- if (targetLeft == 0) {
- targetLeft++;
- }
- if (targetRight == 0) {
- targetRight++;
- }
- synthesisState->curVolLeft = targetLeft;
- synthesisState->curVolRight = targetRight;
-#endif
+ sourceLeft = synthesisState->curVolLeft;
+ sourceRight = synthesisState->curVolRight;
+ targetLeft = (note->targetVolLeft << 5);
+ targetRight = (note->targetVolRight << 5);
+ if (targetLeft == 0)
+ {
+ targetLeft++;
+ }
+ if (targetRight == 0)
+ {
+ targetRight++;
+ }
+ synthesisState->curVolLeft = targetLeft;
+ synthesisState->curVolRight = targetRight;
+ #endif
// For aEnvMixer, five buffers and count are set using aSetBuffer.
// in, dry left, count without A_AUX flag.
// dry right, wet left, wet right with A_AUX flag.
- if (note->usesHeadsetPanEffects) {
+ if (note->usesHeadsetPanEffects)
+ {
aClearBuffer(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, DEFAULT_LEN_1CH);
- switch (headsetPanSettings) {
+ switch (headsetPanSettings)
+ {
case 1:
aSetBuffer(cmd++, 0, inBuf, DMEM_ADDR_NOTE_PAN_TEMP, nSamples * 2);
aSetBuffer(cmd++, A_AUX, DMEM_ADDR_RIGHT_CH, DMEM_ADDR_WET_LEFT_CH,
@@ -1073,94 +1229,113 @@ u64 *process_envelope(u64 *cmd, struct NoteSubEu *note, struct NoteSynthesisStat
DMEM_ADDR_WET_RIGHT_CH);
break;
}
- } else {
+ }
+ else
+ {
// It's a bit unclear what the "stereo strong" concept does.
// Instead of mixing the opposite channel to the normal buffers, the sound is first
// mixed into a temporary buffer and then subtracted from the normal buffer.
- if (note->stereoStrongRight) {
+ if (note->stereoStrongRight)
+ {
aClearBuffer(cmd++, DMEM_ADDR_STEREO_STRONG_TEMP_DRY, DEFAULT_LEN_2CH);
aSetBuffer(cmd++, 0, inBuf, DMEM_ADDR_STEREO_STRONG_TEMP_DRY, nSamples * 2);
aSetBuffer(cmd++, A_AUX, DMEM_ADDR_RIGHT_CH, DMEM_ADDR_STEREO_STRONG_TEMP_WET,
DMEM_ADDR_WET_RIGHT_CH);
- } else if (note->stereoStrongLeft) {
+ }
+ else if (note->stereoStrongLeft)
+ {
aClearBuffer(cmd++, DMEM_ADDR_STEREO_STRONG_TEMP_DRY, DEFAULT_LEN_2CH);
aSetBuffer(cmd++, 0, inBuf, DMEM_ADDR_LEFT_CH, nSamples * 2);
aSetBuffer(cmd++, A_AUX, DMEM_ADDR_STEREO_STRONG_TEMP_DRY, DMEM_ADDR_WET_LEFT_CH,
DMEM_ADDR_STEREO_STRONG_TEMP_WET);
- } else {
+ }
+ else
+ {
aSetBuffer(cmd++, 0, inBuf, DMEM_ADDR_LEFT_CH, nSamples * 2);
aSetBuffer(cmd++, A_AUX, DMEM_ADDR_RIGHT_CH, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_WET_RIGHT_CH);
}
}
-#ifdef VERSION_EU
+ #ifdef VERSION_EU
if (targetLeft == sourceLeft && targetRight == sourceRight && !note->envMixerNeedsInit) {
-#else
+ #else
if (vol->targetLeft == vol->sourceLeft && vol->targetRight == vol->sourceRight
- && !note->envMixerNeedsInit) {
-#endif
+ && !note->envMixerNeedsInit)
+ {
+ #endif
mixerFlags = A_CONTINUE;
- } else {
+ }
+ else
+ {
mixerFlags = A_INIT;
-#ifdef VERSION_EU
+ #ifdef VERSION_EU
rampLeft = gCurrentLeftVolRamping[targetLeft >> 5] * gCurrentRightVolRamping[sourceLeft >> 5];
rampRight = gCurrentLeftVolRamping[targetRight >> 5] * gCurrentRightVolRamping[sourceRight >> 5];
-#else
+ #else
rampLeft = get_volume_ramping(vol->sourceLeft, vol->targetLeft, nSamples);
rampRight = get_volume_ramping(vol->sourceRight, vol->targetRight, nSamples);
-#endif
+ #endif
// The operation's parameters change meanings depending on flags
-#ifdef VERSION_EU
+ #ifdef VERSION_EU
aSetVolume(cmd++, A_VOL | A_LEFT, sourceLeft, 0, 0);
aSetVolume(cmd++, A_VOL | A_RIGHT, sourceRight, 0, 0);
aSetVolume32(cmd++, A_RATE | A_LEFT, targetLeft, rampLeft);
aSetVolume32(cmd++, A_RATE | A_RIGHT, targetRight, rampRight);
aSetVolume(cmd++, A_AUX, gVolume, 0, note->reverbVol << 8);
-#else
+ #else
aSetVolume(cmd++, A_VOL | A_LEFT, vol->sourceLeft, 0, 0);
aSetVolume(cmd++, A_VOL | A_RIGHT, vol->sourceRight, 0, 0);
aSetVolume32(cmd++, A_RATE | A_LEFT, vol->targetLeft, rampLeft);
aSetVolume32(cmd++, A_RATE | A_RIGHT, vol->targetRight, rampRight);
aSetVolume(cmd++, A_AUX, gVolume, 0, note->reverbVolShifted);
-#endif
+ #endif
}
-#ifdef VERSION_EU
- if (gUseReverb && note->reverbVol != 0) {
+ #ifdef VERSION_EU
+ if (gUseReverb &¬e->reverbVol != 0) {
aEnvMixer(cmd++, mixerFlags | A_AUX,
VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->mixEnvelopeState));
-#else
- if (gSynthesisReverb.useReverb && note->reverbVol != 0) {
+ #else
+ if (gSynthesisReverb.useReverb && note->reverbVol != 0)
+ {
aEnvMixer(cmd++, mixerFlags | A_AUX,
VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->mixEnvelopeState));
-#endif
- if (note->stereoStrongRight) {
+ #endif
+ if (note->stereoStrongRight)
+ {
aSetBuffer(cmd++, 0, 0, 0, nSamples * 2);
// 0x8000 is -100%, so subtract sound instead of adding...
aMix(cmd++, 0, /*gain*/ 0x8000, /*in*/ DMEM_ADDR_STEREO_STRONG_TEMP_DRY,
/*out*/ DMEM_ADDR_LEFT_CH);
aMix(cmd++, 0, /*gain*/ 0x8000, /*in*/ DMEM_ADDR_STEREO_STRONG_TEMP_WET,
/*out*/ DMEM_ADDR_WET_LEFT_CH);
- } else if (note->stereoStrongLeft) {
+ }
+ else if (note->stereoStrongLeft)
+ {
aSetBuffer(cmd++, 0, 0, 0, nSamples * 2);
aMix(cmd++, 0, /*gain*/ 0x8000, /*in*/ DMEM_ADDR_STEREO_STRONG_TEMP_DRY,
/*out*/ DMEM_ADDR_RIGHT_CH);
aMix(cmd++, 0, /*gain*/ 0x8000, /*in*/ DMEM_ADDR_STEREO_STRONG_TEMP_WET,
/*out*/ DMEM_ADDR_WET_RIGHT_CH);
}
- } else {
-#ifdef VERSION_EU
+ }
+ else
+ {
+ #ifdef VERSION_EU
aEnvMixer(cmd++, mixerFlags, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->mixEnvelopeState));
-#else
+ #else
aEnvMixer(cmd++, mixerFlags, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->mixEnvelopeState));
-#endif
- if (note->stereoStrongRight) {
+ #endif
+ if (note->stereoStrongRight)
+ {
aSetBuffer(cmd++, 0, 0, 0, nSamples * 2);
aMix(cmd++, 0, /*gain*/ 0x8000, /*in*/ DMEM_ADDR_STEREO_STRONG_TEMP_DRY,
/*out*/ DMEM_ADDR_LEFT_CH);
- } else if (note->stereoStrongLeft) {
+ }
+ else if (note->stereoStrongLeft)
+ {
aSetBuffer(cmd++, 0, 0, 0, nSamples * 2);
aMix(cmd++, 0, /*gain*/ 0x8000, /*in*/ DMEM_ADDR_STEREO_STRONG_TEMP_DRY,
/*out*/ DMEM_ADDR_RIGHT_CH);
@@ -1170,40 +1345,45 @@ u64 *process_envelope(u64 *cmd, struct NoteSubEu *note, struct NoteSynthesisStat
}
#ifdef VERSION_EU
-u64 *note_apply_headset_pan_effects(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *note, s32 bufLen, s32 flags, s32 leftRight) {
+u64 *note_apply_headset_pan_effects(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *note, s32 bufLen, s32 flags, s32 leftRight)
+{
+
+
#else
-u64 *note_apply_headset_pan_effects(u64 *cmd, struct Note *note, s32 bufLen, s32 flags, s32 leftRight) {
-#endif
+u64 *note_apply_headset_pan_effects(u64 *cmd, struct Note *note, s32 bufLen, s32 flags, s32 leftRight)
+{
+ #endif
u16 dest;
u16 pitch;
-#ifdef VERSION_EU
+ #ifdef VERSION_EU
u8 prevPanShift;
u8 panShift;
UNUSED u8 unkDebug;
-#else
+ #else
u16 prevPanShift;
u16 panShift;
-#endif
+ #endif
- switch (leftRight) {
+ switch (leftRight)
+ {
case 1:
dest = DMEM_ADDR_LEFT_CH;
-#ifdef VERSION_EU
+ #ifdef VERSION_EU
panShift = noteSubEu->headsetPanRight;
-#else
+ #else
panShift = note->headsetPanRight;
-#endif
+ #endif
note->prevHeadsetPanLeft = 0;
prevPanShift = note->prevHeadsetPanRight;
note->prevHeadsetPanRight = panShift;
break;
case 2:
dest = DMEM_ADDR_RIGHT_CH;
-#ifdef VERSION_EU
+ #ifdef VERSION_EU
panShift = noteSubEu->headsetPanLeft;
-#else
+ #else
panShift = note->headsetPanLeft;
-#endif
+ #endif
note->prevHeadsetPanRight = 0;
prevPanShift = note->prevHeadsetPanLeft;
@@ -1213,9 +1393,11 @@ u64 *note_apply_headset_pan_effects(u64 *cmd, struct Note *note, s32 bufLen, s32
return cmd;
}
- if (flags != 1) { // A_INIT?
+ if (flags != 1)
+ { // A_INIT?
// Slightly adjust the sample rate in order to fit a change in pan shift
- if (prevPanShift == 0) {
+ if (prevPanShift == 0)
+ {
// Kind of a hack that moves the first samples into the resample state
aDMEMMove(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, DMEM_ADDR_TEMP, 8);
aClearBuffer(cmd++, 8, 8); // Set pitch accumulator to 0 in the resample state
@@ -1225,45 +1407,58 @@ u64 *note_apply_headset_pan_effects(u64 *cmd, struct Note *note, s32 bufLen, s32
aSetBuffer(cmd++, 0, 0, DMEM_ADDR_TEMP, 32);
aSaveBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->panResampleState));
-#ifdef VERSION_EU
+ #ifdef VERSION_EU
pitch = (bufLen << 0xf) / (bufLen + panShift - prevPanShift + 8);
- if (pitch) {
+ if (pitch)
+ {
}
-#else
+ #else
pitch = (bufLen << 0xf) / (panShift + bufLen - prevPanShift + 8);
-#endif
+ #endif
aSetBuffer(cmd++, 0, DMEM_ADDR_NOTE_PAN_TEMP + 8, DMEM_ADDR_TEMP, panShift + bufLen - prevPanShift);
aResample(cmd++, 0, pitch, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->panResampleState));
- } else {
- if (panShift == 0) {
+ }
+ else
+ {
+ if (panShift == 0)
+ {
pitch = (bufLen << 0xf) / (bufLen - prevPanShift - 4);
- } else {
+ }
+ else
+ {
pitch = (bufLen << 0xf) / (bufLen + panShift - prevPanShift);
}
-#if defined(VERSION_EU) && !defined(AVOID_UB)
- if (unkDebug) { // UB
+ #if defined(VERSION_EU) && !defined(AVOID_UB)
+ if (unkDebug)
+ { // UB
}
-#endif
+ #endif
aSetBuffer(cmd++, 0, DMEM_ADDR_NOTE_PAN_TEMP, DMEM_ADDR_TEMP, panShift + bufLen - prevPanShift);
aResample(cmd++, 0, pitch, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->panResampleState));
}
- if (prevPanShift != 0) {
+ if (prevPanShift != 0)
+ {
aSetBuffer(cmd++, 0, DMEM_ADDR_NOTE_PAN_TEMP, 0, prevPanShift);
aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->panSamplesBuffer));
aDMEMMove(cmd++, DMEM_ADDR_TEMP, DMEM_ADDR_NOTE_PAN_TEMP + prevPanShift, panShift + bufLen - prevPanShift);
- } else {
+ }
+ else
+ {
aDMEMMove(cmd++, DMEM_ADDR_TEMP, DMEM_ADDR_NOTE_PAN_TEMP, panShift + bufLen - prevPanShift);
}
- } else {
+ }
+ else
+ {
// Just shift right
aDMEMMove(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, DMEM_ADDR_TEMP, bufLen);
aDMEMMove(cmd++, DMEM_ADDR_TEMP, DMEM_ADDR_NOTE_PAN_TEMP + panShift, bufLen);
aClearBuffer(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, panShift);
}
- if (panShift) {
+ if (panShift)
+ {
// Save excessive samples for next iteration
aSetBuffer(cmd++, 0, 0, DMEM_ADDR_NOTE_PAN_TEMP + bufLen, panShift);
aSaveBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->panSamplesBuffer));
@@ -1278,7 +1473,8 @@ u64 *note_apply_headset_pan_effects(u64 *cmd, struct Note *note, s32 bufLen, s32
#ifndef VERSION_EU
// Moved to playback.c in EU
-void note_init_volume(struct Note *note) {
+void note_init_volume(struct Note *note)
+{
note->targetVolLeft = 0;
note->targetVolRight = 0;
note->reverbVol = 0;
@@ -1289,7 +1485,8 @@ void note_init_volume(struct Note *note) {
note->frequency = 0.0f;
}
-void note_set_vel_pan_reverb(struct Note *note, f32 velocity, f32 pan, u8 reverbVol) {
+void note_set_vel_pan_reverb(struct Note *note, f32 velocity, f32 pan, u8 reverbVol)
+{
s32 panIndex;
f32 volLeft;
f32 volRight;
@@ -1298,17 +1495,21 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, f32 pan, u8 reverb
// in external.c. An out-of-bounds read by itself doesn't crash, but if the
// resulting value is a nan or denormal, performing arithmetic on it crashes
// on console.
-#ifdef VERSION_JP
+ #ifdef VERSION_JP
panIndex = MIN((s32)(pan * 127.5), 127);
-#else
+ #else
panIndex = (s32)(pan * 127.5f) & 127;
-#endif
- if (note->stereoHeadsetEffects && gSoundMode == SOUND_MODE_HEADSET) {
+ #endif
+ if (note->stereoHeadsetEffects && gSoundMode == SOUND_MODE_HEADSET)
+ {
s8 smallPanIndex;
s8 temp = (s8)(pan * 10.0f);
- if (temp < 9) {
+ if (temp < 9)
+ {
smallPanIndex = temp;
- } else {
+ }
+ else
+ {
smallPanIndex = 9;
}
note->headsetPanLeft = gHeadsetPanQuantization[smallPanIndex];
@@ -1318,7 +1519,9 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, f32 pan, u8 reverb
note->usesHeadsetPanEffects = TRUE;
volLeft = gHeadsetPanVolume[panIndex];
volRight = gHeadsetPanVolume[127 - panIndex];
- } else if (note->stereoHeadsetEffects && gSoundMode == SOUND_MODE_STEREO) {
+ }
+ else if (note->stereoHeadsetEffects && gSoundMode == SOUND_MODE_STEREO)
+ {
u8 strongLeft;
u8 strongRight;
strongLeft = FALSE;
@@ -1328,56 +1531,72 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, f32 pan, u8 reverb
note->usesHeadsetPanEffects = FALSE;
volLeft = gStereoPanVolume[panIndex];
volRight = gStereoPanVolume[127 - panIndex];
- if (panIndex < 0x20) {
+ if (panIndex < 0x20)
+ {
strongLeft = TRUE;
- } else if (panIndex > 0x60) {
+ }
+ else if (panIndex > 0x60)
+ {
strongRight = TRUE;
}
note->stereoStrongRight = strongRight;
note->stereoStrongLeft = strongLeft;
- } else if (gSoundMode == SOUND_MODE_MONO) {
+ }
+ else if (gSoundMode == SOUND_MODE_MONO)
+ {
volLeft = .707f;
volRight = .707f;
- } else {
+ }
+ else
+ {
volLeft = gDefaultPanVolume[panIndex];
volRight = gDefaultPanVolume[127 - panIndex];
}
- if (velocity < 0) {
+ if (velocity < 0)
+ {
velocity = 0;
}
-#ifdef VERSION_JP
+ #ifdef VERSION_JP
note->targetVolLeft = (u16)(velocity * volLeft) & ~0x80FF; // 0x7F00, but that doesn't match
note->targetVolRight = (u16)(velocity * volRight) & ~0x80FF;
-#else
+ #else
note->targetVolLeft = (u16)(s32)(velocity * volLeft) & ~0x80FF;
note->targetVolRight = (u16)(s32)(velocity * volRight) & ~0x80FF;
-#endif
- if (note->targetVolLeft == 0) {
+ #endif
+ if (note->targetVolLeft == 0)
+ {
note->targetVolLeft++;
}
- if (note->targetVolRight == 0) {
+ if (note->targetVolRight == 0)
+ {
note->targetVolRight++;
}
- if (note->reverbVol != reverbVol) {
+ if (note->reverbVol != reverbVol)
+ {
note->reverbVol = reverbVol;
note->reverbVolShifted = reverbVol << 8;
note->envMixerNeedsInit = TRUE;
return;
}
- if (note->needsInit) {
+ if (note->needsInit)
+ {
note->envMixerNeedsInit = TRUE;
- } else {
+ }
+ else
+ {
note->envMixerNeedsInit = FALSE;
}
}
-void note_set_frequency(struct Note *note, f32 frequency) {
+void note_set_frequency(struct Note *note, f32 frequency)
+{
note->frequency = frequency;
}
-void note_enable(struct Note *note) {
+void note_enable(struct Note *note)
+{
note->enabled = TRUE;
note->needsInit = TRUE;
note->restart = FALSE;
@@ -1391,10 +1610,14 @@ void note_enable(struct Note *note) {
note->prevHeadsetPanLeft = 0;
}
-void note_disable(struct Note *note) {
- if (note->needsInit == TRUE) {
+void note_disable(struct Note *note)
+{
+ if (note->needsInit == TRUE)
+ {
note->needsInit = FALSE;
- } else {
+ }
+ else
+ {
note_set_vel_pan_reverb(note, 0, .5, 0);
}
note->priority = NOTE_PRIORITY_DISABLED;
diff --git a/src/decomp/audio/synthesis.h b/src/decomp/audio/synthesis.h
index 9ca8643..56b0c7b 100644
--- a/src/decomp/audio/synthesis.h
+++ b/src/decomp/audio/synthesis.h
@@ -30,46 +30,62 @@ struct ReverbRingBufferItem
struct SynthesisReverb
{
- /*0x00, 0x00, 0x00*/ u8 resampleFlags;
- /*0x01, 0x01, 0x01*/ u8 useReverb;
- /*0x02, 0x02, 0x02*/ u8 framesLeftToIgnore;
- /*0x03, 0x03, 0x03*/ u8 curFrame;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+ /*0x00, 0x00, 0x00*/
+ u8 resampleFlags;
+ /*0x01, 0x01, 0x01*/
+ u8 useReverb;
+ /*0x02, 0x02, 0x02*/
+ u8 framesLeftToIgnore;
+ /*0x03, 0x03, 0x03*/
+ u8 curFrame;
+ #if defined(VERSION_EU) || defined(VERSION_SH)
/* 0x04, 0x04*/ u8 downsampleRate;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
/* 0x05*/ s8 unk5;
-#endif
+ #endif
/* 0x06, 0x06*/ u16 windowSize; // same as bufSizePerChannel
-#endif
-#ifdef VERSION_SH
+ #endif
+ #ifdef VERSION_SH
/* 0x08*/ u16 unk08;
-#endif
- /*0x04, 0x08, 0x0A*/ u16 reverbGain;
- /*0x06, 0x0A, 0x0C*/ u16 resampleRate;
-#ifdef VERSION_SH
+ #endif
+ /*0x04, 0x08, 0x0A*/
+ u16 reverbGain;
+ /*0x06, 0x0A, 0x0C*/
+ u16 resampleRate;
+ #ifdef VERSION_SH
/* 0x0E*/ u16 panRight;
/* 0x10*/ u16 panLeft;
-#endif
- /*0x08, 0x0C, 0x14*/ s32 nextRingBufferPos;
- /*0x0C, 0x10, 0x18*/ s32 unkC; // never read
- /*0x10, 0x14, 0x1C*/ s32 bufSizePerChannel;
+ #endif
+ /*0x08, 0x0C, 0x14*/
+ s32 nextRingBufferPos;
+ /*0x0C, 0x10, 0x18*/
+ s32 unkC; // never read
+ /*0x10, 0x14, 0x1C*/
+ s32 bufSizePerChannel;
+
struct
{
s16 *left;
s16 *right;
} ringBuffer;
- /*0x1C, 0x20, 0x28*/ s16 *resampleStateLeft;
- /*0x20, 0x24, 0x2C*/ s16 *resampleStateRight;
- /*0x24, 0x28, 0x30*/ s16 *unk24; // never read
- /*0x28, 0x2C, 0x34*/ s16 *unk28; // never read
- /*0x2C, 0x30, 0x38*/ struct ReverbRingBufferItem items[2][MAX_UPDATES_PER_FRAME];
-#if defined(VERSION_EU) || defined(VERSION_SH)
+
+ /*0x1C, 0x20, 0x28*/
+ s16 *resampleStateLeft;
+ /*0x20, 0x24, 0x2C*/
+ s16 *resampleStateRight;
+ /*0x24, 0x28, 0x30*/
+ s16 *unk24; // never read
+ /*0x28, 0x2C, 0x34*/
+ s16 *unk28; // never read
+ /*0x2C, 0x30, 0x38*/
+ struct ReverbRingBufferItem items[2][MAX_UPDATES_PER_FRAME];
+ #if defined(VERSION_EU) || defined(VERSION_SH)
// Only used in sh:
/* 0x100*/ s16 *unk100;
/* 0x104*/ s16 *unk104;
/* 0x108*/ s16 *unk108;
/* 0x10C*/ s16 *unk10C;
-#endif
+ #endif
}; // 0xCC <= size <= 0x100
#if defined(VERSION_EU) || defined(VERSION_SH)
extern struct SynthesisReverb gSynthesisReverbs[4];
diff --git a/src/decomp/audio/synthesis_sh.c b/src/decomp/audio/synthesis_sh.c
index 706d5d8..e3064fe 100644
--- a/src/decomp/audio/synthesis_sh.c
+++ b/src/decomp/audio/synthesis_sh.c
@@ -39,7 +39,8 @@
#define ALIGN(val, amnt) (((val) + (1 << amnt) - 1) & ~((1 << amnt) - 1))
-struct VolumeChange {
+struct VolumeChange
+{
u16 sourceLeft;
u16 sourceRight;
u16 targetLeft;
@@ -65,7 +66,8 @@ struct NoteSubEu *gNoteSubsEu;
// Equivalent functionality as the US/JP version,
// just that the reverb structure is chosen from an array with index
// Identical in EU.
-void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex) {
+void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex)
+{
struct ReverbRingBufferItem *item;
struct SynthesisReverb *reverb = &gSynthesisReverbs[reverbIndex];
s32 srcPos;
@@ -73,8 +75,10 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex)
s32 nSamples;
s32 excessiveSamples;
s32 UNUSED pad[3];
- if (reverb->downsampleRate != 1) {
- if (reverb->framesLeftToIgnore == 0) {
+ if (reverb->downsampleRate != 1)
+ {
+ if (reverb->framesLeftToIgnore == 0)
+ {
// Now that the RSP has finished, downsample the samples produced two frames ago by skipping
// samples.
item = &reverb->items[reverb->curFrame][updateIndex];
@@ -83,13 +87,15 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex)
osInvalDCache(item->toDownsampleLeft, DEFAULT_LEN_2CH);
for (srcPos = 0, dstPos = 0; dstPos < item->lengthA / 2;
- srcPos += reverb->downsampleRate, dstPos++) {
+ srcPos += reverb->downsampleRate, dstPos++)
+ {
reverb->ringBuffer.left[item->startPos + dstPos] =
- item->toDownsampleLeft[srcPos];
+ item->toDownsampleLeft[srcPos];
reverb->ringBuffer.right[item->startPos + dstPos] =
- item->toDownsampleRight[srcPos];
+ item->toDownsampleRight[srcPos];
}
- for (dstPos = 0; dstPos < item->lengthB / 2; srcPos += reverb->downsampleRate, dstPos++) {
+ for (dstPos = 0; dstPos < item->lengthB / 2; srcPos += reverb->downsampleRate, dstPos++)
+ {
reverb->ringBuffer.left[dstPos] = item->toDownsampleLeft[srcPos];
reverb->ringBuffer.right[dstPos] = item->toDownsampleRight[srcPos];
}
@@ -99,13 +105,16 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex)
item = &reverb->items[reverb->curFrame][updateIndex];
nSamples = chunkLen / reverb->downsampleRate;
excessiveSamples = (nSamples + reverb->nextRingBufferPos) - reverb->bufSizePerChannel;
- if (excessiveSamples < 0) {
+ if (excessiveSamples < 0)
+ {
// There is space in the ring buffer before it wraps around
item->lengthA = nSamples * 2;
item->lengthB = 0;
- item->startPos = (s32) reverb->nextRingBufferPos;
+ item->startPos = (s32)reverb->nextRingBufferPos;
reverb->nextRingBufferPos += nSamples;
- } else {
+ }
+ else
+ {
// Ring buffer wrapped around
item->lengthA = (nSamples - excessiveSamples) * 2;
item->lengthB = excessiveSamples * 2;
@@ -117,7 +126,8 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex)
item->chunkLen = chunkLen;
}
-u64 *synthesis_load_reverb_ring_buffer(u64 *cmd, u16 addr, u16 srcOffset, s32 len, s32 reverbIndex) {
+u64 *synthesis_load_reverb_ring_buffer(u64 *cmd, u16 addr, u16 srcOffset, s32 len, s32 reverbIndex)
+{
aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.left[srcOffset]),
addr, len);
aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.right[srcOffset]),
@@ -125,7 +135,8 @@ u64 *synthesis_load_reverb_ring_buffer(u64 *cmd, u16 addr, u16 srcOffset, s32 le
return cmd;
}
-u64 *synthesis_save_reverb_ring_buffer(u64 *cmd, u16 addr, u16 destOffset, s32 len, s32 reverbIndex) {
+u64 *synthesis_save_reverb_ring_buffer(u64 *cmd, u16 addr, u16 destOffset, s32 len, s32 reverbIndex)
+{
aSaveBuffer(cmd++, addr,
VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.left[destOffset]), len);
aSaveBuffer(cmd++, addr + DEFAULT_LEN_1CH,
@@ -133,71 +144,96 @@ u64 *synthesis_save_reverb_ring_buffer(u64 *cmd, u16 addr, u16 destOffset, s32 l
return cmd;
}
-void func_sh_802ed644(s32 updateIndexStart, s32 noteIndex) {
+void func_sh_802ed644(s32 updateIndexStart, s32 noteIndex)
+{
s32 i;
- for (i = updateIndexStart + 1; i < gAudioBufferParameters.updatesPerFrame; i++) {
- if (!gNoteSubsEu[gMaxSimultaneousNotes * i + noteIndex].needsInit) {
+ for (i = updateIndexStart + 1; i < gAudioBufferParameters.updatesPerFrame; i++)
+ {
+ if (!gNoteSubsEu[gMaxSimultaneousNotes * i + noteIndex].needsInit)
+ {
gNoteSubsEu[gMaxSimultaneousNotes * i + noteIndex].enabled = FALSE;
- } else {
+ }
+ else
+ {
break;
}
}
}
-void synthesis_load_note_subs_eu(s32 updateIndex) {
+void synthesis_load_note_subs_eu(s32 updateIndex)
+{
struct NoteSubEu *src;
struct NoteSubEu *dest;
s32 i;
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
src = &gNotes[i].noteSubEu;
dest = &gNoteSubsEu[gMaxSimultaneousNotes * updateIndex + i];
- if (src->enabled) {
+ if (src->enabled)
+ {
*dest = *src;
src->needsInit = FALSE;
- } else {
+ }
+ else
+ {
dest->enabled = FALSE;
}
}
}
// TODO: (Scrub C) pointless mask and whitespace
-u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) {
+u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen)
+{
s32 i, j;
u32 *aiBufPtr;
u64 *cmd = cmdBuf;
s32 chunkLen;
- for (i = gAudioBufferParameters.updatesPerFrame; i > 0; i--) {
+ for (i = gAudioBufferParameters.updatesPerFrame; i > 0; i--)
+ {
process_sequences(i - 1);
synthesis_load_note_subs_eu(gAudioBufferParameters.updatesPerFrame - i);
}
- aiBufPtr = (u32 *) aiBuf;
- for (i = gAudioBufferParameters.updatesPerFrame; i > 0; i--) {
- if (i == 1) {
+ aiBufPtr = (u32 *)aiBuf;
+ for (i = gAudioBufferParameters.updatesPerFrame; i > 0; i--)
+ {
+ if (i == 1)
+ {
chunkLen = bufLen;
- } else {
- if (bufLen / i >= gAudioBufferParameters.samplesPerUpdateMax) {
+ }
+ else
+ {
+ if (bufLen / i >= gAudioBufferParameters.samplesPerUpdateMax)
+ {
chunkLen = gAudioBufferParameters.samplesPerUpdateMax;
- } else if (bufLen / i <= gAudioBufferParameters.samplesPerUpdateMin) {
+ }
+ else if (bufLen / i <= gAudioBufferParameters.samplesPerUpdateMin)
+ {
chunkLen = gAudioBufferParameters.samplesPerUpdateMin;
- } else {
+ }
+ else
+ {
chunkLen = gAudioBufferParameters.samplesPerUpdate;
}
}
- for (j = 0; j < gNumSynthesisReverbs; j++) {
- if (gSynthesisReverbs[j].useReverb != 0) {
+ for (j = 0; j < gNumSynthesisReverbs; j++)
+ {
+ if (gSynthesisReverbs[j].useReverb != 0)
+ {
prepare_reverb_ring_buffer(chunkLen, gAudioBufferParameters.updatesPerFrame - i, j);
}
}
- cmd = synthesis_do_one_audio_update((s16 *) aiBufPtr, chunkLen, cmd, gAudioBufferParameters.updatesPerFrame - i);
+ cmd = synthesis_do_one_audio_update((s16 *)aiBufPtr, chunkLen, cmd, gAudioBufferParameters.updatesPerFrame - i);
bufLen -= chunkLen;
aiBufPtr += chunkLen;
}
- for (j = 0; j < gNumSynthesisReverbs; j++) {
- if (gSynthesisReverbs[j].framesLeftToIgnore != 0) {
+ for (j = 0; j < gNumSynthesisReverbs; j++)
+ {
+ if (gSynthesisReverbs[j].framesLeftToIgnore != 0)
+ {
gSynthesisReverbs[j].framesLeftToIgnore--;
}
gSynthesisReverbs[j].curFrame ^= 1;
@@ -206,26 +242,32 @@ u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) {
return cmd;
}
-u64 *synthesis_resample_and_mix_reverb(u64 *cmd, s32 bufLen, s16 reverbIndex, s16 updateIndex) {
+u64 *synthesis_resample_and_mix_reverb(u64 *cmd, s32 bufLen, s16 reverbIndex, s16 updateIndex)
+{
struct ReverbRingBufferItem *item;
s16 startPad;
s16 paddedLengthA;
item = &gSynthesisReverbs[reverbIndex].items[gSynthesisReverbs[reverbIndex].curFrame][updateIndex];
- if (gSynthesisReverbs[reverbIndex].downsampleRate == 1) {
+ if (gSynthesisReverbs[reverbIndex].downsampleRate == 1)
+ {
cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_WET_LEFT_CH, item->startPos, item->lengthA, reverbIndex);
- if (item->lengthB != 0) {
+ if (item->lengthB != 0)
+ {
cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_WET_LEFT_CH + item->lengthA, 0, item->lengthB, reverbIndex);
}
aAddMixer(cmd++, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_LEFT_CH, DEFAULT_LEN_2CH);
aMix(cmd++, 0x8000 + gSynthesisReverbs[reverbIndex].reverbGain, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_WET_LEFT_CH, DEFAULT_LEN_2CH);
- } else {
+ }
+ else
+ {
startPad = (item->startPos % 8u) * 2;
paddedLengthA = ALIGN(startPad + item->lengthA, 4);
cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED, (item->startPos - startPad / 2), DEFAULT_LEN_1CH, reverbIndex);
- if (item->lengthB != 0) {
+ if (item->lengthB != 0)
+ {
cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED + paddedLengthA, 0, DEFAULT_LEN_1CH - paddedLengthA, reverbIndex);
}
@@ -238,7 +280,8 @@ u64 *synthesis_resample_and_mix_reverb(u64 *cmd, s32 bufLen, s16 reverbIndex, s1
aAddMixer(cmd++, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_LEFT_CH, DEFAULT_LEN_2CH);
aMix(cmd++, 0x8000 + gSynthesisReverbs[reverbIndex].reverbGain, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_WET_LEFT_CH, DEFAULT_LEN_2CH);
}
- if (gSynthesisReverbs[reverbIndex].panRight != 0 || gSynthesisReverbs[reverbIndex].panLeft != 0) {
+ if (gSynthesisReverbs[reverbIndex].panRight != 0 || gSynthesisReverbs[reverbIndex].panLeft != 0)
+ {
// Leak some audio from the left reverb channel into the right reverb channel and vice versa (pan)
aDMEMMove(cmd++, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_RESAMPLED, DEFAULT_LEN_1CH);
aMix(cmd++, gSynthesisReverbs[reverbIndex].panRight, DMEM_ADDR_WET_RIGHT_CH, DMEM_ADDR_WET_LEFT_CH, DEFAULT_LEN_1CH);
@@ -247,7 +290,8 @@ u64 *synthesis_resample_and_mix_reverb(u64 *cmd, s32 bufLen, s16 reverbIndex, s1
return cmd;
}
-u64 *synthesis_load_reverb_samples(u64 *cmd, s16 reverbIndex, s16 updateIndex) {
+u64 *synthesis_load_reverb_samples(u64 *cmd, s16 reverbIndex, s16 updateIndex)
+{
struct ReverbRingBufferItem *item;
struct SynthesisReverb *reverb;
@@ -255,22 +299,26 @@ u64 *synthesis_load_reverb_samples(u64 *cmd, s16 reverbIndex, s16 updateIndex) {
item = &reverb->items[reverb->curFrame][updateIndex];
// Get the oldest samples in the ring buffer into the wet channels
cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED, item->startPos, item->lengthA, reverbIndex);
- if (item->lengthB != 0) {
+ if (item->lengthB != 0)
+ {
// Ring buffer wrapped
cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED + item->lengthA, 0, item->lengthB, reverbIndex);
}
return cmd;
}
-u64 *synthesis_save_reverb_samples(u64 *cmd, s16 reverbIndex, s16 updateIndex) {
+u64 *synthesis_save_reverb_samples(u64 *cmd, s16 reverbIndex, s16 updateIndex)
+{
struct ReverbRingBufferItem *item;
item = &gSynthesisReverbs[reverbIndex].items[gSynthesisReverbs[reverbIndex].curFrame][updateIndex];
- switch (gSynthesisReverbs[reverbIndex].downsampleRate) {
+ switch (gSynthesisReverbs[reverbIndex].downsampleRate)
+ {
case 1:
// Put the oldest samples in the ring buffer into the wet channels
cmd = synthesis_save_reverb_ring_buffer(cmd, DMEM_ADDR_WET_LEFT_CH, item->startPos, item->lengthA, reverbIndex);
- if (item->lengthB != 0) {
+ if (item->lengthB != 0)
+ {
// Ring buffer wrapped
cmd = synthesis_save_reverb_ring_buffer(cmd, DMEM_ADDR_WET_LEFT_CH + item->lengthA, 0, item->lengthB, reverbIndex);
}
@@ -280,14 +328,15 @@ u64 *synthesis_save_reverb_samples(u64 *cmd, s16 reverbIndex, s16 updateIndex) {
// Downsampling is done later by CPU when RSP is done, therefore we need to have double
// buffering. Left and right buffers are adjacent in memory.
aSaveBuffer(cmd++, DMEM_ADDR_WET_LEFT_CH,
- VIRTUAL_TO_PHYSICAL2(gSynthesisReverbs[reverbIndex].items[gSynthesisReverbs[reverbIndex].curFrame][updateIndex].toDownsampleLeft), DEFAULT_LEN_2CH);
+ VIRTUAL_TO_PHYSICAL2(gSynthesisReverbs[reverbIndex].items[gSynthesisReverbs[reverbIndex].curFrame][updateIndex].toDownsampleLeft), DEFAULT_LEN_2CH);
break;
}
gSynthesisReverbs[reverbIndex].resampleFlags = 0;
return cmd;
}
-u64 *func_sh_802EDF24(u64 *cmd, s16 reverbIndex, s16 updateIndex) {
+u64 *func_sh_802EDF24(u64 *cmd, s16 reverbIndex, s16 updateIndex)
+{
struct ReverbRingBufferItem *item;
struct SynthesisReverb *reverb;
@@ -295,14 +344,16 @@ u64 *func_sh_802EDF24(u64 *cmd, s16 reverbIndex, s16 updateIndex) {
item = &reverb->items[reverb->curFrame][updateIndex];
// Put the oldest samples in the ring buffer into the wet channels
cmd = synthesis_save_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED, item->startPos, item->lengthA, reverbIndex);
- if (item->lengthB != 0) {
+ if (item->lengthB != 0)
+ {
// Ring buffer wrapped
cmd = synthesis_save_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED + item->lengthA, 0, item->lengthB, reverbIndex);
}
return cmd;
}
-u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex) {
+u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex)
+{
struct NoteSubEu *noteSubEu;
u8 noteIndices[56];
s32 temp;
@@ -310,60 +361,81 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI
s16 j;
s16 notePos = 0;
- if (gNumSynthesisReverbs == 0) {
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
- if (gNoteSubsEu[gMaxSimultaneousNotes * updateIndex + i].enabled) {
+ if (gNumSynthesisReverbs == 0)
+ {
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
+ if (gNoteSubsEu[gMaxSimultaneousNotes * updateIndex + i].enabled)
+ {
noteIndices[notePos++] = i;
}
}
- } else {
- for (j = 0; j < gNumSynthesisReverbs; j++) {
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
+ }
+ else
+ {
+ for (j = 0; j < gNumSynthesisReverbs; j++)
+ {
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
noteSubEu = &gNoteSubsEu[gMaxSimultaneousNotes * updateIndex + i];
- if (noteSubEu->enabled && j == noteSubEu->reverbIndex) {
+ if (noteSubEu->enabled && j == noteSubEu->reverbIndex)
+ {
noteIndices[notePos++] = i;
}
}
}
- for (i = 0; i < gMaxSimultaneousNotes; i++) {
+ for (i = 0; i < gMaxSimultaneousNotes; i++)
+ {
noteSubEu = &gNoteSubsEu[gMaxSimultaneousNotes * updateIndex + i];
- if (noteSubEu->enabled && noteSubEu->reverbIndex >= gNumSynthesisReverbs) {
+ if (noteSubEu->enabled && noteSubEu->reverbIndex >= gNumSynthesisReverbs)
+ {
noteIndices[notePos++] = i;
}
}
}
aClearBuffer(cmd++, DMEM_ADDR_LEFT_CH, DEFAULT_LEN_2CH);
i = 0;
- for (j = 0; j < gNumSynthesisReverbs; j++) {
+ for (j = 0; j < gNumSynthesisReverbs; j++)
+ {
gUseReverb = gSynthesisReverbs[j].useReverb;
- if (gUseReverb != 0) {
+ if (gUseReverb != 0)
+ {
cmd = synthesis_resample_and_mix_reverb(cmd, bufLen, j, updateIndex);
}
- for (; i < notePos; i++) {
+ for (; i < notePos; i++)
+ {
temp = updateIndex * gMaxSimultaneousNotes;
- if (j == gNoteSubsEu[temp + noteIndices[i]].reverbIndex) {
+ if (j == gNoteSubsEu[temp + noteIndices[i]].reverbIndex)
+ {
cmd = synthesis_process_note(noteIndices[i],
&gNoteSubsEu[temp + noteIndices[i]],
&gNotes[noteIndices[i]].synthesisState,
aiBuf, bufLen, cmd, updateIndex);
continue;
- } else {
+ }
+ else
+ {
break;
}
}
- if (gSynthesisReverbs[j].useReverb != 0) {
- if (gSynthesisReverbs[j].unk100 != NULL) {
+ if (gSynthesisReverbs[j].useReverb != 0)
+ {
+ if (gSynthesisReverbs[j].unk100 != NULL)
+ {
aFilter(cmd++, 0x02, bufLen * 2, gSynthesisReverbs[j].unk100);
aFilter(cmd++, gSynthesisReverbs[j].resampleFlags, DMEM_ADDR_WET_LEFT_CH, gSynthesisReverbs[j].unk108);
}
- if (gSynthesisReverbs[j].unk104 != NULL) {
+ if (gSynthesisReverbs[j].unk104 != NULL)
+ {
aFilter(cmd++, 0x02, bufLen * 2, gSynthesisReverbs[j].unk104);
aFilter(cmd++, gSynthesisReverbs[j].resampleFlags, DMEM_ADDR_WET_RIGHT_CH, gSynthesisReverbs[j].unk10C);
}
cmd = synthesis_save_reverb_samples(cmd, j, updateIndex);
- if (gSynthesisReverbs[j].unk5 != -1) {
- if (gSynthesisReverbs[gSynthesisReverbs[j].unk5].downsampleRate == 1) {
+ if (gSynthesisReverbs[j].unk5 != -1)
+ {
+ if (gSynthesisReverbs[gSynthesisReverbs[j].unk5].downsampleRate == 1)
+ {
cmd = synthesis_load_reverb_samples(cmd, gSynthesisReverbs[j].unk5, updateIndex);
aMix(cmd++, gSynthesisReverbs[j].unk08, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_RESAMPLED, DEFAULT_LEN_2CH);
cmd = func_sh_802EDF24(cmd++, gSynthesisReverbs[j].unk5, updateIndex);
@@ -371,7 +443,8 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI
}
}
}
- for (; i < notePos; i++) {
+ for (; i < notePos; i++)
+ {
struct NoteSubEu *noteSubEu2 = &gNoteSubsEu[updateIndex * gMaxSimultaneousNotes + noteIndices[i]];
cmd = synthesis_process_note(noteIndices[i],
noteSubEu2,
@@ -385,7 +458,8 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI
return cmd;
}
-u64 *synthesis_process_note(s32 noteIndex, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, UNUSED s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex) {
+u64 *synthesis_process_note(s32 noteIndex, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, UNUSED s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex)
+{
UNUSED s32 pad0[3];
struct AudioBankSample *audioBookSample; // sp164, sp138
struct AdpcmLoop *loopInfo; // sp160, sp134
@@ -415,7 +489,7 @@ u64 *synthesis_process_note(s32 noteIndex, struct NoteSubEu *noteSubEu, struct N
s32 leftRight; //s0
s32 s5; //s4
u32 samplesLenFixedPoint; // v1_1
- s32 s3; // spA0
+ s32 s3; // spA0
s32 nSamplesInThisIteration; // v1_2
u32 a3;
u8 *v0_2;
@@ -433,15 +507,16 @@ u64 *synthesis_process_note(s32 noteIndex, struct NoteSubEu *noteSubEu, struct N
UNUSED u32 padSH2;
UNUSED u32 padSH3;
UNUSED u32 padSH4;
- struct Note *note; // sp58
- u16 sp56; // sp56
+ struct Note *note; // sp58
+ u16 sp56; // sp56
u16 addr;
u8 synthesisVolume;
curLoadedBook = NULL;
note = &gNotes[noteIndex];
flags = 0;
- if (noteSubEu->needsInit == TRUE) {
+ if (noteSubEu->needsInit == TRUE)
+ {
flags = A_INIT;
synthesisState->restart = 0;
synthesisState->samplePosInt = 0;
@@ -461,46 +536,63 @@ u64 *synthesis_process_note(s32 noteIndex, struct NoteSubEu *noteSubEu, struct N
nSamplesToLoad = (samplesLenFixedPoint >> 0x10);
synthesisState->samplePosFrac = samplesLenFixedPoint & 0xFFFF;
- if ((synthesisState->unk5 == 1) && (nParts == 2)) {
+ if ((synthesisState->unk5 == 1) && (nParts == 2))
+ {
nSamplesToLoad += 2;
sp56 = 2;
- } else if ((synthesisState->unk5 == 2) && (nParts == 1)) {
+ }
+ else if ((synthesisState->unk5 == 2) && (nParts == 1))
+ {
nSamplesToLoad -= 4;
sp56 = 4;
- } else {
+ }
+ else
+ {
sp56 = 0;
}
synthesisState->unk5 = nParts;
- if (noteSubEu->isSyntheticWave) {
+ if (noteSubEu->isSyntheticWave)
+ {
cmd = load_wave_samples(cmd, noteSubEu, synthesisState, nSamplesToLoad);
noteSamplesDmemAddrBeforeResampling = (synthesisState->samplePosInt * 2) + DMEM_ADDR_UNCOMPRESSED_NOTE;
synthesisState->samplePosInt += nSamplesToLoad;
- } else {
+ }
+ else
+ {
// ADPCM note
audioBookSample = noteSubEu->sound.audioBankSound->sample;
loopInfo = audioBookSample->loop;
endPos = loopInfo->end;
sampleAddr = audioBookSample->sampleAddr;
resampledTempLen = 0;
- for (curPart = 0; curPart < nParts; curPart++) {
+ for (curPart = 0; curPart < nParts; curPart++)
+ {
nAdpcmSamplesProcessed = 0; // s8
s5 = 0; // s4
- if (nParts == 1) {
+ if (nParts == 1)
+ {
samplesLenAdjusted = nSamplesToLoad;
- } else if (nSamplesToLoad & 1) {
+ }
+ else if (nSamplesToLoad & 1)
+ {
samplesLenAdjusted = (nSamplesToLoad & ~1) + (curPart * 2);
- } else {
+ }
+ else
+ {
samplesLenAdjusted = nSamplesToLoad;
}
- if (audioBookSample->codec == CODEC_ADPCM) {
- if (curLoadedBook != (*audioBookSample->book).book) {
+ if (audioBookSample->codec == CODEC_ADPCM)
+ {
+ if (curLoadedBook != (*audioBookSample->book).book)
+ {
u32 nEntries;
- switch (noteSubEu->bookOffset) {
+ switch (noteSubEu->bookOffset)
+ {
case 1:
curLoadedBook = euUnknownData_80301950 + 1;
break;
@@ -517,7 +609,8 @@ u64 *synthesis_process_note(s32 noteIndex, struct NoteSubEu *noteSubEu, struct N
}
}
- while (nAdpcmSamplesProcessed != samplesLenAdjusted) {
+ while (nAdpcmSamplesProcessed != samplesLenAdjusted)
+ {
s32 samplesRemaining; // v1
s32 s0;
@@ -527,30 +620,39 @@ u64 *synthesis_process_note(s32 noteIndex, struct NoteSubEu *noteSubEu, struct N
samplesRemaining = endPos - synthesisState->samplePosInt;
nSamplesToProcess = samplesLenAdjusted - nAdpcmSamplesProcessed;
- if (s2 == 0 && synthesisState->restart == FALSE) {
+ if (s2 == 0 && synthesisState->restart == FALSE)
+ {
s2 = 16;
}
s6 = 16 - s2; // a1
- if (nSamplesToProcess < samplesRemaining) {
+ if (nSamplesToProcess < samplesRemaining)
+ {
t0 = (nSamplesToProcess - s6 + 0xf) / 16;
s0 = t0 * 16;
s3 = s6 + s0 - nSamplesToProcess;
- } else {
+ }
+ else
+ {
s0 = samplesRemaining - s6;
s3 = 0;
- if (s0 <= 0) {
+ if (s0 <= 0)
+ {
s0 = 0;
s6 = samplesRemaining;
}
t0 = (s0 + 0xf) / 16;
- if (loopInfo->count != 0) {
+ if (loopInfo->count != 0)
+ {
// Loop around and restart
restart = 1;
- } else {
+ }
+ else
+ {
noteFinished = 1;
}
}
- switch (audioBookSample->codec) {
+ switch (audioBookSample->codec)
+ {
case CODEC_ADPCM:
unk_s6 = 9;
sp88 = 0x10;
@@ -561,33 +663,43 @@ u64 *synthesis_process_note(s32 noteIndex, struct NoteSubEu *noteSubEu, struct N
sp88 = 0x10;
sp84 = 0;
break;
- case CODEC_SKIP: goto skip;
+ case CODEC_SKIP:
+ goto skip;
}
- if (t0 != 0) {
+ if (t0 != 0)
+ {
temp = (synthesisState->samplePosInt + sp88 - s2) / 16;
- if (audioBookSample->medium == 0) {
+ if (audioBookSample->medium == 0)
+ {
v0_2 = sp84 + (temp * unk_s6) + sampleAddr;
- } else {
+ }
+ else
+ {
v0_2 = dma_sample_data((uintptr_t)(sp84 + (temp * unk_s6) + sampleAddr),
- ALIGN(t0 * unk_s6 + 16, 4), flags, &synthesisState->sampleDmaIndex, audioBookSample->medium);
+ ALIGN(t0 * unk_s6 + 16, 4), flags, &synthesisState->sampleDmaIndex, audioBookSample->medium);
}
a3 = ((uintptr_t)v0_2 & 0xf);
aligned = ALIGN(t0 * unk_s6 + 16, 4);
addr = (DMEM_ADDR_COMPRESSED_ADPCM_DATA - aligned) & 0xffff;
aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(v0_2 - a3), addr, ALIGN(t0 * unk_s6 + 16, 4));
- } else {
+ }
+ else
+ {
s0 = 0;
a3 = 0;
}
- if (synthesisState->restart != FALSE) {
+ if (synthesisState->restart != FALSE)
+ {
aSetLoop(cmd++, VIRTUAL_TO_PHYSICAL2(audioBookSample->loop->state));
flags = A_LOOP; // = 2
synthesisState->restart = FALSE;
}
nSamplesInThisIteration = s0 + s6 - s3;
- if (nAdpcmSamplesProcessed == 0) {
- switch (audioBookSample->codec) {
+ if (nAdpcmSamplesProcessed == 0)
+ {
+ switch (audioBookSample->codec)
+ {
case CODEC_ADPCM:
aligned = ALIGN(t0 * unk_s6 + 16, 4);
addr = (DMEM_ADDR_COMPRESSED_ADPCM_DATA - aligned) & 0xffff;
@@ -602,9 +714,12 @@ u64 *synthesis_process_note(s32 noteIndex, struct NoteSubEu *noteSubEu, struct N
break;
}
sp130 = s2 * 2;
- } else {
+ }
+ else
+ {
s5Aligned = ALIGN(s5 + 16, 4);
- switch (audioBookSample->codec) {
+ switch (audioBookSample->codec)
+ {
case CODEC_ADPCM:
aligned = ALIGN(t0 * unk_s6 + 16, 4);
addr = (DMEM_ADDR_COMPRESSED_ADPCM_DATA - aligned) & 0xffff;
@@ -621,7 +736,8 @@ u64 *synthesis_process_note(s32 noteIndex, struct NoteSubEu *noteSubEu, struct N
aDMEMMove(cmd++, DMEM_ADDR_UNCOMPRESSED_NOTE + s5Aligned + (s2 * 2), DMEM_ADDR_UNCOMPRESSED_NOTE + s5, (nSamplesInThisIteration) * 2);
}
nAdpcmSamplesProcessed += nSamplesInThisIteration;
- switch (flags) {
+ switch (flags)
+ {
case A_INIT: // = 1
sp130 = 0x20;
s5 = (s0 + 0x10) * 2;
@@ -630,42 +746,51 @@ u64 *synthesis_process_note(s32 noteIndex, struct NoteSubEu *noteSubEu, struct N
s5 = (nSamplesInThisIteration) * 2 + s5;
break;
default:
- if (s5 != 0) {
+ if (s5 != 0)
+ {
s5 = (nSamplesInThisIteration) * 2 + s5;
- } else {
+ }
+ else
+ {
s5 = (s2 + (nSamplesInThisIteration)) * 2;
}
break;
}
flags = 0;
-skip:
- if (noteFinished) {
+ skip: if (noteFinished)
+ {
aClearBuffer(cmd++, DMEM_ADDR_UNCOMPRESSED_NOTE + s5,
- (samplesLenAdjusted - nAdpcmSamplesProcessed) * 2);
+ (samplesLenAdjusted - nAdpcmSamplesProcessed) * 2);
noteSubEu->finished = 1;
note->noteSubEu.finished = 1;
func_sh_802ed644(updateIndex, noteIndex);
break;
}
- if (restart != 0) {
+ if (restart != 0)
+ {
synthesisState->restart = TRUE;
synthesisState->samplePosInt = loopInfo->start;
- } else {
+ }
+ else
+ {
synthesisState->samplePosInt += nSamplesToProcess;
}
}
- switch (nParts) {
+ switch (nParts)
+ {
case 1:
noteSamplesDmemAddrBeforeResampling = DMEM_ADDR_UNCOMPRESSED_NOTE + sp130;
break;
case 2:
- switch (curPart) {
+ switch (curPart)
+ {
case 0:
aDownsampleHalf(cmd++, ALIGN(samplesLenAdjusted / 2, 3), DMEM_ADDR_UNCOMPRESSED_NOTE + sp130, DMEM_ADDR_RESAMPLED);
resampledTempLen = samplesLenAdjusted;
noteSamplesDmemAddrBeforeResampling = DMEM_ADDR_RESAMPLED;
- if (noteSubEu->finished != FALSE) {
+ if (noteSubEu->finished != FALSE)
+ {
aClearBuffer(cmd++, noteSamplesDmemAddrBeforeResampling + resampledTempLen, samplesLenAdjusted + 0x10);
}
break;
@@ -674,52 +799,65 @@ skip:
break;
}
}
- if (noteSubEu->finished != FALSE) {
+ if (noteSubEu->finished != FALSE)
+ {
break;
}
}
}
flags = 0;
- if (noteSubEu->needsInit == TRUE) {
+ if (noteSubEu->needsInit == TRUE)
+ {
flags = A_INIT;
noteSubEu->needsInit = FALSE;
}
flags = flags | sp56;
cmd = final_resample(cmd, synthesisState, bufLen * 2, resamplingRateFixedPoint,
- noteSamplesDmemAddrBeforeResampling, flags);
- if ((flags & 1) != 0) {
+ noteSamplesDmemAddrBeforeResampling, flags);
+ if ((flags & 1) != 0)
+ {
flags = 1;
}
- if (noteSubEu->filter) {
+ if (noteSubEu->filter)
+ {
aFilter(cmd++, 0x02, bufLen * 2, noteSubEu->filter);
aFilter(cmd++, flags, DMEM_ADDR_TEMP, synthesisState->synthesisBuffers->filterBuffer);
-
}
- if (noteSubEu->bookOffset == 3) {
+ if (noteSubEu->bookOffset == 3)
+ {
aUnknown25(cmd++, 0, bufLen * 2, DMEM_ADDR_TEMP, DMEM_ADDR_TEMP);
}
synthesisVolume = noteSubEu->synthesisVolume;
- if (synthesisVolume != 0) {
- if (synthesisVolume < 0x10) {
+ if (synthesisVolume != 0)
+ {
+ if (synthesisVolume < 0x10)
+ {
synthesisVolume = 0x10;
}
aHiLoGain(cmd++, synthesisVolume, (bufLen + 0x10) * 2, DMEM_ADDR_TEMP);
}
- if (noteSubEu->headsetPanRight != 0 || synthesisState->prevHeadsetPanRight != 0) {
+ if (noteSubEu->headsetPanRight != 0 || synthesisState->prevHeadsetPanRight != 0)
+ {
leftRight = 1;
- } else if (noteSubEu->headsetPanLeft != 0 || synthesisState->prevHeadsetPanLeft != 0) {
+ }
+ else if (noteSubEu->headsetPanLeft != 0 || synthesisState->prevHeadsetPanLeft != 0)
+ {
leftRight = 2;
- } else {
+ }
+ else
+ {
leftRight = 0;
}
cmd = process_envelope(cmd, noteSubEu, synthesisState, bufLen, DMEM_ADDR_TEMP, leftRight, flags);
- if (noteSubEu->usesHeadsetPanEffects) {
- if ((flags & 1) == 0) {
+ if (noteSubEu->usesHeadsetPanEffects)
+ {
+ if ((flags & 1) == 0)
+ {
flags = 0;
}
cmd = note_apply_headset_pan_effects(cmd, noteSubEu, synthesisState, bufLen * 2, flags, leftRight);
@@ -728,7 +866,8 @@ skip:
return cmd;
}
-u64 *load_wave_samples(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s32 nSamplesToLoad) {
+u64 *load_wave_samples(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s32 nSamplesToLoad)
+{
s32 a3;
s32 repeats;
aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(noteSubEu->sound.samples),
@@ -736,29 +875,36 @@ u64 *load_wave_samples(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthes
synthesisState->samplePosInt &= 0x3f;
a3 = 64 - synthesisState->samplePosInt;
- if (a3 < nSamplesToLoad) {
+ if (a3 < nSamplesToLoad)
+ {
repeats = (nSamplesToLoad - a3 + 63) / 64;
- if (repeats != 0) {
+ if (repeats != 0)
+ {
aDuplicate(cmd++,
- /*dmemin*/ DMEM_ADDR_UNCOMPRESSED_NOTE,
- /*dmemout*/ DMEM_ADDR_UNCOMPRESSED_NOTE + 128,
- /*copies*/ repeats);
+ /*dmemin*/ DMEM_ADDR_UNCOMPRESSED_NOTE,
+ /*dmemout*/ DMEM_ADDR_UNCOMPRESSED_NOTE + 128,
+ /*copies*/ repeats);
}
}
return cmd;
}
-u64 *final_resample(u64 *cmd, struct NoteSynthesisState *synthesisState, s32 count, u16 pitch, u16 dmemIn, u32 flags) {
- if (pitch == 0) {
+u64 *final_resample(u64 *cmd, struct NoteSynthesisState *synthesisState, s32 count, u16 pitch, u16 dmemIn, u32 flags)
+{
+ if (pitch == 0)
+ {
aClearBuffer(cmd++, DMEM_ADDR_TEMP, count);
- } else {
+ }
+ else
+ {
aSetBuffer(cmd++, /*flags*/ 0, dmemIn, /*dmemout*/ DMEM_ADDR_TEMP, count);
aResample(cmd++, flags, pitch, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->finalResampleState));
}
return cmd;
}
-u64 *process_envelope(u64 *cmd, struct NoteSubEu *note, struct NoteSynthesisState *synthesisState, s32 nSamples, u16 inBuf, s32 headsetPanSettings, UNUSED u32 flags) {
+u64 *process_envelope(u64 *cmd, struct NoteSubEu *note, struct NoteSynthesisState *synthesisState, s32 nSamples, u16 inBuf, s32 headsetPanSettings, UNUSED u32 flags)
+{
u16 sourceRight;
u16 sourceLeft;
u16 targetLeft;
@@ -776,88 +922,103 @@ u64 *process_envelope(u64 *cmd, struct NoteSubEu *note, struct NoteSynthesisStat
targetLeft <<= 4;
targetRight <<= 4;
- if (targetLeft != sourceLeft) {
+ if (targetLeft != sourceLeft)
+ {
rampLeft = (targetLeft - sourceLeft) / (nSamples >> 3);
- } else {
+ }
+ else
+ {
rampLeft = 0;
}
- if (targetRight != sourceRight) {
+ if (targetRight != sourceRight)
+ {
rampRight = (targetRight - sourceRight) / (nSamples >> 3);
- } else {
+ }
+ else
+ {
rampRight = 0;
}
sourceReverbVol = synthesisState->reverbVol;
- if (note->reverbVol != sourceReverbVol) {
+ if (note->reverbVol != sourceReverbVol)
+ {
reverbVolDiff = ((note->reverbVol & 0x7f) - (sourceReverbVol & 0x7f)) << 9;
rampReverb = reverbVolDiff / (nSamples >> 3);
synthesisState->reverbVol = note->reverbVol;
- } else {
+ }
+ else
+ {
rampReverb = 0;
}
synthesisState->curVolLeft = sourceLeft + rampLeft * (nSamples >> 3);
synthesisState->curVolRight = sourceRight + rampRight * (nSamples >> 3);
- if (note->usesHeadsetPanEffects) {
+ if (note->usesHeadsetPanEffects)
+ {
aClearBuffer(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, DEFAULT_LEN_1CH);
aEnvSetup1(cmd++, (sourceReverbVol & 0x7f) * 2, rampReverb, rampLeft, rampRight);
aEnvSetup2(cmd++, sourceLeft, sourceRight);
- switch (headsetPanSettings) {
+ switch (headsetPanSettings)
+ {
case 1:
aEnvMixer(cmd++,
- inBuf, nSamples,
- (sourceReverbVol & 0x80) >> 7,
- note->stereoStrongRight, note->stereoStrongLeft,
- DMEM_ADDR_NOTE_PAN_TEMP,
- DMEM_ADDR_RIGHT_CH,
- DMEM_ADDR_WET_LEFT_CH,
- DMEM_ADDR_WET_RIGHT_CH);
+ inBuf, nSamples,
+ (sourceReverbVol & 0x80) >> 7,
+ note->stereoStrongRight, note->stereoStrongLeft,
+ DMEM_ADDR_NOTE_PAN_TEMP,
+ DMEM_ADDR_RIGHT_CH,
+ DMEM_ADDR_WET_LEFT_CH,
+ DMEM_ADDR_WET_RIGHT_CH);
break;
case 2:
aEnvMixer(cmd++,
- inBuf, nSamples,
- (sourceReverbVol & 0x80) >> 7,
- note->stereoStrongRight, note->stereoStrongLeft,
- DMEM_ADDR_LEFT_CH,
- DMEM_ADDR_NOTE_PAN_TEMP,
- DMEM_ADDR_WET_LEFT_CH,
- DMEM_ADDR_WET_RIGHT_CH);
+ inBuf, nSamples,
+ (sourceReverbVol & 0x80) >> 7,
+ note->stereoStrongRight, note->stereoStrongLeft,
+ DMEM_ADDR_LEFT_CH,
+ DMEM_ADDR_NOTE_PAN_TEMP,
+ DMEM_ADDR_WET_LEFT_CH,
+ DMEM_ADDR_WET_RIGHT_CH);
break;
default:
aEnvMixer(cmd++,
- inBuf, nSamples,
- (sourceReverbVol & 0x80) >> 7,
- note->stereoStrongRight, note->stereoStrongLeft,
- DMEM_ADDR_LEFT_CH,
- DMEM_ADDR_RIGHT_CH,
- DMEM_ADDR_WET_LEFT_CH,
- DMEM_ADDR_WET_RIGHT_CH);
+ inBuf, nSamples,
+ (sourceReverbVol & 0x80) >> 7,
+ note->stereoStrongRight, note->stereoStrongLeft,
+ DMEM_ADDR_LEFT_CH,
+ DMEM_ADDR_RIGHT_CH,
+ DMEM_ADDR_WET_LEFT_CH,
+ DMEM_ADDR_WET_RIGHT_CH);
break;
}
- } else {
+ }
+ else
+ {
aEnvSetup1(cmd++, (sourceReverbVol & 0x7f) * 2, rampReverb, rampLeft, rampRight);
aEnvSetup2(cmd++, sourceLeft, sourceRight);
aEnvMixer(cmd++,
- inBuf, nSamples,
- (sourceReverbVol & 0x80) >> 7,
- note->stereoStrongRight, note->stereoStrongLeft,
- DMEM_ADDR_LEFT_CH,
- DMEM_ADDR_RIGHT_CH,
- DMEM_ADDR_WET_LEFT_CH,
- DMEM_ADDR_WET_RIGHT_CH);
+ inBuf, nSamples,
+ (sourceReverbVol & 0x80) >> 7,
+ note->stereoStrongRight, note->stereoStrongLeft,
+ DMEM_ADDR_LEFT_CH,
+ DMEM_ADDR_RIGHT_CH,
+ DMEM_ADDR_WET_LEFT_CH,
+ DMEM_ADDR_WET_RIGHT_CH);
}
return cmd;
}
-u64 *note_apply_headset_pan_effects(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *note, s32 bufLen, s32 flags, s32 leftRight) {
+u64 *note_apply_headset_pan_effects(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *note, s32 bufLen, s32 flags, s32 leftRight)
+{
u16 dest;
u16 pitch;
u8 prevPanShift;
u8 panShift;
UNUSED u8 unkDebug;
- switch (leftRight) {
+ switch (leftRight)
+ {
case 1:
dest = DMEM_ADDR_LEFT_CH;
panShift = noteSubEu->headsetPanRight;
@@ -877,31 +1038,41 @@ u64 *note_apply_headset_pan_effects(u64 *cmd, struct NoteSubEu *noteSubEu, struc
return cmd;
}
- if (flags != 1) { // A_INIT?
+ if (flags != 1)
+ { // A_INIT?
// Slightly adjust the sample rate in order to fit a change in pan shift
- if (panShift != prevPanShift) {
+ if (panShift != prevPanShift)
+ {
pitch = (((bufLen << 0xf) / 2) - 1) / ((bufLen + panShift - prevPanShift - 2) / 2);
aSetBuffer(cmd++, 0, DMEM_ADDR_NOTE_PAN_TEMP, DMEM_ADDR_TEMP, (bufLen + panShift) - prevPanShift);
aResampleZoh(cmd++, pitch, 0);
- } else {
+ }
+ else
+ {
aDMEMMove(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, DMEM_ADDR_TEMP, bufLen);
}
- if (prevPanShift != 0) {
+ if (prevPanShift != 0)
+ {
aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->panSamplesBuffer),
DMEM_ADDR_NOTE_PAN_TEMP, ALIGN(prevPanShift, 4));
aDMEMMove(cmd++, DMEM_ADDR_TEMP, DMEM_ADDR_NOTE_PAN_TEMP + prevPanShift, bufLen + panShift - prevPanShift);
- } else {
+ }
+ else
+ {
aDMEMMove(cmd++, DMEM_ADDR_TEMP, DMEM_ADDR_NOTE_PAN_TEMP, bufLen + panShift);
}
- } else {
+ }
+ else
+ {
// Just shift right
aDMEMMove(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, DMEM_ADDR_TEMP, bufLen);
aClearBuffer(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, panShift);
aDMEMMove(cmd++, DMEM_ADDR_TEMP, DMEM_ADDR_NOTE_PAN_TEMP + panShift, bufLen);
}
- if (panShift) {
+ if (panShift)
+ {
// Save excessive samples for next iteration
aSaveBuffer(cmd++, DMEM_ADDR_NOTE_PAN_TEMP + bufLen,
VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->panSamplesBuffer), ALIGN(panShift, 4));
diff --git a/src/decomp/engine/geo_layout.c b/src/decomp/engine/geo_layout.c
index ae40125..75f3bf4 100644
--- a/src/decomp/engine/geo_layout.c
+++ b/src/decomp/engine/geo_layout.c
@@ -6,7 +6,7 @@
#include "graph_node.h"
#include "../shim.h"
-static Vec3s gVec3sZero = { 0, 0, 0 };
+static Vec3s gVec3sZero = {0, 0, 0};
typedef void (*GeoLayoutCommandProc)(void);
@@ -102,53 +102,60 @@ UNUSED s16 D_8038BD7C;
s16 gGeoLayoutReturnIndex; // similar to RA register in MIPS
u8 *gGeoLayoutCommand;
-u32 unused_8038B894[3] = { 0 };
+u32 unused_8038B894[3] = {0};
/*
0x00: Branch and store return address
cmd+0x04: void *branchTarget
*/
-void geo_layout_cmd_branch_and_link(void) {
- gGeoLayoutStack[gGeoLayoutStackIndex++] = (uintptr_t) (gGeoLayoutCommand + CMD_PROCESS_OFFSET(8));
+void geo_layout_cmd_branch_and_link(void)
+{
+ gGeoLayoutStack[gGeoLayoutStackIndex++] = (uintptr_t)(gGeoLayoutCommand + CMD_PROCESS_OFFSET(8));
gGeoLayoutStack[gGeoLayoutStackIndex++] = (gCurGraphNodeIndex << 16) + gGeoLayoutReturnIndex;
gGeoLayoutReturnIndex = gGeoLayoutStackIndex;
gGeoLayoutCommand = segmented_to_virtual(cur_geo_cmd_ptr(0x04));
}
// 0x01: Terminate geo layout
-void geo_layout_cmd_end(void) {
+void geo_layout_cmd_end(void)
+{
gGeoLayoutStackIndex = gGeoLayoutReturnIndex;
gGeoLayoutReturnIndex = gGeoLayoutStack[--gGeoLayoutStackIndex] & 0xFFFF;
gCurGraphNodeIndex = gGeoLayoutStack[gGeoLayoutStackIndex] >> 16;
- gGeoLayoutCommand = (u8 *) gGeoLayoutStack[--gGeoLayoutStackIndex];
+ gGeoLayoutCommand = (u8 *)gGeoLayoutStack[--gGeoLayoutStackIndex];
}
/*
0x02: Branch
cmd+0x04: void *branchTarget
*/
-void geo_layout_cmd_branch(void) {
- if (cur_geo_cmd_u8(0x01) == 1) {
- gGeoLayoutStack[gGeoLayoutStackIndex++] = (uintptr_t) (gGeoLayoutCommand + CMD_PROCESS_OFFSET(8));
+void geo_layout_cmd_branch(void)
+{
+ if (cur_geo_cmd_u8(0x01) == 1)
+ {
+ gGeoLayoutStack[gGeoLayoutStackIndex++] = (uintptr_t)(gGeoLayoutCommand + CMD_PROCESS_OFFSET(8));
}
gGeoLayoutCommand = segmented_to_virtual(cur_geo_cmd_ptr(0x04));
}
// 0x03: Return from branch
-void geo_layout_cmd_return(void) {
- gGeoLayoutCommand = (u8 *) gGeoLayoutStack[--gGeoLayoutStackIndex];
+void geo_layout_cmd_return(void)
+{
+ gGeoLayoutCommand = (u8 *)gGeoLayoutStack[--gGeoLayoutStackIndex];
}
// 0x04: Open node
-void geo_layout_cmd_open_node(void) {
+void geo_layout_cmd_open_node(void)
+{
gCurGraphNodeList[gCurGraphNodeIndex + 1] = gCurGraphNodeList[gCurGraphNodeIndex];
gCurGraphNodeIndex++;
gGeoLayoutCommand += 0x04 << CMD_SIZE_SHIFT;
}
// 0x05: Close node
-void geo_layout_cmd_close_node(void) {
+void geo_layout_cmd_close_node(void)
+{
gCurGraphNodeIndex--;
gGeoLayoutCommand += 0x04 << CMD_SIZE_SHIFT;
}
@@ -159,10 +166,12 @@ void geo_layout_cmd_close_node(void) {
Register the current node in the gGeoViews array at the given index
*/
-void geo_layout_cmd_assign_as_view(void) {
+void geo_layout_cmd_assign_as_view(void)
+{
u16 index = cur_geo_cmd_s16(0x02);
- if (index < gGeoNumViews) {
+ if (index < gGeoNumViews)
+ {
gGeoViews[index] = gCurGraphNodeList[gCurGraphNodeIndex];
}
@@ -174,11 +183,13 @@ void geo_layout_cmd_assign_as_view(void) {
cmd+0x01: u8 operation (0 = reset, 1 = set, 2 = clear)
cmd+0x02: s16 bits
*/
-void geo_layout_cmd_update_node_flags(void) {
+void geo_layout_cmd_update_node_flags(void)
+{
u16 operation = cur_geo_cmd_u8(0x01);
u16 flagBits = cur_geo_cmd_s16(0x02);
- switch (operation) {
+ switch (operation)
+ {
case GEO_CMD_FLAGS_RESET:
gCurGraphNodeList[gCurGraphNodeIndex]->flags = flagBits;
break;
@@ -201,7 +212,8 @@ void geo_layout_cmd_update_node_flags(void) {
cmd+0x08: s16 width
cmd+0x0A: s16 height
*/
-void geo_layout_cmd_node_root(void) {
+void geo_layout_cmd_node_root(void)
+{
s32 i;
struct GraphNodeRoot *graphNode;
@@ -223,7 +235,8 @@ void geo_layout_cmd_node_root(void) {
graphNode->views = gGeoViews;
graphNode->numViews = gGeoNumViews;
- for (i = 0; i < gGeoNumViews; i++) {
+ for (i = 0; i < gGeoNumViews; i++)
+ {
gGeoViews[i] = NULL;
}
@@ -236,9 +249,10 @@ void geo_layout_cmd_node_root(void) {
0x09: Create orthographic projection scene graph node
cmd+0x02: s16 scale as a percentage (usually it's 100)
*/
-void geo_layout_cmd_node_ortho_projection(void) {
+void geo_layout_cmd_node_ortho_projection(void)
+{
struct GraphNodeOrthoProjection *graphNode;
- f32 scale = (f32) cur_geo_cmd_s16(0x02) / 100.0f;
+ f32 scale = (f32)cur_geo_cmd_s16(0x02) / 100.0f;
graphNode = init_graph_node_ortho_projection(gGraphNodePool, NULL, scale);
@@ -255,20 +269,22 @@ void geo_layout_cmd_node_ortho_projection(void) {
cmd+0x06: s16 far
[cmd+0x08: GraphNodeFunc frustumFunc]
*/
-void geo_layout_cmd_node_perspective(void) {
+void geo_layout_cmd_node_perspective(void)
+{
struct GraphNodePerspective *graphNode;
GraphNodeFunc frustumFunc = NULL;
s16 fov = cur_geo_cmd_s16(0x02);
s16 near = cur_geo_cmd_s16(0x04);
s16 far = cur_geo_cmd_s16(0x06);
- if (cur_geo_cmd_u8(0x01) != 0) {
+ if (cur_geo_cmd_u8(0x01) != 0)
+ {
// optional asm function
- frustumFunc = (GraphNodeFunc) cur_geo_cmd_ptr(0x08);
+ frustumFunc = (GraphNodeFunc)cur_geo_cmd_ptr(0x08);
gGeoLayoutCommand += 4 << CMD_SIZE_SHIFT;
}
- graphNode = init_graph_node_perspective(gGraphNodePool, NULL, (f32) fov, near, far, frustumFunc, 0);
+ graphNode = init_graph_node_perspective(gGraphNodePool, NULL, fov, near, far, frustumFunc, 0);
register_scene_graph_node(&graphNode->fnNode.node);
@@ -279,7 +295,8 @@ void geo_layout_cmd_node_perspective(void) {
0x0B: Create a scene graph node that groups other nodes without any
additional functionality
*/
-void geo_layout_cmd_node_start(void) {
+void geo_layout_cmd_node_start(void)
+{
struct GraphNodeStart *graphNode;
graphNode = init_graph_node_start(gGraphNodePool, NULL);
@@ -290,7 +307,8 @@ void geo_layout_cmd_node_start(void) {
}
// 0x1F: No operation
-void geo_layout_cmd_nop3(void) {
+void geo_layout_cmd_nop3(void)
+{
gGeoLayoutCommand += 0x10 << CMD_SIZE_SHIFT;
}
@@ -298,7 +316,8 @@ void geo_layout_cmd_nop3(void) {
0x0C: Create zbuffer-toggling scene graph node
cmd+0x01: u8 enableZBuffer (1 = on, 0 = off)
*/
-void geo_layout_cmd_node_master_list(void) {
+void geo_layout_cmd_node_master_list(void)
+{
struct GraphNodeMasterList *graphNode;
graphNode = init_graph_node_master_list(gGraphNodePool, NULL, cur_geo_cmd_u8(0x01));
@@ -314,7 +333,8 @@ void geo_layout_cmd_node_master_list(void) {
cmd+0x04: s16 minDistance
cmd+0x06: s16 maxDistance
*/
-void geo_layout_cmd_node_level_of_detail(void) {
+void geo_layout_cmd_node_level_of_detail(void)
+{
struct GraphNodeLevelOfDetail *graphNode;
s16 minDistance = cur_geo_cmd_s16(0x04);
s16 maxDistance = cur_geo_cmd_s16(0x06);
@@ -334,15 +354,16 @@ void geo_layout_cmd_node_level_of_detail(void) {
caseSelectorFunc returns an index which is used to select the child node to render.
Used for animating coins, blinking, color selection, etc.
*/
-void geo_layout_cmd_node_switch_case(void) {
+void geo_layout_cmd_node_switch_case(void)
+{
struct GraphNodeSwitchCase *graphNode;
graphNode =
- init_graph_node_switch_case(gGraphNodePool, NULL,
- cur_geo_cmd_s16(0x02), // case which is initially selected
- 0,
- (GraphNodeFunc) cur_geo_cmd_ptr(0x04), // case update function
- 0);
+ init_graph_node_switch_case(gGraphNodePool, NULL,
+ cur_geo_cmd_s16(0x02), // case which is initially selected
+ 0,
+ cur_geo_cmd_ptr(0x04), // case update function
+ 0);
register_scene_graph_node(&graphNode->fnNode.node);
@@ -360,9 +381,10 @@ void geo_layout_cmd_node_switch_case(void) {
cmd+0x0E: s16 focusZ
cmd+0x10: GraphNodeFunc func
*/
-void geo_layout_cmd_node_camera(void) {
+void geo_layout_cmd_node_camera(void)
+{
struct GraphNodeCamera *graphNode;
- s16 *cmdPos = (s16 *) &gGeoLayoutCommand[4];
+ s16 *cmdPos = (s16 *)&gGeoLayoutCommand[4];
Vec3f pos, focus;
@@ -370,7 +392,7 @@ void geo_layout_cmd_node_camera(void) {
cmdPos = read_vec3s_to_vec3f(focus, cmdPos);
graphNode = init_graph_node_camera(gGraphNodePool, NULL, pos, focus,
- (GraphNodeFunc) cur_geo_cmd_ptr(0x10), cur_geo_cmd_s16(0x02));
+ cur_geo_cmd_ptr(0x10), cur_geo_cmd_s16(0x02));
register_scene_graph_node(&graphNode->fnNode.node);
@@ -413,7 +435,8 @@ void geo_layout_cmd_node_camera(void) {
[cmd+var: void *displayList]
*/
-void geo_layout_cmd_node_translation_rotation(void) {
+void geo_layout_cmd_node_translation_rotation(void)
+{
struct GraphNodeTranslationRotation *graphNode;
Vec3s translation, rotation;
@@ -422,9 +445,10 @@ void geo_layout_cmd_node_translation_rotation(void) {
s16 drawingLayer = 0;
s16 params = cur_geo_cmd_u8(0x01);
- s16 *cmdPos = (s16 *) gGeoLayoutCommand;
+ s16 *cmdPos = (s16 *)gGeoLayoutCommand;
- switch ((params & 0x70) >> 4) {
+ switch ((params & 0x70) >> 4)
+ {
case 0:
cmdPos = read_vec3s(translation, &cmdPos[2]);
cmdPos = read_vec3s_angle(rotation, cmdPos);
@@ -444,8 +468,9 @@ void geo_layout_cmd_node_translation_rotation(void) {
break;
}
- if (params & 0x80) {
- displayList = *(void **) &cmdPos[0];
+ if (params & 0x80)
+ {
+ displayList = *(void **)&cmdPos[0];
drawingLayer = params & 0x0F;
cmdPos += 2 << CMD_SIZE_SHIFT;
}
@@ -454,7 +479,7 @@ void geo_layout_cmd_node_translation_rotation(void) {
translation, rotation);
register_scene_graph_node(&graphNode->node);
- gGeoLayoutCommand = (u8 *) cmdPos;
+ gGeoLayoutCommand = (u8 *)cmdPos;
}
/*
@@ -467,30 +492,32 @@ void geo_layout_cmd_node_translation_rotation(void) {
cmd+0x06: s16 zTranslation
[cmd+0x08: void *displayList]
*/
-void geo_layout_cmd_node_translation(void) {
+void geo_layout_cmd_node_translation(void)
+{
struct GraphNodeTranslation *graphNode;
Vec3s translation;
s16 drawingLayer = 0;
s16 params = cur_geo_cmd_u8(0x01);
- s16 *cmdPos = (s16 *) gGeoLayoutCommand;
+ s16 *cmdPos = (s16 *)gGeoLayoutCommand;
void *displayList = NULL;
cmdPos = read_vec3s(translation, &cmdPos[1]);
- if (params & 0x80) {
- displayList = *(void **) &cmdPos[0];
+ if (params & 0x80)
+ {
+ displayList = *(void **)&cmdPos[0];
drawingLayer = params & 0x0F;
cmdPos += 2 << CMD_SIZE_SHIFT;
}
graphNode =
- init_graph_node_translation(gGraphNodePool, NULL, drawingLayer, displayList, translation);
+ init_graph_node_translation(gGraphNodePool, NULL, drawingLayer, displayList, translation);
register_scene_graph_node(&graphNode->node);
- gGeoLayoutCommand = (u8 *) cmdPos;
+ gGeoLayoutCommand = (u8 *)cmdPos;
}
/*
@@ -503,20 +530,22 @@ void geo_layout_cmd_node_translation(void) {
cmd+0x06: s16 unkZ
[cmd+0x08: void *displayList]
*/
-void geo_layout_cmd_node_rotation(void) {
+void geo_layout_cmd_node_rotation(void)
+{
struct GraphNodeRotation *graphNode;
Vec3s sp2c;
s16 drawingLayer = 0;
s16 params = cur_geo_cmd_u8(0x01);
- s16 *cmdPos = (s16 *) gGeoLayoutCommand;
+ s16 *cmdPos = (s16 *)gGeoLayoutCommand;
void *displayList = NULL;
cmdPos = read_vec3s_angle(sp2c, &cmdPos[1]);
- if (params & 0x80) {
- displayList = *(void **) &cmdPos[0];
+ if (params & 0x80)
+ {
+ displayList = *(void **)&cmdPos[0];
drawingLayer = params & 0x0F;
cmdPos += 2 << CMD_SIZE_SHIFT;
}
@@ -525,7 +554,7 @@ void geo_layout_cmd_node_rotation(void) {
register_scene_graph_node(&graphNode->node);
- gGeoLayoutCommand = (u8 *) cmdPos;
+ gGeoLayoutCommand = (u8 *)cmdPos;
}
/*
@@ -536,7 +565,8 @@ void geo_layout_cmd_node_rotation(void) {
cmd+0x04: u32 scale (0x10000 = 1.0)
[cmd+0x08: void *displayList]
*/
-void geo_layout_cmd_node_scale(void) {
+void geo_layout_cmd_node_scale(void)
+{
struct GraphNodeScale *graphNode;
s16 drawingLayer = 0;
@@ -544,7 +574,8 @@ void geo_layout_cmd_node_scale(void) {
f32 scale = cur_geo_cmd_u32(0x04) / 65536.0f;
void *displayList = NULL;
- if (params & 0x80) {
+ if (params & 0x80)
+ {
displayList = cur_geo_cmd_ptr(0x08);
drawingLayer = params & 0x0F;
gGeoLayoutCommand += 4 << CMD_SIZE_SHIFT;
@@ -558,7 +589,8 @@ void geo_layout_cmd_node_scale(void) {
}
// 0x1E: No operation
-void geo_layout_cmd_nop2(void) {
+void geo_layout_cmd_nop2(void)
+{
gGeoLayoutCommand += 0x08 << CMD_SIZE_SHIFT;
}
@@ -570,17 +602,18 @@ void geo_layout_cmd_nop2(void) {
cmd+0x06: s16 zTranslation
cmd+0x08: void *displayList
*/
-void geo_layout_cmd_node_animated_part(void) {
+void geo_layout_cmd_node_animated_part(void)
+{
struct GraphNodeAnimatedPart *graphNode;
Vec3s translation;
s32 drawingLayer = cur_geo_cmd_u8(0x01);
void *displayList = cur_geo_cmd_ptr(0x08);
- s16 *cmdPos = (s16 *) gGeoLayoutCommand;
+ s16 *cmdPos = (s16 *)gGeoLayoutCommand;
read_vec3s(translation, &cmdPos[1]);
graphNode =
- init_graph_node_animated_part(gGraphNodePool, NULL, drawingLayer, displayList, translation);
+ init_graph_node_animated_part(gGraphNodePool, NULL, drawingLayer, displayList, translation);
register_scene_graph_node(&graphNode->node);
@@ -597,18 +630,20 @@ void geo_layout_cmd_node_animated_part(void) {
cmd+0x06: s16 zTranslation
[cmd+0x08: void *displayList]
*/
-void geo_layout_cmd_node_billboard(void) {
+void geo_layout_cmd_node_billboard(void)
+{
struct GraphNodeBillboard *graphNode;
Vec3s translation;
s16 drawingLayer = 0;
s16 params = cur_geo_cmd_u8(0x01);
- s16 *cmdPos = (s16 *) gGeoLayoutCommand;
+ s16 *cmdPos = (s16 *)gGeoLayoutCommand;
void *displayList = NULL;
cmdPos = read_vec3s(translation, &cmdPos[1]);
- if (params & 0x80) {
- displayList = *(void **) &cmdPos[0];
+ if (params & 0x80)
+ {
+ displayList = *(void **)&cmdPos[0];
drawingLayer = params & 0x0F;
cmdPos += 2 << CMD_SIZE_SHIFT;
}
@@ -617,7 +652,7 @@ void geo_layout_cmd_node_billboard(void) {
register_scene_graph_node(&graphNode->node);
- gGeoLayoutCommand = (u8 *) cmdPos;
+ gGeoLayoutCommand = (u8 *)cmdPos;
}
/*
@@ -625,7 +660,8 @@ void geo_layout_cmd_node_billboard(void) {
cmd+0x01: u8 drawingLayer
cmd+0x04: void *displayList
*/
-void geo_layout_cmd_node_display_list(void) {
+void geo_layout_cmd_node_display_list(void)
+{
struct GraphNodeDisplayList *graphNode;
s32 drawingLayer = cur_geo_cmd_u8(0x01);
void *displayList = cur_geo_cmd_ptr(0x04);
@@ -643,7 +679,8 @@ void geo_layout_cmd_node_display_list(void) {
cmd+0x04: s16 shadowSolidity
cmd+0x06: s16 shadowScale
*/
-void geo_layout_cmd_node_shadow(void) {
+void geo_layout_cmd_node_shadow(void)
+{
struct GraphNodeShadow *graphNode;
u8 shadowType = cur_geo_cmd_s16(0x02);
u8 shadowSolidity = cur_geo_cmd_s16(0x04);
@@ -657,7 +694,8 @@ void geo_layout_cmd_node_shadow(void) {
}
// 0x17: Create scene graph node that manages the group of all object nodes
-void geo_layout_cmd_node_object_parent(void) {
+void geo_layout_cmd_node_object_parent(void)
+{
struct GraphNodeObjectParent *graphNode;
graphNode = init_graph_node_object_parent(gGraphNodePool, NULL, &gObjParentGraphNode);
@@ -672,12 +710,13 @@ void geo_layout_cmd_node_object_parent(void) {
cmd+0x02: s16 parameter
cmd+0x04: GraphNodeFunc func
*/
-void geo_layout_cmd_node_generated(void) {
+void geo_layout_cmd_node_generated(void)
+{
struct GraphNodeGenerated *graphNode;
graphNode = init_graph_node_generated(gGraphNodePool, NULL,
- (GraphNodeFunc) cur_geo_cmd_ptr(0x04), // asm function
- cur_geo_cmd_s16(0x02)); // parameter
+ cur_geo_cmd_ptr(0x04), // asm function
+ cur_geo_cmd_s16(0x02)); // parameter
register_scene_graph_node(&graphNode->fnNode.node);
@@ -689,13 +728,14 @@ void geo_layout_cmd_node_generated(void) {
cmd+0x02: s16 background // background ID, or RGBA5551 color if backgroundFunc is null
cmd+0x04: GraphNodeFunc backgroundFunc
*/
-void geo_layout_cmd_node_background(void) {
+void geo_layout_cmd_node_background(void)
+{
struct GraphNodeBackground *graphNode;
graphNode = init_graph_node_background(
gGraphNodePool, NULL,
cur_geo_cmd_s16(0x02), // background ID, or RGBA5551 color if asm function is null
- (GraphNodeFunc) cur_geo_cmd_ptr(0x04), // asm function
+ cur_geo_cmd_ptr(0x04), // asm function
0);
register_scene_graph_node(&graphNode->fnNode.node);
@@ -704,7 +744,8 @@ void geo_layout_cmd_node_background(void) {
}
// 0x1A: No operation
-void geo_layout_cmd_nop(void) {
+void geo_layout_cmd_nop(void)
+{
gGeoLayoutCommand += 0x08 << CMD_SIZE_SHIFT;
}
@@ -713,17 +754,22 @@ void geo_layout_cmd_nop(void) {
to a newly created object parent node.
cmd+0x02: s16 index (of gGeoViews)
*/
-void geo_layout_cmd_copy_view(void) {
+void geo_layout_cmd_copy_view(void)
+{
struct GraphNodeObjectParent *graphNode;
struct GraphNode *node = NULL;
s16 index = cur_geo_cmd_s16(0x02);
- if (index >= 0) {
+ if (index >= 0)
+ {
node = gGeoViews[index];
- if (node->type == GRAPH_NODE_TYPE_OBJECT_PARENT) {
- node = ((struct GraphNodeObjectParent *) node)->sharedChild;
- } else {
+ if (node->type == GRAPH_NODE_TYPE_OBJECT_PARENT)
+ {
+ node = ((struct GraphNodeObjectParent *)node)->sharedChild;
+ }
+ else
+ {
node = NULL;
}
}
@@ -743,14 +789,15 @@ void geo_layout_cmd_copy_view(void) {
cmd+0x06: s16 offsetZ
cmd+0x08: GraphNodeFunc nodeFunc
*/
-void geo_layout_cmd_node_held_obj(void) {
+void geo_layout_cmd_node_held_obj(void)
+{
struct GraphNodeHeldObject *graphNode;
Vec3s offset;
- read_vec3s(offset, (s16 *) &gGeoLayoutCommand[0x02]);
+ read_vec3s(offset, (s16 *)&gGeoLayoutCommand[0x02]);
graphNode = init_graph_node_held_object(
- gGraphNodePool, NULL, NULL, offset, (GraphNodeFunc) cur_geo_cmd_ptr(0x08), cur_geo_cmd_u8(0x01));
+ gGraphNodePool, NULL, NULL, offset, cur_geo_cmd_ptr(0x08), cur_geo_cmd_u8(0x01));
register_scene_graph_node(&graphNode->fnNode.node);
@@ -762,14 +809,16 @@ void geo_layout_cmd_node_held_obj(void) {
is used for frustum culling.
cmd+0x02: s16 cullingRadius
*/
-void geo_layout_cmd_node_culling_radius(void) {
+void geo_layout_cmd_node_culling_radius(void)
+{
struct GraphNodeCullingRadius *graphNode;
graphNode = init_graph_node_culling_radius(gGraphNodePool, NULL, cur_geo_cmd_s16(0x02));
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand += 0x04 << CMD_SIZE_SHIFT;
}
-struct GraphNode *process_geo_layout(struct AllocOnlyPool *pool, void *segptr) {
+struct GraphNode *process_geo_layout(struct AllocOnlyPool *pool, void *segptr)
+{
// set by register_scene_graph_node when gCurGraphNodeIndex is 0
// and gCurRootGraphNode is NULL
gCurRootGraphNode = NULL;
@@ -789,7 +838,8 @@ struct GraphNode *process_geo_layout(struct AllocOnlyPool *pool, void *segptr) {
gGeoLayoutStack[0] = 0;
gGeoLayoutStack[1] = 0;
- while (gGeoLayoutCommand != NULL) {
+ while (gGeoLayoutCommand != NULL)
+ {
GeoLayoutJumpTable[gGeoLayoutCommand[0x00]]();
}
diff --git a/src/decomp/engine/geo_layout.h b/src/decomp/engine/geo_layout.h
index 744f06d..66e758f 100644
--- a/src/decomp/engine/geo_layout.h
+++ b/src/decomp/engine/geo_layout.h
@@ -49,37 +49,69 @@ extern s16 D_8038BD78;
extern struct GraphNode *D_8038BCF8[];
void geo_layout_cmd_branch_and_link(void);
+
void geo_layout_cmd_end(void);
+
void geo_layout_cmd_branch(void);
+
void geo_layout_cmd_return(void);
+
void geo_layout_cmd_open_node(void);
+
void geo_layout_cmd_close_node(void);
+
void geo_layout_cmd_assign_as_view(void);
+
void geo_layout_cmd_update_node_flags(void);
+
void geo_layout_cmd_node_root(void);
+
void geo_layout_cmd_node_ortho_projection(void);
+
void geo_layout_cmd_node_perspective(void);
+
void geo_layout_cmd_node_start(void);
+
void geo_layout_cmd_nop3(void);
+
void geo_layout_cmd_node_master_list(void);
+
void geo_layout_cmd_node_level_of_detail(void);
+
void geo_layout_cmd_node_switch_case(void);
+
void geo_layout_cmd_node_camera(void);
+
void geo_layout_cmd_node_translation_rotation(void);
+
void geo_layout_cmd_node_translation(void);
+
void geo_layout_cmd_node_rotation(void);
+
void geo_layout_cmd_node_scale(void);
+
void geo_layout_cmd_nop2(void);
+
void geo_layout_cmd_node_animated_part(void);
+
void geo_layout_cmd_node_billboard(void);
+
void geo_layout_cmd_node_display_list(void);
+
void geo_layout_cmd_node_shadow(void);
+
void geo_layout_cmd_node_object_parent(void);
+
void geo_layout_cmd_node_generated(void);
+
void geo_layout_cmd_node_background(void);
+
void geo_layout_cmd_nop(void);
+
void geo_layout_cmd_copy_view(void);
+
void geo_layout_cmd_node_held_obj(void);
+
void geo_layout_cmd_node_culling_radius(void);
struct GraphNode *process_geo_layout(struct AllocOnlyPool *a0, void *segptr);
diff --git a/src/decomp/engine/graph_node.c b/src/decomp/engine/graph_node.c
index 8f83638..0ece64b 100644
--- a/src/decomp/engine/graph_node.c
+++ b/src/decomp/engine/graph_node.c
@@ -10,15 +10,16 @@
#include "../shim.h"
// unused Mtx(s)
-static Vec3f gVec3fZero = { 0.0f, 0.0f, 0.0f };
-static Vec3s gVec3sZero = { 0, 0, 0 };
-static Vec3f gVec3fOne = { 1.0f, 1.0f, 1.0f };
+static Vec3f gVec3fZero = {0.0f, 0.0f, 0.0f};
+static Vec3s gVec3sZero = {0, 0, 0};
+static Vec3f gVec3fOne = {1.0f, 1.0f, 1.0f};
/**
* Initialize a geo node with a given type. Sets all links such that there
* are no siblings, parent or children for this node.
*/
-void init_scene_graph_node_links(struct GraphNode *graphNode, s32 type) {
+void init_scene_graph_node_links(struct GraphNode *graphNode, s32 type)
+{
graphNode->type = type;
graphNode->flags = GRAPH_RENDER_ACTIVE;
graphNode->prev = graphNode;
@@ -30,13 +31,17 @@ void init_scene_graph_node_links(struct GraphNode *graphNode, s32 type) {
/**
* Allocated and returns a newly created root node
*/
-struct GraphNodeRoot *init_graph_node_root(struct AllocOnlyPool *pool, struct GraphNodeRoot *graphNode,
- s16 areaIndex, s16 x, s16 y, s16 width, s16 height) {
- if (pool != NULL) {
+struct GraphNodeRoot *init_graph_node_root(
+ struct AllocOnlyPool *pool, struct GraphNodeRoot *graphNode,
+ s16 areaIndex, s16 x, s16 y, s16 width, s16 height)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeRoot));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_ROOT);
graphNode->areaIndex = areaIndex;
@@ -55,14 +60,17 @@ struct GraphNodeRoot *init_graph_node_root(struct AllocOnlyPool *pool, struct Gr
/**
* Allocates and returns a newly created otrhographic projection node
*/
-struct GraphNodeOrthoProjection *
-init_graph_node_ortho_projection(struct AllocOnlyPool *pool, struct GraphNodeOrthoProjection *graphNode,
- f32 scale) {
- if (pool != NULL) {
+struct GraphNodeOrthoProjection *init_graph_node_ortho_projection(
+ struct AllocOnlyPool *pool, struct GraphNodeOrthoProjection *graphNode,
+ f32 scale)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeOrthoProjection));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_ORTHO_PROJECTION);
graphNode->scale = scale;
}
@@ -73,15 +81,19 @@ init_graph_node_ortho_projection(struct AllocOnlyPool *pool, struct GraphNodeOrt
/**
* Allocates and returns a newly created perspective node
*/
-struct GraphNodePerspective *init_graph_node_perspective(struct AllocOnlyPool *pool,
- struct GraphNodePerspective *graphNode,
- f32 fov, s16 near, s16 far,
- GraphNodeFunc nodeFunc, s32 unused) {
- if (pool != NULL) {
+struct GraphNodePerspective *init_graph_node_perspective(
+ struct AllocOnlyPool *pool,
+ struct GraphNodePerspective *graphNode,
+ f32 fov, s16 near, s16 far,
+ GraphNodeFunc nodeFunc, s32 unused)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodePerspective));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->fnNode.node, GRAPH_NODE_TYPE_PERSPECTIVE);
graphNode->fov = fov;
@@ -90,7 +102,8 @@ struct GraphNodePerspective *init_graph_node_perspective(struct AllocOnlyPool *p
graphNode->fnNode.func = nodeFunc;
graphNode->unused = unused;
- if (nodeFunc != NULL) {
+ if (nodeFunc != NULL)
+ {
nodeFunc(GEO_CONTEXT_CREATE, &graphNode->fnNode.node, pool);
}
}
@@ -101,13 +114,17 @@ struct GraphNodePerspective *init_graph_node_perspective(struct AllocOnlyPool *p
/**
* Allocates and returns a newly created start node
*/
-struct GraphNodeStart *init_graph_node_start(struct AllocOnlyPool *pool,
- struct GraphNodeStart *graphNode) {
- if (pool != NULL) {
+struct GraphNodeStart *init_graph_node_start(
+ struct AllocOnlyPool *pool,
+ struct GraphNodeStart *graphNode)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeStart));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_START);
}
@@ -117,16 +134,21 @@ struct GraphNodeStart *init_graph_node_start(struct AllocOnlyPool *pool,
/**
* Allocates and returns a newly created master list node
*/
-struct GraphNodeMasterList *init_graph_node_master_list(struct AllocOnlyPool *pool,
- struct GraphNodeMasterList *graphNode, s16 on) {
- if (pool != NULL) {
+struct GraphNodeMasterList *init_graph_node_master_list(
+ struct AllocOnlyPool *pool,
+ struct GraphNodeMasterList *graphNode, s16 on)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeMasterList));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_MASTER_LIST);
- if (on) {
+ if (on)
+ {
graphNode->node.flags |= GRAPH_RENDER_Z_BUFFER;
}
}
@@ -137,14 +159,18 @@ struct GraphNodeMasterList *init_graph_node_master_list(struct AllocOnlyPool *po
/**
* Allocates and returns a newly created render range node
*/
-struct GraphNodeLevelOfDetail *init_graph_node_render_range(struct AllocOnlyPool *pool,
- struct GraphNodeLevelOfDetail *graphNode,
- s16 minDistance, s16 maxDistance) {
- if (pool != NULL) {
+struct GraphNodeLevelOfDetail *init_graph_node_render_range(
+ struct AllocOnlyPool *pool,
+ struct GraphNodeLevelOfDetail *graphNode,
+ s16 minDistance, s16 maxDistance)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeLevelOfDetail));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_LEVEL_OF_DETAIL);
graphNode->minDistance = minDistance;
graphNode->maxDistance = maxDistance;
@@ -156,22 +182,27 @@ struct GraphNodeLevelOfDetail *init_graph_node_render_range(struct AllocOnlyPool
/**
* Allocates and returns a newly created switch case node
*/
-struct GraphNodeSwitchCase *init_graph_node_switch_case(struct AllocOnlyPool *pool,
- struct GraphNodeSwitchCase *graphNode,
- s16 numCases, s16 selectedCase,
- GraphNodeFunc nodeFunc, s32 unused) {
- if (pool != NULL) {
+struct GraphNodeSwitchCase *init_graph_node_switch_case(
+ struct AllocOnlyPool *pool,
+ struct GraphNodeSwitchCase *graphNode,
+ s16 numCases, s16 selectedCase,
+ GraphNodeFunc nodeFunc, s32 unused)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeSwitchCase));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->fnNode.node, GRAPH_NODE_TYPE_SWITCH_CASE);
graphNode->numCases = numCases;
graphNode->selectedCase = selectedCase;
graphNode->fnNode.func = nodeFunc;
graphNode->unused = unused;
- if (nodeFunc != NULL) {
+ if (nodeFunc != NULL)
+ {
nodeFunc(GEO_CONTEXT_CREATE, &graphNode->fnNode.node, pool);
}
}
@@ -182,14 +213,18 @@ struct GraphNodeSwitchCase *init_graph_node_switch_case(struct AllocOnlyPool *po
/**
* Allocates and returns a newly created camera node
*/
-struct GraphNodeCamera *init_graph_node_camera(struct AllocOnlyPool *pool,
- struct GraphNodeCamera *graphNode, f32 *pos,
- f32 *focus, GraphNodeFunc func, s32 mode) {
- if (pool != NULL) {
+struct GraphNodeCamera *init_graph_node_camera(
+ struct AllocOnlyPool *pool,
+ struct GraphNodeCamera *graphNode, f32 *pos,
+ f32 *focus, GraphNodeFunc func, s32 mode)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeCamera));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->fnNode.node, GRAPH_NODE_TYPE_CAMERA);
vec3f_copy(graphNode->pos, pos);
vec3f_copy(graphNode->focus, focus);
@@ -198,7 +233,8 @@ struct GraphNodeCamera *init_graph_node_camera(struct AllocOnlyPool *pool,
graphNode->roll = 0;
graphNode->rollScreen = 0;
- if (func != NULL) {
+ if (func != NULL)
+ {
func(GEO_CONTEXT_CREATE, &graphNode->fnNode.node, pool);
}
}
@@ -209,20 +245,23 @@ struct GraphNodeCamera *init_graph_node_camera(struct AllocOnlyPool *pool,
/**
* Allocates and returns a newly created translation rotation node
*/
-struct GraphNodeTranslationRotation *
-init_graph_node_translation_rotation(struct AllocOnlyPool *pool,
- struct GraphNodeTranslationRotation *graphNode, s32 drawingLayer,
- void *displayList, Vec3s translation, Vec3s rotation) {
- if (pool != NULL) {
+struct GraphNodeTranslationRotation *init_graph_node_translation_rotation(
+ struct AllocOnlyPool *pool,
+ struct GraphNodeTranslationRotation *graphNode, s32 drawingLayer,
+ void *displayList, Vec3s translation, Vec3s rotation)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeTranslationRotation));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_TRANSLATION_ROTATION);
vec3s_copy(graphNode->translation, translation);
vec3s_copy(graphNode->rotation, rotation);
- graphNode->node.flags = (drawingLayer << 8) | (graphNode->node.flags & 0xFF);
+ graphNode->node.flags = drawingLayer << 8 | graphNode->node.flags & 0xFF;
graphNode->displayList = displayList;
}
@@ -232,19 +271,23 @@ init_graph_node_translation_rotation(struct AllocOnlyPool *pool,
/**
* Allocates and returns a newly created translation node
*/
-struct GraphNodeTranslation *init_graph_node_translation(struct AllocOnlyPool *pool,
- struct GraphNodeTranslation *graphNode,
- s32 drawingLayer, void *displayList,
- Vec3s translation) {
- if (pool != NULL) {
+struct GraphNodeTranslation *init_graph_node_translation(
+ struct AllocOnlyPool *pool,
+ struct GraphNodeTranslation *graphNode,
+ s32 drawingLayer, void *displayList,
+ Vec3s translation)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeTranslation));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_TRANSLATION);
vec3s_copy(graphNode->translation, translation);
- graphNode->node.flags = (drawingLayer << 8) | (graphNode->node.flags & 0xFF);
+ graphNode->node.flags = drawingLayer << 8 | graphNode->node.flags & 0xFF;
graphNode->displayList = displayList;
}
@@ -254,18 +297,22 @@ struct GraphNodeTranslation *init_graph_node_translation(struct AllocOnlyPool *p
/**
* Allocates and returns a newly created rotation node
*/
-struct GraphNodeRotation *init_graph_node_rotation(struct AllocOnlyPool *pool,
- struct GraphNodeRotation *graphNode,
- s32 drawingLayer, void *displayList,
- Vec3s rotation) {
- if (pool != NULL) {
+struct GraphNodeRotation *init_graph_node_rotation(
+ struct AllocOnlyPool *pool,
+ struct GraphNodeRotation *graphNode,
+ s32 drawingLayer, void *displayList,
+ Vec3s rotation)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeRotation));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_ROTATION);
vec3s_copy(graphNode->rotation, rotation);
- graphNode->node.flags = (drawingLayer << 8) | (graphNode->node.flags & 0xFF);
+ graphNode->node.flags = drawingLayer << 8 | graphNode->node.flags & 0xFF;
graphNode->displayList = displayList;
}
@@ -275,16 +322,20 @@ struct GraphNodeRotation *init_graph_node_rotation(struct AllocOnlyPool *pool,
/**
* Allocates and returns a newly created scaling node
*/
-struct GraphNodeScale *init_graph_node_scale(struct AllocOnlyPool *pool,
- struct GraphNodeScale *graphNode, s32 drawingLayer,
- void *displayList, f32 scale) {
- if (pool != NULL) {
+struct GraphNodeScale *init_graph_node_scale(
+ struct AllocOnlyPool *pool,
+ struct GraphNodeScale *graphNode, s32 drawingLayer,
+ void *displayList, f32 scale)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeScale));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_SCALE);
- graphNode->node.flags = (drawingLayer << 8) | (graphNode->node.flags & 0xFF);
+ graphNode->node.flags = drawingLayer << 8 | graphNode->node.flags & 0xFF;
graphNode->scale = scale;
graphNode->displayList = displayList;
}
@@ -295,23 +346,27 @@ struct GraphNodeScale *init_graph_node_scale(struct AllocOnlyPool *pool,
/**
* Allocates and returns a newly created object node
*/
-struct GraphNodeObject *init_graph_node_object(struct AllocOnlyPool *pool,
- struct GraphNodeObject *graphNode,
- struct GraphNode *sharedChild, Vec3f pos, Vec3s angle,
- Vec3f scale) {
- if (pool != NULL) {
+struct GraphNodeObject *init_graph_node_object(
+ struct AllocOnlyPool *pool,
+ struct GraphNodeObject *graphNode,
+ struct GraphNode *sharedChild, Vec3f pos, Vec3s angle,
+ Vec3f scale)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeObject));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_OBJECT);
vec3f_copy(graphNode->pos, pos);
vec3f_copy(graphNode->scale, scale);
vec3s_copy(graphNode->angle, angle);
-#ifdef USE_SYSTEM_MALLOC
+ #ifdef USE_SYSTEM_MALLOC
// To avoid uninitialised memory usage in audio code
vec3f_copy(graphNode->cameraToObject, gVec3fZero);
-#endif
+ #endif
graphNode->sharedChild = sharedChild;
graphNode->throwMatrix = NULL;
graphNode->animInfo.animID = 0;
@@ -329,14 +384,18 @@ struct GraphNodeObject *init_graph_node_object(struct AllocOnlyPool *pool,
/**
* Allocates and returns a newly created frustum culling radius node
*/
-struct GraphNodeCullingRadius *init_graph_node_culling_radius(struct AllocOnlyPool *pool,
- struct GraphNodeCullingRadius *graphNode,
- s16 radius) {
- if (pool != NULL) {
+struct GraphNodeCullingRadius *init_graph_node_culling_radius(
+ struct AllocOnlyPool *pool,
+ struct GraphNodeCullingRadius *graphNode,
+ s16 radius)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeCullingRadius));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_CULLING_RADIUS);
graphNode->cullingRadius = radius;
}
@@ -347,18 +406,22 @@ struct GraphNodeCullingRadius *init_graph_node_culling_radius(struct AllocOnlyPo
/**
* Allocates and returns a newly created animated part node
*/
-struct GraphNodeAnimatedPart *init_graph_node_animated_part(struct AllocOnlyPool *pool,
- struct GraphNodeAnimatedPart *graphNode,
- s32 drawingLayer, void *displayList,
- Vec3s translation) {
- if (pool != NULL) {
+struct GraphNodeAnimatedPart *init_graph_node_animated_part(
+ struct AllocOnlyPool *pool,
+ struct GraphNodeAnimatedPart *graphNode,
+ s32 drawingLayer, void *displayList,
+ Vec3s translation)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeAnimatedPart));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_ANIMATED_PART);
vec3s_copy(graphNode->translation, translation);
- graphNode->node.flags = (drawingLayer << 8) | (graphNode->node.flags & 0xFF);
+ graphNode->node.flags = drawingLayer << 8 | graphNode->node.flags & 0xFF;
graphNode->displayList = displayList;
}
@@ -368,18 +431,22 @@ struct GraphNodeAnimatedPart *init_graph_node_animated_part(struct AllocOnlyPool
/**
* Allocates and returns a newly created billboard node
*/
-struct GraphNodeBillboard *init_graph_node_billboard(struct AllocOnlyPool *pool,
- struct GraphNodeBillboard *graphNode,
- s32 drawingLayer, void *displayList,
- Vec3s translation) {
- if (pool != NULL) {
+struct GraphNodeBillboard *init_graph_node_billboard(
+ struct AllocOnlyPool *pool,
+ struct GraphNodeBillboard *graphNode,
+ s32 drawingLayer, void *displayList,
+ Vec3s translation)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeBillboard));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_BILLBOARD);
vec3s_copy(graphNode->translation, translation);
- graphNode->node.flags = (drawingLayer << 8) | (graphNode->node.flags & 0xFF);
+ graphNode->node.flags = drawingLayer << 8 | graphNode->node.flags & 0xFF;
graphNode->displayList = displayList;
}
@@ -389,16 +456,20 @@ struct GraphNodeBillboard *init_graph_node_billboard(struct AllocOnlyPool *pool,
/**
* Allocates and returns a newly created displaylist node
*/
-struct GraphNodeDisplayList *init_graph_node_display_list(struct AllocOnlyPool *pool,
- struct GraphNodeDisplayList *graphNode,
- s32 drawingLayer, void *displayList) {
- if (pool != NULL) {
+struct GraphNodeDisplayList *init_graph_node_display_list(
+ struct AllocOnlyPool *pool,
+ struct GraphNodeDisplayList *graphNode,
+ s32 drawingLayer, void *displayList)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeDisplayList));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_DISPLAY_LIST);
- graphNode->node.flags = (drawingLayer << 8) | (graphNode->node.flags & 0xFF);
+ graphNode->node.flags = drawingLayer << 8 | graphNode->node.flags & 0xFF;
graphNode->displayList = displayList;
}
@@ -408,14 +479,18 @@ struct GraphNodeDisplayList *init_graph_node_display_list(struct AllocOnlyPool *
/**
* Allocates and returns a newly created shadow node
*/
-struct GraphNodeShadow *init_graph_node_shadow(struct AllocOnlyPool *pool,
- struct GraphNodeShadow *graphNode, s16 shadowScale,
- u8 shadowSolidity, u8 shadowType) {
- if (pool != NULL) {
+struct GraphNodeShadow *init_graph_node_shadow(
+ struct AllocOnlyPool *pool,
+ struct GraphNodeShadow *graphNode, s16 shadowScale,
+ u8 shadowSolidity, u8 shadowType)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeShadow));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_SHADOW);
graphNode->shadowScale = shadowScale;
graphNode->shadowSolidity = shadowSolidity;
@@ -428,14 +503,18 @@ struct GraphNodeShadow *init_graph_node_shadow(struct AllocOnlyPool *pool,
/**
* Allocates and returns a newly created object parent node
*/
-struct GraphNodeObjectParent *init_graph_node_object_parent(struct AllocOnlyPool *pool,
- struct GraphNodeObjectParent *graphNode,
- struct GraphNode *sharedChild) {
- if (pool != NULL) {
+struct GraphNodeObjectParent *init_graph_node_object_parent(
+ struct AllocOnlyPool *pool,
+ struct GraphNodeObjectParent *graphNode,
+ struct GraphNode *sharedChild)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeObjectParent));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_OBJECT_PARENT);
graphNode->sharedChild = sharedChild;
}
@@ -446,19 +525,24 @@ struct GraphNodeObjectParent *init_graph_node_object_parent(struct AllocOnlyPool
/**
* Allocates and returns a newly created generated node
*/
-struct GraphNodeGenerated *init_graph_node_generated(struct AllocOnlyPool *pool,
- struct GraphNodeGenerated *graphNode,
- GraphNodeFunc gfxFunc, s32 parameter) {
- if (pool != NULL) {
+struct GraphNodeGenerated *init_graph_node_generated(
+ struct AllocOnlyPool *pool,
+ struct GraphNodeGenerated *graphNode,
+ GraphNodeFunc gfxFunc, s32 parameter)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeGenerated));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->fnNode.node, GRAPH_NODE_TYPE_GENERATED_LIST);
graphNode->fnNode.func = gfxFunc;
graphNode->parameter = parameter;
- if (gfxFunc != NULL) {
+ if (gfxFunc != NULL)
+ {
gfxFunc(GEO_CONTEXT_CREATE, &graphNode->fnNode.node, pool);
}
}
@@ -469,22 +553,27 @@ struct GraphNodeGenerated *init_graph_node_generated(struct AllocOnlyPool *pool,
/**
* Allocates and returns a newly created background node
*/
-struct GraphNodeBackground *init_graph_node_background(struct AllocOnlyPool *pool,
- struct GraphNodeBackground *graphNode,
- u16 background, GraphNodeFunc backgroundFunc,
- s32 zero) {
- if (pool != NULL) {
+struct GraphNodeBackground *init_graph_node_background(
+ struct AllocOnlyPool *pool,
+ struct GraphNodeBackground *graphNode,
+ u16 background, GraphNodeFunc backgroundFunc,
+ s32 zero)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeBackground));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->fnNode.node, GRAPH_NODE_TYPE_BACKGROUND);
- graphNode->background = (background << 16) | background;
+ graphNode->background = background << 16 | background;
graphNode->fnNode.func = backgroundFunc;
graphNode->unused = zero; // always 0, unused
- if (backgroundFunc != NULL) {
+ if (backgroundFunc != NULL)
+ {
backgroundFunc(GEO_CONTEXT_CREATE, &graphNode->fnNode.node, pool);
}
}
@@ -495,23 +584,28 @@ struct GraphNodeBackground *init_graph_node_background(struct AllocOnlyPool *poo
/**
* Allocates and returns a newly created held object node
*/
-struct GraphNodeHeldObject *init_graph_node_held_object(struct AllocOnlyPool *pool,
- struct GraphNodeHeldObject *graphNode,
- struct Object *objNode,
- Vec3s translation,
- GraphNodeFunc nodeFunc, s32 playerIndex) {
- if (pool != NULL) {
+struct GraphNodeHeldObject *init_graph_node_held_object(
+ struct AllocOnlyPool *pool,
+ struct GraphNodeHeldObject *graphNode,
+ struct Object *objNode,
+ Vec3s translation,
+ GraphNodeFunc nodeFunc, s32 playerIndex)
+{
+ if (pool != NULL)
+ {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeHeldObject));
}
- if (graphNode != NULL) {
+ if (graphNode != NULL)
+ {
init_scene_graph_node_links(&graphNode->fnNode.node, GRAPH_NODE_TYPE_HELD_OBJ);
vec3s_copy(graphNode->translation, translation);
graphNode->objNode = objNode;
graphNode->fnNode.func = nodeFunc;
graphNode->playerIndex = playerIndex;
- if (nodeFunc != NULL) {
+ if (nodeFunc != NULL)
+ {
nodeFunc(GEO_CONTEXT_CREATE, &graphNode->fnNode.node, pool);
}
}
@@ -522,19 +616,24 @@ struct GraphNodeHeldObject *init_graph_node_held_object(struct AllocOnlyPool *po
/**
* Adds 'childNode' to the end of the list children from 'parent'
*/
-struct GraphNode *geo_add_child(struct GraphNode *parent, struct GraphNode *childNode) {
+struct GraphNode *geo_add_child(struct GraphNode *parent, struct GraphNode *childNode)
+{
struct GraphNode *parentFirstChild;
struct GraphNode *parentLastChild;
- if (childNode != NULL) {
+ if (childNode != NULL)
+ {
childNode->parent = parent;
parentFirstChild = parent->children;
- if (parentFirstChild == NULL) {
+ if (parentFirstChild == NULL)
+ {
parent->children = childNode;
childNode->prev = childNode;
childNode->next = childNode;
- } else {
+ }
+ else
+ {
parentLastChild = parentFirstChild->prev;
childNode->prev = parentLastChild;
childNode->next = parentFirstChild;
@@ -552,7 +651,8 @@ struct GraphNode *geo_add_child(struct GraphNode *parent, struct GraphNode *chil
* since geo nodes are allocated in a pointer-bumping pool that
* gets thrown out when changing areas.
*/
-struct GraphNode *geo_remove_child(struct GraphNode *graphNode) {
+struct GraphNode *geo_remove_child(struct GraphNode *graphNode)
+{
struct GraphNode *parent;
struct GraphNode **firstChild;
@@ -564,11 +664,15 @@ struct GraphNode *geo_remove_child(struct GraphNode *graphNode) {
graphNode->next->prev = graphNode->prev;
// If this node was the first child, a new first child must be chosen
- if (*firstChild == graphNode) {
+ if (*firstChild == graphNode)
+ {
// The list is circular, so this checks whether it was the only child
- if (graphNode->next == graphNode) {
+ if (graphNode->next == graphNode)
+ {
*firstChild = NULL; // Parent has no children anymore
- } else {
+ }
+ else
+ {
*firstChild = graphNode->next; // Choose a new first child
}
}
@@ -582,7 +686,8 @@ struct GraphNode *geo_remove_child(struct GraphNode *graphNode) {
* object is always drawn before any other objects. (Note that the geo order
* is independent from processing group order, where Mario is not first.)
*/
-struct GraphNode *geo_make_first_child(struct GraphNode *newFirstChild) {
+struct GraphNode *geo_make_first_child(struct GraphNode *newFirstChild)
+{
struct GraphNode *lastSibling;
struct GraphNode *parent;
struct GraphNode **firstChild;
@@ -590,8 +695,10 @@ struct GraphNode *geo_make_first_child(struct GraphNode *newFirstChild) {
parent = newFirstChild->parent;
firstChild = &parent->children;
- if (*firstChild != newFirstChild) {
- if ((*firstChild)->prev != newFirstChild) {
+ if (*firstChild != newFirstChild)
+ {
+ if ((*firstChild)->prev != newFirstChild)
+ {
newFirstChild->prev->next = newFirstChild->next;
newFirstChild->next->prev = newFirstChild->prev;
lastSibling = (*firstChild)->prev;
@@ -610,52 +717,61 @@ struct GraphNode *geo_make_first_child(struct GraphNode *newFirstChild) {
* Helper function for geo_call_global_function_nodes that recursively
* traverses the scene graph and calls the functions of global nodes.
*/
-void geo_call_global_function_nodes_helper(struct GraphNode *graphNode, s32 callContext) {
+void geo_call_global_function_nodes_helper(struct GraphNode *graphNode, s32 callContext)
+{
struct GraphNode **globalPtr;
struct GraphNode *curNode;
struct FnGraphNode *asFnNode;
curNode = graphNode;
- do {
- asFnNode = (struct FnGraphNode *) curNode;
+ do
+ {
+ asFnNode = (struct FnGraphNode *)curNode;
- if (curNode->type & GRAPH_NODE_TYPE_FUNCTIONAL) {
- if (asFnNode->func != NULL) {
+ if (curNode->type & GRAPH_NODE_TYPE_FUNCTIONAL)
+ {
+ if (asFnNode->func != NULL)
+ {
asFnNode->func(callContext, curNode, NULL);
}
}
- if (curNode->children != NULL) {
- switch (curNode->type) {
+ if (curNode->children != NULL)
+ {
+ switch (curNode->type)
+ {
case GRAPH_NODE_TYPE_MASTER_LIST:
- globalPtr = (struct GraphNode **) &gCurGraphNodeMasterList;
+ globalPtr = (struct GraphNode **)&gCurGraphNodeMasterList;
break;
case GRAPH_NODE_TYPE_PERSPECTIVE:
- globalPtr = (struct GraphNode **) &gCurGraphNodeCamFrustum;
+ globalPtr = (struct GraphNode **)&gCurGraphNodeCamFrustum;
break;
case GRAPH_NODE_TYPE_CAMERA:
- globalPtr = (struct GraphNode **) &gCurGraphNodeCamera;
+ globalPtr = (struct GraphNode **)&gCurGraphNodeCamera;
break;
case GRAPH_NODE_TYPE_OBJECT:
- globalPtr = (struct GraphNode **) &gCurGraphNodeObject;
+ globalPtr = (struct GraphNode **)&gCurGraphNodeObject;
break;
default:
globalPtr = NULL;
break;
}
- if (globalPtr != NULL) {
+ if (globalPtr != NULL)
+ {
*globalPtr = curNode;
}
geo_call_global_function_nodes_helper(curNode->children, callContext);
- if (globalPtr != NULL) {
+ if (globalPtr != NULL)
+ {
*globalPtr = NULL;
}
}
- } while ((curNode = curNode->next) != graphNode);
+ }
+ while ((curNode = curNode->next) != graphNode);
}
/**
@@ -665,11 +781,14 @@ void geo_call_global_function_nodes_helper(struct GraphNode *graphNode, s32 call
* callContext is one of the GEO_CONTEXT_ defines.
* The graphNode argument should be of type GraphNodeRoot.
*/
-void geo_call_global_function_nodes(struct GraphNode *graphNode, s32 callContext) {
- if (graphNode->flags & GRAPH_RENDER_ACTIVE) {
- gCurGraphNodeRoot = (struct GraphNodeRoot *) graphNode;
+void geo_call_global_function_nodes(struct GraphNode *graphNode, s32 callContext)
+{
+ if (graphNode->flags & GRAPH_RENDER_ACTIVE)
+ {
+ gCurGraphNodeRoot = (struct GraphNodeRoot *)graphNode;
- if (graphNode->children != NULL) {
+ if (graphNode->children != NULL)
+ {
geo_call_global_function_nodes_helper(graphNode->children, callContext);
}
@@ -680,7 +799,8 @@ void geo_call_global_function_nodes(struct GraphNode *graphNode, s32 callContext
/**
* When objects are cleared, this is called on all object nodes (loaded or unloaded).
*/
-void geo_reset_object_node(struct GraphNodeObject *graphNode) {
+void geo_reset_object_node(struct GraphNodeObject *graphNode)
+{
init_graph_node_object(NULL, graphNode, 0, gVec3fZero, gVec3sZero, gVec3fOne);
geo_add_child(&gObjParentGraphNode, &graphNode->node);
@@ -690,7 +810,8 @@ void geo_reset_object_node(struct GraphNodeObject *graphNode) {
/**
* Initialize an object node using the given parameters
*/
-void geo_obj_init(struct GraphNodeObject *graphNode, void *sharedChild, Vec3f pos, Vec3s angle) {
+void geo_obj_init(struct GraphNodeObject *graphNode, void *sharedChild, Vec3f pos, Vec3s angle)
+{
vec3f_set(graphNode->scale, 1.0f, 1.0f, 1.0f);
vec3f_copy(graphNode->pos, pos);
vec3s_copy(graphNode->angle, angle);
@@ -709,13 +830,14 @@ void geo_obj_init(struct GraphNodeObject *graphNode, void *sharedChild, Vec3f po
/**
* Initialize and object node using the given SpawnInfo struct
*/
-void geo_obj_init_spawninfo(struct GraphNodeObject *graphNode, struct SpawnInfo *spawn) {
+void geo_obj_init_spawninfo(struct GraphNodeObject *graphNode, struct SpawnInfo *spawn)
+{
vec3f_set(graphNode->scale, 1.0f, 1.0f, 1.0f);
vec3s_copy(graphNode->angle, spawn->startAngle);
- graphNode->pos[0] = (f32) spawn->startPos[0];
- graphNode->pos[1] = (f32) spawn->startPos[1];
- graphNode->pos[2] = (f32) spawn->startPos[2];
+ graphNode->pos[0] = spawn->startPos[0];
+ graphNode->pos[1] = spawn->startPos[1];
+ graphNode->pos[2] = spawn->startPos[2];
graphNode->areaIndex = spawn->areaIndex;
graphNode->activeAreaIndex = spawn->activeAreaIndex;
@@ -733,13 +855,15 @@ void geo_obj_init_spawninfo(struct GraphNodeObject *graphNode, struct SpawnInfo
/**
* Initialize the animation of an object node
*/
-void geo_obj_init_animation(struct GraphNodeObject *graphNode, struct Animation **animPtrAddr) {
+void geo_obj_init_animation(struct GraphNodeObject *graphNode, struct Animation **animPtrAddr)
+{
struct Animation **animSegmented = segmented_to_virtual(animPtrAddr);
struct Animation *anim = segmented_to_virtual(*animSegmented);
- if (graphNode->animInfo.curAnim != anim) {
+ if (graphNode->animInfo.curAnim != anim)
+ {
graphNode->animInfo.curAnim = anim;
- graphNode->animInfo.animFrame = anim->startFrame + ((anim->flags & ANIM_FLAG_FORWARD) ? 1 : -1);
+ graphNode->animInfo.animFrame = anim->startFrame + (anim->flags & ANIM_FLAG_FORWARD ? 1 : -1);
graphNode->animInfo.animAccel = 0;
graphNode->animInfo.animYTrans = 0;
}
@@ -748,15 +872,17 @@ void geo_obj_init_animation(struct GraphNodeObject *graphNode, struct Animation
/**
* Initialize the animation of an object node
*/
-void geo_obj_init_animation_accel(struct GraphNodeObject *graphNode, struct Animation **animPtrAddr, u32 animAccel) {
+void geo_obj_init_animation_accel(struct GraphNodeObject *graphNode, struct Animation **animPtrAddr, u32 animAccel)
+{
struct Animation **animSegmented = segmented_to_virtual(animPtrAddr);
struct Animation *anim = segmented_to_virtual(*animSegmented);
- if (graphNode->animInfo.curAnim != anim) {
+ if (graphNode->animInfo.curAnim != anim)
+ {
graphNode->animInfo.curAnim = anim;
graphNode->animInfo.animYTrans = 0;
graphNode->animInfo.animFrameAccelAssist =
- (anim->startFrame << 16) + ((anim->flags & ANIM_FLAG_FORWARD) ? animAccel : -animAccel);
+ (anim->startFrame << 16) + (anim->flags & ANIM_FLAG_FORWARD ? animAccel : -animAccel);
graphNode->animInfo.animFrame = graphNode->animInfo.animFrameAccelAssist >> 16;
}
@@ -770,12 +896,16 @@ void geo_obj_init_animation_accel(struct GraphNodeObject *graphNode, struct Anim
* and the second s16 the actual index. This index can be used to index in the array
* with actual animation values.
*/
-s32 retrieve_animation_index(s32 frame, u16 **attributes) {
+s32 retrieve_animation_index(s32 frame, u16 **attributes)
+{
s32 result;
- if (frame < (*attributes)[0]) {
+ if (frame < (*attributes)[0])
+ {
result = (*attributes)[1] + frame;
- } else {
+ }
+ else
+ {
result = (*attributes)[1] + (*attributes)[0] - 1;
}
@@ -789,51 +919,72 @@ s32 retrieve_animation_index(s32 frame, u16 **attributes) {
* whether it plays forwards or backwards, and whether it stops or loops at
* the end etc.
*/
-s16 geo_update_animation_frame(struct AnimInfo *obj, s32 *accelAssist) {
+s16 geo_update_animation_frame(struct AnimInfo *obj, s32 *accelAssist)
+{
s32 result;
struct Animation *anim;
anim = obj->curAnim;
- if (obj->animTimer == gAreaUpdateCounter || anim->flags & ANIM_FLAG_2) {
- if (accelAssist != NULL) {
+ if (obj->animTimer == gAreaUpdateCounter || anim->flags & ANIM_FLAG_2)
+ {
+ if (accelAssist != NULL)
+ {
accelAssist[0] = obj->animFrameAccelAssist;
}
return obj->animFrame;
}
- if (anim->flags & ANIM_FLAG_FORWARD) {
- if (obj->animAccel) {
+ if (anim->flags & ANIM_FLAG_FORWARD)
+ {
+ if (obj->animAccel)
+ {
result = obj->animFrameAccelAssist - obj->animAccel;
- } else {
+ }
+ else
+ {
result = (obj->animFrame - 1) << 16;
}
- if (GET_HIGH_S16_OF_32(result) < anim->loopStart) {
- if (anim->flags & ANIM_FLAG_NOLOOP) {
+ if (GET_HIGH_S16_OF_32(result) < anim->loopStart)
+ {
+ if (anim->flags & ANIM_FLAG_NOLOOP)
+ {
SET_HIGH_S16_OF_32(result, anim->loopStart);
- } else {
+ }
+ else
+ {
SET_HIGH_S16_OF_32(result, anim->loopEnd - 1);
}
}
- } else {
- if (obj->animAccel != 0) {
+ }
+ else
+ {
+ if (obj->animAccel != 0)
+ {
result = obj->animFrameAccelAssist + obj->animAccel;
- } else {
+ }
+ else
+ {
result = (obj->animFrame + 1) << 16;
}
- if (GET_HIGH_S16_OF_32(result) >= anim->loopEnd) {
- if (anim->flags & ANIM_FLAG_NOLOOP) {
+ if (GET_HIGH_S16_OF_32(result) >= anim->loopEnd)
+ {
+ if (anim->flags & ANIM_FLAG_NOLOOP)
+ {
SET_HIGH_S16_OF_32(result, anim->loopEnd - 1);
- } else {
+ }
+ else
+ {
SET_HIGH_S16_OF_32(result, anim->loopStart);
}
}
}
- if (accelAssist != 0) {
+ if (accelAssist != 0)
+ {
accelAssist[0] = result;
}
@@ -848,29 +999,34 @@ s16 geo_update_animation_frame(struct AnimInfo *obj, s32 *accelAssist) {
* currently happens in-line in geo_process_shadow where it also accounts for
* animations without lateral translation.
*/
-void geo_retreive_animation_translation(struct GraphNodeObject *obj, Vec3f position) {
+void geo_retreive_animation_translation(struct GraphNodeObject *obj, Vec3f position)
+{
struct Animation *animation = obj->animInfo.curAnim;
u16 *attribute;
s16 *values;
s16 frame;
- if (animation != NULL) {
- attribute = segmented_to_virtual((void *) animation->index);
- values = segmented_to_virtual((void *) animation->values);
+ if (animation != NULL)
+ {
+ attribute = segmented_to_virtual(animation->index);
+ values = segmented_to_virtual(animation->values);
frame = obj->animInfo.animFrame;
- if (frame < 0) {
+ if (frame < 0)
+ {
frame = 0;
}
if (1) // ? necessary to match
{
- position[0] = (f32) values[retrieve_animation_index(frame, &attribute)];
- position[1] = (f32) values[retrieve_animation_index(frame, &attribute)];
- position[2] = (f32) values[retrieve_animation_index(frame, &attribute)];
+ position[0] = (f32)values[retrieve_animation_index(frame, &attribute)];
+ position[1] = (f32)values[retrieve_animation_index(frame, &attribute)];
+ position[2] = (f32)values[retrieve_animation_index(frame, &attribute)];
}
- } else {
+ }
+ else
+ {
vec3f_set(position, 0, 0, 0);
}
}
@@ -879,15 +1035,18 @@ void geo_retreive_animation_translation(struct GraphNodeObject *obj, Vec3f posit
* Unused function to find the root of the geo node tree, which should be a
* GraphNodeRoot. If it is not for some reason, null is returned.
*/
-struct GraphNodeRoot *geo_find_root(struct GraphNode *graphNode) {
+struct GraphNodeRoot *geo_find_root(struct GraphNode *graphNode)
+{
struct GraphNodeRoot *resGraphNode = NULL;
- while (graphNode->parent != NULL) {
+ while (graphNode->parent != NULL)
+ {
graphNode = graphNode->parent;
}
- if (graphNode->type == GRAPH_NODE_TYPE_ROOT) {
- resGraphNode = (struct GraphNodeRoot *) graphNode;
+ if (graphNode->type == GRAPH_NODE_TYPE_ROOT)
+ {
+ resGraphNode = (struct GraphNodeRoot *)graphNode;
}
return resGraphNode;
diff --git a/src/decomp/engine/graph_node.h b/src/decomp/engine/graph_node.h
index a77007d..29e60ee 100644
--- a/src/decomp/engine/graph_node.h
+++ b/src/decomp/engine/graph_node.h
@@ -18,7 +18,7 @@
#define GRAPH_NODE_TYPE_FUNCTIONAL 0x100
// Type used for Bowser and an unused geo function in obj_behaviors.c
-#define GRAPH_NODE_TYPE_400 0x400
+#define GRAPH_NODE_TYPE_400 0x400
// The discriminant for different types of geo nodes
#define GRAPH_NODE_TYPE_ROOT 0x001
@@ -70,23 +70,34 @@ typedef Gfx *(*GraphNodeFunc)(s32 callContext, struct GraphNode *node, void *con
*/
struct FnGraphNode
{
- /*0x00*/ struct GraphNode node;
- /*0x14*/ GraphNodeFunc func;
+ /*0x00*/
+ struct GraphNode node;
+ /*0x14*/
+ GraphNodeFunc func;
};
/** The very root of the geo tree. Specifies the viewport.
*/
struct GraphNodeRoot
{
- /*0x00*/ struct GraphNode node;
- /*0x14*/ u8 areaIndex;
- /*0x15*/ s8 unk15; // ?
- /*0x16*/ s16 x;
- /*0x18*/ s16 y;
- /*0x1A*/ s16 width; // half width, 160
- /*0x1C*/ s16 height; // half height
- /*0x1E*/ s16 numViews; // number of entries in mystery array
- /*0x20*/ struct GraphNode **views;
+ /*0x00*/
+ struct GraphNode node;
+ /*0x14*/
+ u8 areaIndex;
+ /*0x15*/
+ s8 unk15; // ?
+ /*0x16*/
+ s16 x;
+ /*0x18*/
+ s16 y;
+ /*0x1A*/
+ s16 width; // half width, 160
+ /*0x1C*/
+ s16 height; // half height
+ /*0x1E*/
+ s16 numViews; // number of entries in mystery array
+ /*0x20*/
+ struct GraphNode **views;
};
/** A node that sets up an orthographic projection based on the global
@@ -94,8 +105,10 @@ struct GraphNodeRoot
*/
struct GraphNodeOrthoProjection
{
- /*0x00*/ struct GraphNode node;
- /*0x14*/ f32 scale;
+ /*0x00*/
+ struct GraphNode node;
+ /*0x14*/
+ f32 scale;
};
/** A node that sets up a perspective projection. Used for drawing the
@@ -104,11 +117,16 @@ struct GraphNodeOrthoProjection
*/
struct GraphNodePerspective
{
- /*0x00*/ struct FnGraphNode fnNode;
- /*0x18*/ s32 unused;
- /*0x1C*/ f32 fov; // horizontal field of view in degrees
- /*0x20*/ s16 near; // near clipping plane
- /*0x22*/ s16 far; // far clipping plane
+ /*0x00*/
+ struct FnGraphNode fnNode;
+ /*0x18*/
+ s32 unused;
+ /*0x1C*/
+ f32 fov; // horizontal field of view in degrees
+ /*0x20*/
+ s16 near; // near clipping plane
+ /*0x22*/
+ s16 far; // far clipping plane
};
/** An entry in the master list. It is a linked list of display lists
@@ -128,9 +146,12 @@ struct DisplayListNode
*/
struct GraphNodeMasterList
{
- /*0x00*/ struct GraphNode node;
- /*0x14*/ struct DisplayListNode *listHeads[GFX_NUM_MASTER_LISTS];
- /*0x34*/ struct DisplayListNode *listTails[GFX_NUM_MASTER_LISTS];
+ /*0x00*/
+ struct GraphNode node;
+ /*0x14*/
+ struct DisplayListNode *listHeads[GFX_NUM_MASTER_LISTS];
+ /*0x34*/
+ struct DisplayListNode *listTails[GFX_NUM_MASTER_LISTS];
};
/** Simply used as a parent to group multiple children.
@@ -138,7 +159,8 @@ struct GraphNodeMasterList
*/
struct GraphNodeStart
{
- /*0x00*/ struct GraphNode node;
+ /*0x00*/
+ struct GraphNode node;
};
/** GraphNode that only renders its children if the current transformation matrix
@@ -149,9 +171,12 @@ struct GraphNodeStart
*/
struct GraphNodeLevelOfDetail
{
- /*0x00*/ struct GraphNode node;
- /*0x14*/ s16 minDistance;
- /*0x16*/ s16 maxDistance;
+ /*0x00*/
+ struct GraphNode node;
+ /*0x14*/
+ s16 minDistance;
+ /*0x16*/
+ s16 maxDistance;
};
/** GraphNode that renders exactly one of its children.
@@ -161,10 +186,14 @@ struct GraphNodeLevelOfDetail
*/
struct GraphNodeSwitchCase
{
- /*0x00*/ struct FnGraphNode fnNode;
- /*0x18*/ s32 unused;
- /*0x1C*/ s16 numCases;
- /*0x1E*/ s16 selectedCase;
+ /*0x00*/
+ struct FnGraphNode fnNode;
+ /*0x18*/
+ s32 unused;
+ /*0x1C*/
+ s16 numCases;
+ /*0x1E*/
+ s16 selectedCase;
};
/**
@@ -173,8 +202,12 @@ struct GraphNodeSwitchCase
*/
struct GraphNodeCamera
{
- /*0x00*/ struct FnGraphNode fnNode;
- /*0x18*/ union {
+ /*0x00*/
+ struct FnGraphNode fnNode;
+
+ /*0x18*/
+ union
+ {
// When the node is created, a mode is assigned to the node.
// Later in geo_camera_main a Camera is allocated,
// the mode is passed to the struct, and the field is overridden
@@ -182,11 +215,17 @@ struct GraphNodeCamera
s32 mode;
struct Camera *camera;
} config;
- /*0x1C*/ Vec3f pos;
- /*0x28*/ Vec3f focus;
- /*0x34*/ Mat4 *matrixPtr; // pointer to look-at matrix of this camera as a Mat4
- /*0x38*/ s16 roll; // roll in look at matrix. Doesn't account for light direction unlike rollScreen.
- /*0x3A*/ s16 rollScreen; // rolls screen while keeping the light direction consistent
+
+ /*0x1C*/
+ Vec3f pos;
+ /*0x28*/
+ Vec3f focus;
+ /*0x34*/
+ Mat4 *matrixPtr; // pointer to look-at matrix of this camera as a Mat4
+ /*0x38*/
+ s16 roll; // roll in look at matrix. Doesn't account for light direction unlike rollScreen.
+ /*0x3A*/
+ s16 rollScreen; // rolls screen while keeping the light direction consistent
};
/** GraphNode that translates and rotates its children.
@@ -197,10 +236,14 @@ struct GraphNodeCamera
*/
struct GraphNodeTranslationRotation
{
- /*0x00*/ struct GraphNode node;
- /*0x14*/ void *displayList;
- /*0x18*/ Vec3s translation;
- /*0x1E*/ Vec3s rotation;
+ /*0x00*/
+ struct GraphNode node;
+ /*0x14*/
+ void *displayList;
+ /*0x18*/
+ Vec3s translation;
+ /*0x1E*/
+ Vec3s rotation;
};
/** GraphNode that translates itself and its children.
@@ -209,9 +252,12 @@ struct GraphNodeTranslationRotation
*/
struct GraphNodeTranslation
{
- /*0x00*/ struct GraphNode node;
- /*0x14*/ void *displayList;
- /*0x18*/ Vec3s translation;
+ /*0x00*/
+ struct GraphNode node;
+ /*0x14*/
+ void *displayList;
+ /*0x18*/
+ Vec3s translation;
u8 pad1E[2];
};
@@ -222,9 +268,12 @@ struct GraphNodeTranslation
*/
struct GraphNodeRotation
{
- /*0x00*/ struct GraphNode node;
- /*0x14*/ void *displayList;
- /*0x18*/ Vec3s rotation;
+ /*0x00*/
+ struct GraphNode node;
+ /*0x14*/
+ void *displayList;
+ /*0x18*/
+ Vec3s rotation;
u8 pad1E[2];
};
@@ -237,9 +286,12 @@ struct GraphNodeRotation
*/
struct GraphNodeAnimatedPart
{
- /*0x00*/ struct GraphNode node;
- /*0x14*/ void *displayList;
- /*0x18*/ Vec3s translation;
+ /*0x00*/
+ struct GraphNode node;
+ /*0x14*/
+ void *displayList;
+ /*0x18*/
+ Vec3s translation;
};
/** A GraphNode that draws a display list rotated in a way to always face the
@@ -249,9 +301,12 @@ struct GraphNodeAnimatedPart
*/
struct GraphNodeBillboard
{
- /*0x00*/ struct GraphNode node;
- /*0x14*/ void *displayList;
- /*0x18*/ Vec3s translation;
+ /*0x00*/
+ struct GraphNode node;
+ /*0x14*/
+ void *displayList;
+ /*0x18*/
+ Vec3s translation;
};
/** A GraphNode that simply draws a display list without doing any
@@ -259,8 +314,10 @@ struct GraphNodeBillboard
*/
struct GraphNodeDisplayList
{
- /*0x00*/ struct GraphNode node;
- /*0x14*/ void *displayList;
+ /*0x00*/
+ struct GraphNode node;
+ /*0x14*/
+ void *displayList;
};
/** GraphNode part that scales itself and its children.
@@ -273,9 +330,12 @@ struct GraphNodeDisplayList
*/
struct GraphNodeScale
{
- /*0x00*/ struct GraphNode node;
- /*0x14*/ void *displayList;
- /*0x18*/ f32 scale;
+ /*0x00*/
+ struct GraphNode node;
+ /*0x14*/
+ void *displayList;
+ /*0x18*/
+ f32 scale;
};
/** GraphNode that draws a shadow under an object.
@@ -285,10 +345,14 @@ struct GraphNodeScale
*/
struct GraphNodeShadow
{
- /*0x00*/ struct GraphNode node;
- /*0x14*/ s16 shadowScale; // diameter (when a circle) or side (when a square) of shadow
- /*0x16*/ u8 shadowSolidity; // opacity of shadow, 255 = opaque
- /*0x17*/ u8 shadowType; // see ShadowType enum in shadow.h
+ /*0x00*/
+ struct GraphNode node;
+ /*0x14*/
+ s16 shadowScale; // diameter (when a circle) or side (when a square) of shadow
+ /*0x16*/
+ u8 shadowSolidity; // opacity of shadow, 255 = opaque
+ /*0x17*/
+ u8 shadowType; // see ShadowType enum in shadow.h
};
/** GraphNode that contains as its sharedChild a group node containing all
@@ -296,8 +360,10 @@ struct GraphNodeShadow
*/
struct GraphNodeObjectParent
{
- /*0x00*/ struct GraphNode node;
- /*0x14*/ struct GraphNode *sharedChild;
+ /*0x00*/
+ struct GraphNode node;
+ /*0x14*/
+ struct GraphNode *sharedChild;
};
/** GraphNode that draws display lists not directly in memory but generated by
@@ -310,8 +376,10 @@ struct GraphNodeObjectParent
*/
struct GraphNodeGenerated
{
- /*0x00*/ struct FnGraphNode fnNode;
- /*0x18*/ u32 parameter; // extra context for the function
+ /*0x00*/
+ struct FnGraphNode fnNode;
+ /*0x18*/
+ u32 parameter; // extra context for the function
};
/** GraphNode that draws a background image or a rectangle of a color.
@@ -319,19 +387,26 @@ struct GraphNodeGenerated
*/
struct GraphNodeBackground
{
- /*0x00*/ struct FnGraphNode fnNode;
- /*0x18*/ s32 unused;
- /*0x1C*/ s32 background; // background ID, or rgba5551 color if fnNode.func is null
+ /*0x00*/
+ struct FnGraphNode fnNode;
+ /*0x18*/
+ s32 unused;
+ /*0x1C*/
+ s32 background; // background ID, or rgba5551 color if fnNode.func is null
};
/** Renders the object that Mario is holding.
*/
struct GraphNodeHeldObject
{
- /*0x00*/ struct FnGraphNode fnNode;
- /*0x18*/ s32 playerIndex;
- /*0x1C*/ struct Object *objNode;
- /*0x20*/ Vec3s translation;
+ /*0x00*/
+ struct FnGraphNode fnNode;
+ /*0x18*/
+ s32 playerIndex;
+ /*0x1C*/
+ struct Object *objNode;
+ /*0x20*/
+ Vec3s translation;
};
/** A node that allows an object to specify a different culling radius than the
@@ -341,8 +416,10 @@ struct GraphNodeHeldObject
*/
struct GraphNodeCullingRadius
{
- /*0x00*/ struct GraphNode node;
- /*0x14*/ s16 cullingRadius; // specifies the 'sphere radius' for purposes of frustum culling
+ /*0x00*/
+ struct GraphNode node;
+ /*0x14*/
+ s16 cullingRadius; // specifies the 'sphere radius' for purposes of frustum culling
u8 pad1E[2];
};
@@ -363,71 +440,122 @@ extern s16 gCurGraphNodeIndex;
void init_scene_graph_node_links(struct GraphNode *graphNode, s32 type);
-struct GraphNodeRoot *init_graph_node_root(struct AllocOnlyPool *pool, struct GraphNodeRoot *graphNode,
- s16 areaIndex, s16 x, s16 y, s16 width, s16 height);
+struct GraphNodeRoot *init_graph_node_root(
+ struct AllocOnlyPool *pool, struct GraphNodeRoot *graphNode,
+ s16 areaIndex, s16 x, s16 y, s16 width, s16 height);
+
struct GraphNodeOrthoProjection *init_graph_node_ortho_projection(struct AllocOnlyPool *pool, struct GraphNodeOrthoProjection *graphNode, f32 scale);
-struct GraphNodePerspective *init_graph_node_perspective(struct AllocOnlyPool *pool, struct GraphNodePerspective *graphNode,
- f32 fov, s16 near, s16 far, GraphNodeFunc nodeFunc, s32 unused);
+
+struct GraphNodePerspective *init_graph_node_perspective(
+ struct AllocOnlyPool *pool, struct GraphNodePerspective *graphNode,
+ f32 fov, s16 near, s16 far, GraphNodeFunc nodeFunc, s32 unused);
+
struct GraphNodeStart *init_graph_node_start(struct AllocOnlyPool *pool, struct GraphNodeStart *graphNode);
+
struct GraphNodeMasterList *init_graph_node_master_list(struct AllocOnlyPool *pool, struct GraphNodeMasterList *graphNode, s16 on);
-struct GraphNodeLevelOfDetail *init_graph_node_render_range(struct AllocOnlyPool *pool, struct GraphNodeLevelOfDetail *graphNode,
- s16 minDistance, s16 maxDistance);
-struct GraphNodeSwitchCase *init_graph_node_switch_case(struct AllocOnlyPool *pool, struct GraphNodeSwitchCase *graphNode,
- s16 numCases, s16 selectedCase, GraphNodeFunc nodeFunc, s32 unused);
-struct GraphNodeCamera *init_graph_node_camera(struct AllocOnlyPool *pool, struct GraphNodeCamera *graphNode,
- f32 *pos, f32 *focus, GraphNodeFunc func, s32 mode);
-struct GraphNodeTranslationRotation *init_graph_node_translation_rotation(struct AllocOnlyPool *pool, struct GraphNodeTranslationRotation *graphNode,
- s32 drawingLayer, void *displayList, Vec3s translation, Vec3s rotation);
-struct GraphNodeTranslation *init_graph_node_translation(struct AllocOnlyPool *pool, struct GraphNodeTranslation *graphNode,
- s32 drawingLayer, void *displayList, Vec3s translation);
-struct GraphNodeRotation *init_graph_node_rotation(struct AllocOnlyPool *pool, struct GraphNodeRotation *graphNode,
- s32 drawingLayer, void *displayList, Vec3s rotation);
-struct GraphNodeScale *init_graph_node_scale(struct AllocOnlyPool *pool, struct GraphNodeScale *graphNode,
- s32 drawingLayer, void *displayList, f32 scale);
-struct GraphNodeObject *init_graph_node_object(struct AllocOnlyPool *pool, struct GraphNodeObject *graphNode,
- struct GraphNode *sharedChild, Vec3f pos, Vec3s angle, Vec3f scale);
+
+struct GraphNodeLevelOfDetail *init_graph_node_render_range(
+ struct AllocOnlyPool *pool, struct GraphNodeLevelOfDetail *graphNode,
+ s16 minDistance, s16 maxDistance);
+
+struct GraphNodeSwitchCase *init_graph_node_switch_case(
+ struct AllocOnlyPool *pool, struct GraphNodeSwitchCase *graphNode,
+ s16 numCases, s16 selectedCase, GraphNodeFunc nodeFunc, s32 unused);
+
+struct GraphNodeCamera *init_graph_node_camera(
+ struct AllocOnlyPool *pool, struct GraphNodeCamera *graphNode,
+ f32 *pos, f32 *focus, GraphNodeFunc func, s32 mode);
+
+struct GraphNodeTranslationRotation *init_graph_node_translation_rotation(
+ struct AllocOnlyPool *pool, struct GraphNodeTranslationRotation *graphNode,
+ s32 drawingLayer, void *displayList, Vec3s translation, Vec3s rotation);
+
+struct GraphNodeTranslation *init_graph_node_translation(
+ struct AllocOnlyPool *pool, struct GraphNodeTranslation *graphNode,
+ s32 drawingLayer, void *displayList, Vec3s translation);
+
+struct GraphNodeRotation *init_graph_node_rotation(
+ struct AllocOnlyPool *pool, struct GraphNodeRotation *graphNode,
+ s32 drawingLayer, void *displayList, Vec3s rotation);
+
+struct GraphNodeScale *init_graph_node_scale(
+ struct AllocOnlyPool *pool, struct GraphNodeScale *graphNode,
+ s32 drawingLayer, void *displayList, f32 scale);
+
+struct GraphNodeObject *init_graph_node_object(
+ struct AllocOnlyPool *pool, struct GraphNodeObject *graphNode,
+ struct GraphNode *sharedChild, Vec3f pos, Vec3s angle, Vec3f scale);
+
struct GraphNodeCullingRadius *init_graph_node_culling_radius(struct AllocOnlyPool *pool, struct GraphNodeCullingRadius *graphNode, s16 radius);
-struct GraphNodeAnimatedPart *init_graph_node_animated_part(struct AllocOnlyPool *pool, struct GraphNodeAnimatedPart *graphNode,
- s32 drawingLayer, void *displayList, Vec3s translation);
-struct GraphNodeBillboard *init_graph_node_billboard(struct AllocOnlyPool *pool, struct GraphNodeBillboard *graphNode,
- s32 drawingLayer, void *displayList, Vec3s translation);
-struct GraphNodeDisplayList *init_graph_node_display_list(struct AllocOnlyPool *pool, struct GraphNodeDisplayList *graphNode,
- s32 drawingLayer, void *displayList);
-struct GraphNodeShadow *init_graph_node_shadow(struct AllocOnlyPool *pool, struct GraphNodeShadow *graphNode,
- s16 shadowScale, u8 shadowSolidity, u8 shadowType);
-struct GraphNodeObjectParent *init_graph_node_object_parent(struct AllocOnlyPool *pool, struct GraphNodeObjectParent *sp1c,
- struct GraphNode *sharedChild);
-struct GraphNodeGenerated *init_graph_node_generated(struct AllocOnlyPool *pool, struct GraphNodeGenerated *sp1c,
- GraphNodeFunc gfxFunc, s32 parameter);
-struct GraphNodeBackground *init_graph_node_background(struct AllocOnlyPool *pool, struct GraphNodeBackground *sp1c,
- u16 background, GraphNodeFunc backgroundFunc, s32 zero);
-struct GraphNodeHeldObject *init_graph_node_held_object(struct AllocOnlyPool *pool, struct GraphNodeHeldObject *sp1c,
- struct Object *objNode, Vec3s translation,
- GraphNodeFunc nodeFunc, s32 playerIndex);
+
+struct GraphNodeAnimatedPart *init_graph_node_animated_part(
+ struct AllocOnlyPool *pool, struct GraphNodeAnimatedPart *graphNode,
+ s32 drawingLayer, void *displayList, Vec3s translation);
+
+struct GraphNodeBillboard *init_graph_node_billboard(
+ struct AllocOnlyPool *pool, struct GraphNodeBillboard *graphNode,
+ s32 drawingLayer, void *displayList, Vec3s translation);
+
+struct GraphNodeDisplayList *init_graph_node_display_list(
+ struct AllocOnlyPool *pool, struct GraphNodeDisplayList *graphNode,
+ s32 drawingLayer, void *displayList);
+
+struct GraphNodeShadow *init_graph_node_shadow(
+ struct AllocOnlyPool *pool, struct GraphNodeShadow *graphNode,
+ s16 shadowScale, u8 shadowSolidity, u8 shadowType);
+
+struct GraphNodeObjectParent *init_graph_node_object_parent(
+ struct AllocOnlyPool *pool, struct GraphNodeObjectParent *sp1c,
+ struct GraphNode *sharedChild);
+
+struct GraphNodeGenerated *init_graph_node_generated(
+ struct AllocOnlyPool *pool, struct GraphNodeGenerated *sp1c,
+ GraphNodeFunc gfxFunc, s32 parameter);
+
+struct GraphNodeBackground *init_graph_node_background(
+ struct AllocOnlyPool *pool, struct GraphNodeBackground *sp1c,
+ u16 background, GraphNodeFunc backgroundFunc, s32 zero);
+
+struct GraphNodeHeldObject *init_graph_node_held_object(
+ struct AllocOnlyPool *pool, struct GraphNodeHeldObject *sp1c,
+ struct Object *objNode, Vec3s translation,
+ GraphNodeFunc nodeFunc, s32 playerIndex);
+
struct GraphNode *geo_add_child(struct GraphNode *parent, struct GraphNode *childNode);
+
struct GraphNode *geo_remove_child(struct GraphNode *graphNode);
+
struct GraphNode *geo_make_first_child(struct GraphNode *newFirstChild);
void geo_call_global_function_nodes_helper(struct GraphNode *graphNode, s32 callContext);
+
void geo_call_global_function_nodes(struct GraphNode *graphNode, s32 callContext);
void geo_reset_object_node(struct GraphNodeObject *graphNode);
+
void geo_obj_init(struct GraphNodeObject *graphNode, void *sharedChild, Vec3f pos, Vec3s angle);
+
void geo_obj_init_spawninfo(struct GraphNodeObject *graphNode, struct SpawnInfo *spawn);
+
void geo_obj_init_animation(struct GraphNodeObject *graphNode, struct Animation **animPtrAddr);
+
void geo_obj_init_animation_accel(struct GraphNodeObject *graphNode, struct Animation **animPtrAddr, u32 animAccel);
s32 retrieve_animation_index(s32 frame, u16 **attributes);
s16 geo_update_animation_frame(struct AnimInfo *obj, s32 *accelAssist);
+
void geo_retreive_animation_translation(struct GraphNodeObject *obj, Vec3f position);
struct GraphNodeRoot *geo_find_root(struct GraphNode *graphNode);
// graph_node_manager
-s16 *read_vec3s_to_vec3f(Vec3f, s16 *src);
+s16 *read_vec3s_to_vec3f(Vec3f, s16 * src);
+
s16 *read_vec3s(Vec3s dst, s16 *src);
+
s16 *read_vec3s_angle(Vec3s dst, s16 *src);
+
void register_scene_graph_node(struct GraphNode *graphNode);
#endif // GRAPH_NODE_H
diff --git a/src/decomp/engine/graph_node_manager.c b/src/decomp/engine/graph_node_manager.c
index edde5aa..de458f2 100644
--- a/src/decomp/engine/graph_node_manager.c
+++ b/src/decomp/engine/graph_node_manager.c
@@ -6,14 +6,17 @@
#include "graph_node.h"
#if IS_64_BIT
-static s16 next_s16_in_geo_script(s16 **src) {
+static s16 next_s16_in_geo_script(s16 **src)
+{
s16 ret;
- if (((uintptr_t)(*src) & 7) == 4) {
- *src += 2; // skip 32 bits
+ if (((uintptr_t) * src & 7) == 4)
+ {
+ *src += 2; // skip 32 bits
}
ret = *(*src)++;
- if (((uintptr_t)(*src) & 7) == 4) {
- *src += 2; // skip 32 bits
+ if (((uintptr_t) * src & 7) == 4)
+ {
+ *src += 2; // skip 32 bits
}
return ret;
}
@@ -25,7 +28,8 @@ static s16 next_s16_in_geo_script(s16 **src) {
* Takes a pointer to three shorts (supplied by a geo layout script) and
* copies it to the destination float vector.
*/
-s16 *read_vec3s_to_vec3f(Vec3f dst, s16 *src) {
+s16 *read_vec3s_to_vec3f(Vec3f dst, s16 *src)
+{
dst[0] = next_s16_in_geo_script(&src);
dst[1] = next_s16_in_geo_script(&src);
dst[2] = next_s16_in_geo_script(&src);
@@ -37,7 +41,8 @@ s16 *read_vec3s_to_vec3f(Vec3f dst, s16 *src) {
* copies it to the destination vector. It's essentially a memcpy but consistent
* with the other two 'geo-script vector to internal vector' functions.
*/
-s16 *read_vec3s(Vec3s dst, s16 *src) {
+s16 *read_vec3s(Vec3s dst, s16 *src)
+{
dst[0] = next_s16_in_geo_script(&src);
dst[1] = next_s16_in_geo_script(&src);
dst[2] = next_s16_in_geo_script(&src);
@@ -49,7 +54,8 @@ s16 *read_vec3s(Vec3s dst, s16 *src) {
* and converts it to a vector of three in-game angle units in [-32768, 32767]
* range.
*/
-s16 *read_vec3s_angle(Vec3s dst, s16 *src) {
+s16 *read_vec3s_angle(Vec3s dst, s16 *src)
+{
dst[0] = (next_s16_in_geo_script(&src) << 15) / 180;
dst[1] = (next_s16_in_geo_script(&src) << 15) / 180;
dst[2] = (next_s16_in_geo_script(&src) << 15) / 180;
@@ -61,19 +67,28 @@ s16 *read_vec3s_angle(Vec3s dst, s16 *src) {
* 'gCurGraphNodeList'. This is called from geo_layout commands to add nodes
* to the scene graph.
*/
-void register_scene_graph_node(struct GraphNode *graphNode) {
- if (graphNode != NULL) {
+void register_scene_graph_node(struct GraphNode *graphNode)
+{
+ if (graphNode != NULL)
+ {
gCurGraphNodeList[gCurGraphNodeIndex] = graphNode;
- if (gCurGraphNodeIndex == 0) {
- if (gCurRootGraphNode == NULL) {
+ if (gCurGraphNodeIndex == 0)
+ {
+ if (gCurRootGraphNode == NULL)
+ {
gCurRootGraphNode = graphNode;
}
- } else {
- if (gCurGraphNodeList[gCurGraphNodeIndex - 1]->type == GRAPH_NODE_TYPE_OBJECT_PARENT) {
- ((struct GraphNodeObjectParent *) gCurGraphNodeList[gCurGraphNodeIndex - 1])
- ->sharedChild = graphNode;
- } else {
+ }
+ else
+ {
+ if (gCurGraphNodeList[gCurGraphNodeIndex - 1]->type == GRAPH_NODE_TYPE_OBJECT_PARENT)
+ {
+ ((struct GraphNodeObjectParent *)gCurGraphNodeList[gCurGraphNodeIndex - 1])
+ ->sharedChild = graphNode;
+ }
+ else
+ {
geo_add_child(gCurGraphNodeList[gCurGraphNodeIndex - 1], graphNode);
}
}
diff --git a/src/decomp/engine/guMtxF2L.c b/src/decomp/engine/guMtxF2L.c
index 246336b..a635df7 100644
--- a/src/decomp/engine/guMtxF2L.c
+++ b/src/decomp/engine/guMtxF2L.c
@@ -5,14 +5,17 @@
#endif
#ifndef GBI_FLOATS
-void guMtxF2L(float mf[4][4], Mtx *m) {
+void guMtxF2L(float mf[4][4], Mtx *m)
+{
int r, c;
s32 tmp1;
s32 tmp2;
s32 *m1 = &m->m[0][0];
s32 *m2 = &m->m[2][0];
- for (r = 0; r < 4; r++) {
- for (c = 0; c < 2; c++) {
+ for (r = 0; r < 4; r++)
+ {
+ for (c = 0; c < 2; c++)
+ {
tmp1 = mf[r][2 * c] * 65536.0f;
tmp2 = mf[r][2 * c + 1] * 65536.0f;
*m1++ = (tmp1 & 0xffff0000) | ((tmp2 >> 0x10) & 0xffff);
@@ -20,53 +23,67 @@ void guMtxF2L(float mf[4][4], Mtx *m) {
}
}
}
-void guMtxL2F(float mf[4][4], Mtx *m) {
+
+void guMtxL2F(float mf[4][4], Mtx *m)
+{
int r, c;
u32 tmp1;
u32 tmp2;
u32 *m1;
u32 *m2;
s32 stmp1, stmp2;
- m1 = (u32 *) &m->m[0][0];
- m2 = (u32 *) &m->m[2][0];
- for (r = 0; r < 4; r++) {
- for (c = 0; c < 2; c++) {
+ m1 = (u32 *)&m->m[0][0];
+ m2 = (u32 *)&m->m[2][0];
+ for (r = 0; r < 4; r++)
+ {
+ for (c = 0; c < 2; c++)
+ {
tmp1 = (*m1 & 0xffff0000) | ((*m2 >> 0x10) & 0xffff);
tmp2 = ((*m1++ << 0x10) & 0xffff0000) | (*m2++ & 0xffff);
- stmp1 = *(s32 *) &tmp1;
- stmp2 = *(s32 *) &tmp2;
+ stmp1 = *(s32 *)&tmp1;
+ stmp2 = *(s32 *)&tmp2;
mf[r][c * 2 + 0] = stmp1 / 65536.0f;
mf[r][c * 2 + 1] = stmp2 / 65536.0f;
}
}
}
#else
-void guMtxF2L(float mf[4][4], Mtx *m) {
+void guMtxF2L(float mf[4][4], Mtx *m)
+{
memcpy(m, mf, sizeof(Mtx));
}
-void guMtxL2F(float mf[4][4], Mtx *m) {
+void guMtxL2F(float mf[4][4], Mtx *m)
+{
memcpy(mf, m, sizeof(Mtx));
}
#endif
-void guMtxIdentF(float mf[4][4]) {
+void guMtxIdentF(float mf[4][4])
+{
int r, c;
- for (r = 0; r < 4; r++) {
- for (c = 0; c < 4; c++) {
- if (r == c) {
+ for (r = 0; r < 4; r++)
+ {
+ for (c = 0; c < 4; c++)
+ {
+ if (r == c)
+ {
mf[r][c] = 1.0f;
- } else {
+ }
+ else
+ {
mf[r][c] = 0.0f;
}
}
}
}
-void guMtxIdent(Mtx *m) {
-#ifndef GBI_FLOATS
+
+void guMtxIdent(Mtx *m)
+{
+ #ifndef GBI_FLOATS
float mf[4][4];
guMtxIdentF(mf);
guMtxF2L(mf, m);
-#else
+ #else
guMtxIdentF(m->m);
-#endif
+ #endif
}
diff --git a/src/decomp/engine/guMtxF2L.h b/src/decomp/engine/guMtxF2L.h
index ccfa212..0894d01 100644
--- a/src/decomp/engine/guMtxF2L.h
+++ b/src/decomp/engine/guMtxF2L.h
@@ -4,6 +4,7 @@
#include "../include/PR/gbi.h"
extern void guMtxF2L(float mf[4][4], Mtx *m);
+
extern void guMtxL2F(float mf[4][4], Mtx *m);
#endif//GUMTXF2L_H
\ No newline at end of file
diff --git a/src/decomp/engine/math_util.c b/src/decomp/engine/math_util.c
index 91396ff..1532813 100644
--- a/src/decomp/engine/math_util.c
+++ b/src/decomp/engine/math_util.c
@@ -8,13 +8,13 @@
#include "graph_node.h"
#include "surface_collision.h"
-static Vec3f gVec3fZero = { 0.0f, 0.0f, 0.0f };
+static Vec3f gVec3fZero = {0.0f, 0.0f, 0.0f};
// Inlined tables
f32 gSineTable[] = {
- 0.000000000f, 0.0015339801f,0.0030679568f,0.004601926f,
- 0.0061358847f,0.007669829f, 0.009203754f, 0.010737659f,
- 0.012271538f, 0.0138053885f,0.015339206f, 0.016872987f,
+ 0.000000000f, 0.0015339801f, 0.0030679568f, 0.004601926f,
+ 0.0061358847f, 0.007669829f, 0.009203754f, 0.010737659f,
+ 0.012271538f, 0.0138053885f, 0.015339206f, 0.016872987f,
0.018406730f, 0.019940428f, 0.021474080f, 0.023007682f,
0.024541229f, 0.026074719f, 0.027608145f, 0.029141508f,
0.030674804f, 0.032208025f, 0.033741172f, 0.035274237f,
@@ -268,11 +268,11 @@ f32 gSineTable[] = {
0.999830604f, 0.999857664f, 0.999882340f, 0.999904692f,
0.999924719f, 0.999942362f, 0.999957621f, 0.999970615f,
0.999981165f, 0.999989390f, 0.999995291f, 0.999998808f,
-#ifndef AVOID_UB
+ #ifndef AVOID_UB
};
f32 gCosineTable[0x1000] = {
-#endif
+ #endif
// cosine
1.000000000f, 0.999998808f, 0.999995291f, 0.999989390f,
0.999981165f, 0.999970615f, 0.999957621f, 0.999942362f,
@@ -529,12 +529,12 @@ f32 gCosineTable[0x1000] = {
0.024541229f, 0.023007682f, 0.021474080f, 0.019940428f,
0.018406730f, 0.016872987f, 0.015339206f, 0.0138053885f,
0.012271538f, 0.010737659f, 0.009203754f, 0.007669829f,
- 0.0061358847f,0.004601926f, 0.0030679568f,0.0015339801f,
+ 0.0061358847f, 0.004601926f, 0.0030679568f, 0.0015339801f,
// negative sine
- 0.000000000f, -0.0015339801f,-0.0030679568f,-0.004601926f,
- -0.0061358847f,-0.007669829f, -0.009203754f, -0.010737659f,
- -0.012271538f, -0.0138053885f,-0.015339206f, -0.016872987f,
+ 0.000000000f, -0.0015339801f, -0.0030679568f, -0.004601926f,
+ -0.0061358847f, -0.007669829f, -0.009203754f, -0.010737659f,
+ -0.012271538f, -0.0138053885f, -0.015339206f, -0.016872987f,
-0.018406730f, -0.019940428f, -0.021474080f, -0.023007682f,
-0.024541229f, -0.026074719f, -0.027608145f, -0.029141508f,
-0.030674804f, -0.032208025f, -0.033741172f, -0.035274237f,
@@ -1045,12 +1045,12 @@ f32 gCosineTable[0x1000] = {
-0.024541229f, -0.023007682f, -0.021474080f, -0.019940428f,
-0.018406730f, -0.016872987f, -0.015339206f, -0.0138053885f,
-0.012271538f, -0.010737659f, -0.009203754f, -0.007669829f,
- -0.0061358847f,-0.004601926f, -0.0030679568f,-0.0015339801f,
+ -0.0061358847f, -0.004601926f, -0.0030679568f, -0.0015339801f,
// sine
- 0.000000000f, 0.0015339801f,0.0030679568f,0.004601926f,
- 0.0061358847f,0.007669829f, 0.009203754f, 0.010737659f,
- 0.012271538f, 0.0138053885f,0.015339206f, 0.016872987f,
+ 0.000000000f, 0.0015339801f, 0.0030679568f, 0.004601926f,
+ 0.0061358847f, 0.007669829f, 0.009203754f, 0.010737659f,
+ 0.012271538f, 0.0138053885f, 0.015339206f, 0.016872987f,
0.018406730f, 0.019940428f, 0.021474080f, 0.023007682f,
0.024541229f, 0.026074719f, 0.027608145f, 0.029141508f,
0.030674804f, 0.032208025f, 0.033741172f, 0.035274237f,
@@ -1450,7 +1450,8 @@ int gSplineState;
#pragma GCC diagnostic ignored "-Wreturn-local-addr"
/// Copy vector 'src' to 'dest'
-void *vec3f_copy(Vec3f dest, Vec3f src) {
+void *vec3f_copy(Vec3f dest, Vec3f src)
+{
dest[0] = src[0];
dest[1] = src[1];
dest[2] = src[2];
@@ -1458,7 +1459,8 @@ void *vec3f_copy(Vec3f dest, Vec3f src) {
}
/// Set vector 'dest' to (x, y, z)
-void *vec3f_set(Vec3f dest, f32 x, f32 y, f32 z) {
+void *vec3f_set(Vec3f dest, f32 x, f32 y, f32 z)
+{
dest[0] = x;
dest[1] = y;
dest[2] = z;
@@ -1466,7 +1468,8 @@ void *vec3f_set(Vec3f dest, f32 x, f32 y, f32 z) {
}
/// Add vector 'a' to 'dest'
-void *vec3f_add(Vec3f dest, Vec3f a) {
+void *vec3f_add(Vec3f dest, Vec3f a)
+{
dest[0] += a[0];
dest[1] += a[1];
dest[2] += a[2];
@@ -1474,7 +1477,8 @@ void *vec3f_add(Vec3f dest, Vec3f a) {
}
/// Make 'dest' the sum of vectors a and b.
-void *vec3f_sum(Vec3f dest, Vec3f a, Vec3f b) {
+void *vec3f_sum(Vec3f dest, Vec3f a, Vec3f b)
+{
dest[0] = a[0] + b[0];
dest[1] = a[1] + b[1];
dest[2] = a[2] + b[2];
@@ -1482,7 +1486,8 @@ void *vec3f_sum(Vec3f dest, Vec3f a, Vec3f b) {
}
/// Copy vector src to dest
-void *vec3s_copy(Vec3s dest, Vec3s src) {
+void *vec3s_copy(Vec3s dest, Vec3s src)
+{
dest[0] = src[0];
dest[1] = src[1];
dest[2] = src[2];
@@ -1490,7 +1495,8 @@ void *vec3s_copy(Vec3s dest, Vec3s src) {
}
/// Set vector 'dest' to (x, y, z)
-void *vec3s_set(Vec3s dest, s16 x, s16 y, s16 z) {
+void *vec3s_set(Vec3s dest, s16 x, s16 y, s16 z)
+{
dest[0] = x;
dest[1] = y;
dest[2] = z;
@@ -1498,7 +1504,8 @@ void *vec3s_set(Vec3s dest, s16 x, s16 y, s16 z) {
}
/// Add vector a to 'dest'
-void *vec3s_add(Vec3s dest, Vec3s a) {
+void *vec3s_add(Vec3s dest, Vec3s a)
+{
dest[0] += a[0];
dest[1] += a[1];
dest[2] += a[2];
@@ -1506,7 +1513,8 @@ void *vec3s_add(Vec3s dest, Vec3s a) {
}
/// Make 'dest' the sum of vectors a and b.
-void *vec3s_sum(Vec3s dest, Vec3s a, Vec3s b) {
+void *vec3s_sum(Vec3s dest, Vec3s a, Vec3s b)
+{
dest[0] = a[0] + b[0];
dest[1] = a[1] + b[1];
dest[2] = a[2] + b[2];
@@ -1514,7 +1522,8 @@ void *vec3s_sum(Vec3s dest, Vec3s a, Vec3s b) {
}
/// Subtract vector a from 'dest'
-void *vec3s_sub(Vec3s dest, Vec3s a) {
+void *vec3s_sub(Vec3s dest, Vec3s a)
+{
dest[0] -= a[0];
dest[1] -= a[1];
dest[2] -= a[2];
@@ -1522,7 +1531,8 @@ void *vec3s_sub(Vec3s dest, Vec3s a) {
}
/// Convert short vector a to float vector 'dest'
-void *vec3s_to_vec3f(Vec3f dest, Vec3s a) {
+void *vec3s_to_vec3f(Vec3f dest, Vec3s a)
+{
dest[0] = a[0];
dest[1] = a[1];
dest[2] = a[2];
@@ -1533,11 +1543,12 @@ void *vec3s_to_vec3f(Vec3f dest, Vec3s a) {
* Convert float vector a to a short vector 'dest' by rounding the components
* to the nearest integer.
*/
-void *vec3f_to_vec3s(Vec3s dest, Vec3f a) {
+void *vec3f_to_vec3s(Vec3s dest, Vec3f a)
+{
// add/subtract 0.5 in order to round to the nearest s32 instead of truncating
- dest[0] = a[0] + ((a[0] > 0) ? 0.5f : -0.5f);
- dest[1] = a[1] + ((a[1] > 0) ? 0.5f : -0.5f);
- dest[2] = a[2] + ((a[2] > 0) ? 0.5f : -0.5f);
+ dest[0] = a[0] + (a[0] > 0 ? 0.5f : -0.5f);
+ dest[1] = a[1] + (a[1] > 0 ? 0.5f : -0.5f);
+ dest[2] = a[2] + (a[2] > 0 ? 0.5f : -0.5f);
return &dest; //! warning: function returns address of local variable
}
@@ -1546,7 +1557,8 @@ void *vec3f_to_vec3s(Vec3s dest, Vec3f a) {
* It is similar to vec3f_cross, but it calculates the vectors (c-b) and (b-a)
* at the same time.
*/
-void *find_vector_perpendicular_to_plane(Vec3f dest, Vec3f a, Vec3f b, Vec3f c) {
+void *find_vector_perpendicular_to_plane(Vec3f dest, Vec3f a, Vec3f b, Vec3f c)
+{
dest[0] = (b[1] - a[1]) * (c[2] - b[2]) - (c[1] - b[1]) * (b[2] - a[2]);
dest[1] = (b[2] - a[2]) * (c[0] - b[0]) - (c[2] - b[2]) * (b[0] - a[0]);
dest[2] = (b[0] - a[0]) * (c[1] - b[1]) - (c[0] - b[0]) * (b[1] - a[1]);
@@ -1554,7 +1566,8 @@ void *find_vector_perpendicular_to_plane(Vec3f dest, Vec3f a, Vec3f b, Vec3f c)
}
/// Make vector 'dest' the cross product of vectors a and b.
-void *vec3f_cross(Vec3f dest, Vec3f a, Vec3f b) {
+void *vec3f_cross(Vec3f dest, Vec3f a, Vec3f b)
+{
dest[0] = a[1] * b[2] - b[1] * a[2];
dest[1] = a[2] * b[0] - b[2] * a[0];
dest[2] = a[0] * b[1] - b[0] * a[1];
@@ -1562,7 +1575,8 @@ void *vec3f_cross(Vec3f dest, Vec3f a, Vec3f b) {
}
/// Scale vector 'dest' so it has length 1
-void *vec3f_normalize(Vec3f dest) {
+void *vec3f_normalize(Vec3f dest)
+{
//! Possible division by zero
f32 invsqrt = 1.0f / sqrtf(dest[0] * dest[0] + dest[1] * dest[1] + dest[2] * dest[2]);
@@ -1575,12 +1589,14 @@ void *vec3f_normalize(Vec3f dest) {
#pragma GCC diagnostic pop
/// Copy matrix 'src' to 'dest'
-void mtxf_copy(Mat4 dest, Mat4 src) {
+void mtxf_copy(Mat4 dest, Mat4 src)
+{
register s32 i;
- register u32 *d = (u32 *) dest;
- register u32 *s = (u32 *) src;
+ register u32 *d = (u32 *)dest;
+ register u32 *s = (u32 *)src;
- for (i = 0; i < 16; i++) {
+ for (i = 0; i < 16; i++)
+ {
*d++ = *s++;
}
}
@@ -1588,22 +1604,24 @@ void mtxf_copy(Mat4 dest, Mat4 src) {
/**
* Set mtx to the identity matrix
*/
-void mtxf_identity(Mat4 mtx) {
+void mtxf_identity(Mat4 mtx)
+{
register s32 i;
register f32 *dest;
// These loops must be one line to match on -O2
// initialize everything except the first and last cells to 0
- for (dest = (f32 *) mtx + 1, i = 0; i < 14; dest++, i++) *dest = 0;
+ for (dest = (f32 *)mtx + 1, i = 0; i < 14; dest++, i++) *dest = 0;
// initialize the diagonal cells to 1
- for (dest = (f32 *) mtx, i = 0; i < 4; dest += 5, i++) *dest = 1;
+ for (dest = (f32 *)mtx, i = 0; i < 4; dest += 5, i++) *dest = 1;
}
/**
* Set dest to a translation matrix of vector b
*/
-void mtxf_translate(Mat4 dest, Vec3f b) {
+void mtxf_translate(Mat4 dest, Vec3f b)
+{
mtxf_identity(dest);
dest[3][0] = b[0];
dest[3][1] = b[1];
@@ -1616,7 +1634,8 @@ void mtxf_translate(Mat4 dest, Vec3f b) {
* at the position 'to'. The up-vector is assumed to be (0, 1, 0), but the 'roll'
* angle allows a bank rotation of the camera.
*/
-void mtxf_lookat(Mat4 mtx, Vec3f from, Vec3f to, s16 roll) {
+void mtxf_lookat(Mat4 mtx, Vec3f from, Vec3f to, s16 roll)
+{
register f32 invLength;
f32 dx;
f32 dz;
@@ -1694,7 +1713,8 @@ void mtxf_lookat(Mat4 mtx, Vec3f from, Vec3f to, s16 roll) {
* Build a matrix that rotates around the z axis, then the x axis, then the y
* axis, and then translates.
*/
-void mtxf_rotate_zxy_and_translate(Mat4 dest, Vec3f translate, Vec3s rotate) {
+void mtxf_rotate_zxy_and_translate(Mat4 dest, Vec3f translate, Vec3s rotate)
+{
register f32 sx = sins(rotate[0]);
register f32 cx = coss(rotate[0]);
@@ -1727,7 +1747,8 @@ void mtxf_rotate_zxy_and_translate(Mat4 dest, Vec3f translate, Vec3s rotate) {
* Build a matrix that rotates around the x axis, then the y axis, then the z
* axis, and then translates.
*/
-void mtxf_rotate_xyz_and_translate(Mat4 dest, Vec3f b, Vec3s c) {
+void mtxf_rotate_xyz_and_translate(Mat4 dest, Vec3f b, Vec3s c)
+{
register f32 sx = sins(c[0]);
register f32 cx = coss(c[0]);
@@ -1764,7 +1785,8 @@ void mtxf_rotate_xyz_and_translate(Mat4 dest, Vec3f b, Vec3s c) {
* 'position' is the position of the object in the world
* 'angle' rotates the object while still facing the camera.
*/
-void mtxf_billboard(Mat4 dest, Mat4 mtx, Vec3f position, s16 angle) {
+void mtxf_billboard(Mat4 dest, Mat4 mtx, Vec3f position, s16 angle)
+{
dest[0][0] = coss(angle);
dest[0][1] = sins(angle);
dest[0][2] = 0;
@@ -1781,11 +1803,11 @@ void mtxf_billboard(Mat4 dest, Mat4 mtx, Vec3f position, s16 angle) {
dest[2][3] = 0;
dest[3][0] =
- mtx[0][0] * position[0] + mtx[1][0] * position[1] + mtx[2][0] * position[2] + mtx[3][0];
+ mtx[0][0] * position[0] + mtx[1][0] * position[1] + mtx[2][0] * position[2] + mtx[3][0];
dest[3][1] =
- mtx[0][1] * position[0] + mtx[1][1] * position[1] + mtx[2][1] * position[2] + mtx[3][1];
+ mtx[0][1] * position[0] + mtx[1][1] * position[1] + mtx[2][1] * position[2] + mtx[3][1];
dest[3][2] =
- mtx[0][2] * position[0] + mtx[1][2] * position[1] + mtx[2][2] * position[2] + mtx[3][2];
+ mtx[0][2] * position[0] + mtx[1][2] * position[1] + mtx[2][2] * position[2] + mtx[3][2];
dest[3][3] = 1;
}
@@ -1796,7 +1818,8 @@ void mtxf_billboard(Mat4 dest, Mat4 mtx, Vec3f position, s16 angle) {
* 'yaw' is the angle which it should face
* 'pos' is the object's position in the world
*/
-void mtxf_align_terrain_normal(Mat4 dest, Vec3f upDir, Vec3f pos, s16 yaw) {
+void mtxf_align_terrain_normal(Mat4 dest, Vec3f upDir, Vec3f pos, s16 yaw)
+{
Vec3f lateralDir;
Vec3f leftDir;
Vec3f forwardDir;
@@ -1839,7 +1862,8 @@ void mtxf_align_terrain_normal(Mat4 dest, Vec3f upDir, Vec3f pos, s16 yaw) {
* 'pos' is the object's position in the world
* 'radius' is the distance from each triangle vertex to the center
*/
-void mtxf_align_terrain_triangle(Mat4 mtx, Vec3f pos, s16 yaw, f32 radius) {
+void mtxf_align_terrain_triangle(Mat4 mtx, Vec3f pos, s16 yaw, f32 radius)
+{
struct SM64SurfaceCollisionData *sp74;
Vec3f point0;
Vec3f point1;
@@ -1862,15 +1886,18 @@ void mtxf_align_terrain_triangle(Mat4 mtx, Vec3f pos, s16 yaw, f32 radius) {
point1[1] = find_floor(point1[0], pos[1] + 150, point1[2], &sp74);
point2[1] = find_floor(point2[0], pos[1] + 150, point2[2], &sp74);
- if (point0[1] - pos[1] < minY) {
+ if (point0[1] - pos[1] < minY)
+ {
point0[1] = pos[1];
}
- if (point1[1] - pos[1] < minY) {
+ if (point1[1] - pos[1] < minY)
+ {
point1[1] = pos[1];
}
- if (point2[1] - pos[1] < minY) {
+ if (point2[1] - pos[1] < minY)
+ {
point2[1] = pos[1];
}
@@ -1892,7 +1919,7 @@ void mtxf_align_terrain_triangle(Mat4 mtx, Vec3f pos, s16 yaw, f32 radius) {
mtx[1][0] = yColumn[0];
mtx[1][1] = yColumn[1];
mtx[1][2] = yColumn[2];
- mtx[3][1] = (avgY < pos[1]) ? pos[1] : avgY;
+ mtx[3][1] = avgY < pos[1] ? pos[1] : avgY;
mtx[2][0] = zColumn[0];
mtx[2][1] = zColumn[1];
@@ -1913,7 +1940,8 @@ void mtxf_align_terrain_triangle(Mat4 mtx, Vec3f pos, s16 yaw, f32 radius) {
* The resulting matrix represents first applying transformation b and
* then a.
*/
-void mtxf_mul(Mat4 dest, Mat4 a, Mat4 b) {
+void mtxf_mul(Mat4 dest, Mat4 a, Mat4 b)
+{
Mat4 temp;
register f32 entry0;
register f32 entry1;
@@ -1960,10 +1988,12 @@ void mtxf_mul(Mat4 dest, Mat4 a, Mat4 b) {
/**
* Set matrix 'dest' to 'mtx' scaled by vector s
*/
-void mtxf_scale_vec3f(Mat4 dest, Mat4 mtx, Vec3f s) {
+void mtxf_scale_vec3f(Mat4 dest, Mat4 mtx, Vec3f s)
+{
register s32 i;
- for (i = 0; i < 4; i++) {
+ for (i = 0; i < 4; i++)
+ {
dest[0][i] = mtx[0][i] * s[0];
dest[1][i] = mtx[1][i] * s[1];
dest[2][i] = mtx[2][i] * s[2];
@@ -1976,7 +2006,8 @@ void mtxf_scale_vec3f(Mat4 dest, Mat4 mtx, Vec3f s) {
* to the point. Note that the bottom row is assumed to be [0, 0, 0, 1], which is
* true for transformation matrices if the translation has a w component of 1.
*/
-void mtxf_mul_vec3s(Mat4 mtx, Vec3s b) {
+void mtxf_mul_vec3s(Mat4 mtx, Vec3s b)
+{
register f32 x = b[0];
register f32 y = b[1];
register f32 z = b[2];
@@ -1986,7 +2017,8 @@ void mtxf_mul_vec3s(Mat4 mtx, Vec3s b) {
b[2] = x * mtx[0][2] + y * mtx[1][2] + z * mtx[2][2] + mtx[3][2];
}
-void mtxf_mul_vec3f(Mat4 mtx, Vec3f b) {
+void mtxf_mul_vec3f(Mat4 mtx, Vec3f b)
+{
register f32 x = b[0];
register f32 y = b[1];
register f32 z = b[2];
@@ -1994,7 +2026,8 @@ void mtxf_mul_vec3f(Mat4 mtx, Vec3f b) {
b[0] = x * mtx[0][0] + y * mtx[1][0] + z * mtx[2][0] + mtx[3][0];
b[1] = x * mtx[0][1] + y * mtx[1][1] + z * mtx[2][1] + mtx[3][1];
b[2] = x * mtx[0][2] + y * mtx[1][2] + z * mtx[2][2] + mtx[3][2];
-}
+}
+
/**
* Convert float matrix 'src' to fixed point matrix 'dest'.
* The float matrix may not contain entries larger than 65536 or the console
@@ -2004,30 +2037,33 @@ void mtxf_mul_vec3f(Mat4 mtx, Vec3f b) {
* exception. On Wii and Wii U Virtual Console the value will simply be clamped
* and no crashes occur.
*/
-void mtxf_to_mtx(Mtx *dest, Mat4 src) {
-#ifdef AVOID_UB
+void mtxf_to_mtx(Mtx *dest, Mat4 src)
+{
+ #ifdef AVOID_UB
// Avoid type-casting which is technically UB by calling the equivalent
// guMtxF2L function. This helps little-endian systems, as well.
guMtxF2L(src, dest);
-#else
+ #else
s32 asFixedPoint;
register s32 i;
- register s16 *a3 = (s16 *) dest; // all integer parts stored in first 16 bytes
- register s16 *t0 = (s16 *) dest + 16; // all fraction parts stored in last 16 bytes
- register f32 *t1 = (f32 *) src;
+ register s16 *a3 = (s16 *)dest; // all integer parts stored in first 16 bytes
+ register s16 *t0 = (s16 *)dest + 16; // all fraction parts stored in last 16 bytes
+ register f32 *t1 = (f32 *)src;
- for (i = 0; i < 16; i++) {
+ for (i = 0; i < 16; i++)
+ {
asFixedPoint = *t1++ * (1 << 16); //! float-to-integer conversion responsible for PU crashes
*a3++ = GET_HIGH_S16_OF_32(asFixedPoint); // integer part
- *t0++ = GET_LOW_S16_OF_32(asFixedPoint); // fraction part
+ *t0++ = GET_LOW_S16_OF_32(asFixedPoint); // fraction part
}
-#endif
+ #endif
}
/**
* Set 'mtx' to a transformation matrix that rotates around the z axis.
*/
-void mtxf_rotate_xy(Mtx *mtx, s16 angle) {
+void mtxf_rotate_xy(Mtx *mtx, s16 angle)
+{
Mat4 temp;
mtxf_identity(temp);
@@ -2046,17 +2082,18 @@ void mtxf_rotate_xy(Mtx *mtx, s16 angle) {
* objMtx back from screen orientation to world orientation, and then subtracting
* the camera position.
*/
-void get_pos_from_transform_mtx(Vec3f dest, Mat4 objMtx, Mat4 camMtx) {
+void get_pos_from_transform_mtx(Vec3f dest, Mat4 objMtx, Mat4 camMtx)
+{
f32 camX = camMtx[3][0] * camMtx[0][0] + camMtx[3][1] * camMtx[0][1] + camMtx[3][2] * camMtx[0][2];
f32 camY = camMtx[3][0] * camMtx[1][0] + camMtx[3][1] * camMtx[1][1] + camMtx[3][2] * camMtx[1][2];
f32 camZ = camMtx[3][0] * camMtx[2][0] + camMtx[3][1] * camMtx[2][1] + camMtx[3][2] * camMtx[2][2];
dest[0] =
- objMtx[3][0] * camMtx[0][0] + objMtx[3][1] * camMtx[0][1] + objMtx[3][2] * camMtx[0][2] - camX;
+ objMtx[3][0] * camMtx[0][0] + objMtx[3][1] * camMtx[0][1] + objMtx[3][2] * camMtx[0][2] - camX;
dest[1] =
- objMtx[3][0] * camMtx[1][0] + objMtx[3][1] * camMtx[1][1] + objMtx[3][2] * camMtx[1][2] - camY;
+ objMtx[3][0] * camMtx[1][0] + objMtx[3][1] * camMtx[1][1] + objMtx[3][2] * camMtx[1][2] - camY;
dest[2] =
- objMtx[3][0] * camMtx[2][0] + objMtx[3][1] * camMtx[2][1] + objMtx[3][2] * camMtx[2][2] - camZ;
+ objMtx[3][0] * camMtx[2][0] + objMtx[3][1] * camMtx[2][1] + objMtx[3][2] * camMtx[2][2] - camZ;
}
/**
@@ -2064,7 +2101,8 @@ void get_pos_from_transform_mtx(Vec3f dest, Mat4 objMtx, Mat4 camMtx) {
* of that vector, as well as the yaw and pitch angles.
* Basically it converts the direction to spherical coordinates.
*/
-void vec3f_get_dist_and_angle(Vec3f from, Vec3f to, f32 *dist, s16 *pitch, s16 *yaw) {
+void vec3f_get_dist_and_angle(Vec3f from, Vec3f to, f32 *dist, s16 *pitch, s16 *yaw)
+{
register f32 x = to[0] - from[0];
register f32 y = to[1] - from[1];
register f32 z = to[2] - from[2];
@@ -2078,7 +2116,8 @@ void vec3f_get_dist_and_angle(Vec3f from, Vec3f to, f32 *dist, s16 *pitch, s16 *
* Construct the 'to' point which is distance 'dist' away from the 'from' position,
* and has the angles pitch and yaw.
*/
-void vec3f_set_dist_and_angle(Vec3f from, Vec3f to, f32 dist, s16 pitch, s16 yaw) {
+void vec3f_set_dist_and_angle(Vec3f from, Vec3f to, f32 dist, s16 pitch, s16 yaw)
+{
to[0] = from[0] + dist * coss(pitch) * sins(yaw);
to[1] = from[1] + dist * sins(pitch);
to[2] = from[2] + dist * coss(pitch) * coss(yaw);
@@ -2088,18 +2127,24 @@ void vec3f_set_dist_and_angle(Vec3f from, Vec3f to, f32 dist, s16 pitch, s16 yaw
* Return the value 'current' after it tries to approach target, going up at
* most 'inc' and going down at most 'dec'.
*/
-s32 approach_s32(s32 current, s32 target, s32 inc, s32 dec) {
+s32 approach_s32(s32 current, s32 target, s32 inc, s32 dec)
+{
//! If target is close to the max or min s32, then it's possible to overflow
// past it without stopping.
- if (current < target) {
+ if (current < target)
+ {
current += inc;
- if (current > target) {
+ if (current > target)
+ {
current = target;
}
- } else {
+ }
+ else
+ {
current -= dec;
- if (current < target) {
+ if (current < target)
+ {
current = target;
}
}
@@ -2110,15 +2155,21 @@ s32 approach_s32(s32 current, s32 target, s32 inc, s32 dec) {
* Return the value 'current' after it tries to approach target, going up at
* most 'inc' and going down at most 'dec'.
*/
-f32 approach_f32(f32 current, f32 target, f32 inc, f32 dec) {
- if (current < target) {
+f32 approach_f32(f32 current, f32 target, f32 inc, f32 dec)
+{
+ if (current < target)
+ {
current += inc;
- if (current > target) {
+ if (current > target)
+ {
current = target;
}
- } else {
+ }
+ else
+ {
current -= dec;
- if (current < target) {
+ if (current < target)
+ {
current = target;
}
}
@@ -2129,12 +2180,16 @@ f32 approach_f32(f32 current, f32 target, f32 inc, f32 dec) {
* Helper function for atan2s. Does a look up of the arctangent of y/x assuming
* the resulting angle is in range [0, 0x2000] (1/8 of a circle).
*/
-static u16 atan2_lookup(f32 y, f32 x) {
+static u16 atan2_lookup(f32 y, f32 x)
+{
u16 ret;
- if (x == 0) {
+ if (x == 0)
+ {
ret = gArctanTable[0];
- } else {
+ }
+ else
+ {
ret = gArctanTable[(s32)(y / x * 1024 + 0.5f)];
}
return ret;
@@ -2144,37 +2199,59 @@ static u16 atan2_lookup(f32 y, f32 x) {
* Compute the angle from (0, 0) to (x, y) as a s16. Given that terrain is in
* the xz-plane, this is commonly called with (z, x) to get a yaw angle.
*/
-s16 atan2s(f32 y, f32 x) {
+s16 atan2s(f32 y, f32 x)
+{
u16 ret;
- if (x >= 0) {
- if (y >= 0) {
- if (y >= x) {
+ if (x >= 0)
+ {
+ if (y >= 0)
+ {
+ if (y >= x)
+ {
ret = atan2_lookup(x, y);
- } else {
+ }
+ else
+ {
ret = 0x4000 - atan2_lookup(y, x);
}
- } else {
+ }
+ else
+ {
y = -y;
- if (y < x) {
+ if (y < x)
+ {
ret = 0x4000 + atan2_lookup(y, x);
- } else {
+ }
+ else
+ {
ret = 0x8000 - atan2_lookup(x, y);
}
}
- } else {
+ }
+ else
+ {
x = -x;
- if (y < 0) {
+ if (y < 0)
+ {
y = -y;
- if (y >= x) {
+ if (y >= x)
+ {
ret = 0x8000 + atan2_lookup(x, y);
- } else {
+ }
+ else
+ {
ret = 0xC000 - atan2_lookup(y, x);
}
- } else {
- if (y < x) {
+ }
+ else
+ {
+ if (y < x)
+ {
ret = 0xC000 + atan2_lookup(y, x);
- } else {
+ }
+ else
+ {
ret = -atan2_lookup(x, y);
}
}
@@ -2220,14 +2297,16 @@ s16 atan2s(f32 y, f32 x) {
* [0, 0, 0, 0, 1, 2, ... n-1, n, n, n, n]
* TODO: verify the classification of the spline / figure out how polynomials were computed
*/
-void spline_get_weights(Vec4f result, f32 t, UNUSED s32 c) {
+void spline_get_weights(Vec4f result, f32 t, UNUSED s32 c)
+{
f32 tinv = 1 - t;
f32 tinv2 = tinv * tinv;
f32 tinv3 = tinv2 * tinv;
f32 t2 = t * t;
f32 t3 = t2 * t;
- switch (gSplineState) {
+ switch (gSplineState)
+ {
case CURVE_BEGIN_1:
result[0] = tinv3;
result[1] = t3 * 1.75f - t2 * 4.5f + t * 3.0f;
@@ -2236,20 +2315,20 @@ void spline_get_weights(Vec4f result, f32 t, UNUSED s32 c) {
break;
case CURVE_BEGIN_2:
result[0] = tinv3 * 0.25f;
- result[1] = t3 * (7 / 12.0f) - t2 * 1.25f + t * 0.25f + (7 / 12.0f);
- result[2] = -t3 * 0.5f + t2 * 0.5f + t * 0.5f + (1 / 6.0f);
+ result[1] = t3 * (7 / 12.0f) - t2 * 1.25f + t * 0.25f + 7 / 12.0f;
+ result[2] = -t3 * 0.5f + t2 * 0.5f + t * 0.5f + 1 / 6.0f;
result[3] = t3 * (1 / 6.0f);
break;
case CURVE_MIDDLE:
result[0] = tinv3 * (1 / 6.0f);
- result[1] = t3 * 0.5f - t2 + (4 / 6.0f);
- result[2] = -t3 * 0.5f + t2 * 0.5f + t * 0.5f + (1 / 6.0f);
+ result[1] = t3 * 0.5f - t2 + 4 / 6.0f;
+ result[2] = -t3 * 0.5f + t2 * 0.5f + t * 0.5f + 1 / 6.0f;
result[3] = t3 * (1 / 6.0f);
break;
case CURVE_END_1:
result[0] = tinv3 * (1 / 6.0f);
- result[1] = -tinv3 * 0.5f + tinv2 * 0.5f + tinv * 0.5f + (1 / 6.0f);
- result[2] = tinv3 * (7 / 12.0f) - tinv2 * 1.25f + tinv * 0.25f + (7 / 12.0f);
+ result[1] = -tinv3 * 0.5f + tinv2 * 0.5f + tinv * 0.5f + 1 / 6.0f;
+ result[2] = tinv3 * (7 / 12.0f) - tinv2 * 1.25f + tinv * 0.25f + 7 / 12.0f;
result[3] = t3 * 0.25f;
break;
case CURVE_END_2:
@@ -2269,7 +2348,8 @@ void spline_get_weights(Vec4f result, f32 t, UNUSED s32 c) {
* The array should end with three entries with s=0 (infinite keyframe duration).
* That's because the spline has a 3rd degree polynomial, so it looks 3 points ahead.
*/
-void anim_spline_init(Vec4s *keyFrames) {
+void anim_spline_init(Vec4s *keyFrames)
+{
gSplineKeyframe = keyFrames;
gSplineKeyframeFraction = 0;
gSplineState = 1;
@@ -2280,28 +2360,33 @@ void anim_spline_init(Vec4s *keyFrames) {
* anim_spline_init should be called before polling for vectors.
* Returns TRUE when the last point is reached, FALSE otherwise.
*/
-s32 anim_spline_poll(Vec3f result) {
+s32 anim_spline_poll(Vec3f result)
+{
Vec4f weights;
s32 i;
s32 hasEnded = FALSE;
vec3f_copy(result, gVec3fZero);
spline_get_weights(weights, gSplineKeyframeFraction, gSplineState);
- for (i = 0; i < 4; i++) {
+ for (i = 0; i < 4; i++)
+ {
result[0] += weights[i] * gSplineKeyframe[i][1];
result[1] += weights[i] * gSplineKeyframe[i][2];
result[2] += weights[i] * gSplineKeyframe[i][3];
}
- if ((gSplineKeyframeFraction += gSplineKeyframe[0][0] / 1000.0f) >= 1) {
+ if ((gSplineKeyframeFraction += gSplineKeyframe[0][0] / 1000.0f) >= 1)
+ {
gSplineKeyframe++;
gSplineKeyframeFraction--;
- switch (gSplineState) {
+ switch (gSplineState)
+ {
case CURVE_END_2:
hasEnded = TRUE;
break;
case CURVE_MIDDLE:
- if (gSplineKeyframe[2][0] == 0) {
+ if (gSplineKeyframe[2][0] == 0)
+ {
gSplineState = CURVE_END_1;
}
break;
@@ -2315,7 +2400,6 @@ s32 anim_spline_poll(Vec3f result) {
}
-
// From object_helpers.c
/**
@@ -2326,9 +2410,11 @@ s32 anim_spline_poll(Vec3f result) {
* | 0 0 0 1 |
* i.e. a matrix representing a linear transformation over 3 space.
*/
-void linear_mtxf_mul_vec3f(Mat4 m, Vec3f dst, Vec3f v) {
+void linear_mtxf_mul_vec3f(Mat4 m, Vec3f dst, Vec3f v)
+{
s32 i;
- for (i = 0; i < 3; i++) {
+ for (i = 0; i < 3; i++)
+ {
dst[i] = m[0][i] * v[0] + m[1][i] * v[1] + m[2][i] * v[2];
}
}
@@ -2341,9 +2427,11 @@ void linear_mtxf_mul_vec3f(Mat4 m, Vec3f dst, Vec3f v) {
* | 0 0 0 1 |
* i.e. a matrix representing a linear transformation over 3 space.
*/
-void linear_mtxf_transpose_mul_vec3f(Mat4 m, Vec3f dst, Vec3f v) {
+void linear_mtxf_transpose_mul_vec3f(Mat4 m, Vec3f dst, Vec3f v)
+{
s32 i;
- for (i = 0; i < 3; i++) {
+ for (i = 0; i < 3; i++)
+ {
dst[i] = m[i][0] * v[0] + m[i][1] * v[1] + m[i][2] * v[2];
}
}
diff --git a/src/decomp/engine/math_util.h b/src/decomp/engine/math_util.h
index a035bb5..0bbd8dd 100644
--- a/src/decomp/engine/math_util.h
+++ b/src/decomp/engine/math_util.h
@@ -34,49 +34,87 @@ extern f32 gCosineTable[];
#define sqr(x) ((x) * (x))
void *vec3f_copy(Vec3f dest, Vec3f src);
+
void *vec3f_set(Vec3f dest, f32 x, f32 y, f32 z);
+
void *vec3f_add(Vec3f dest, Vec3f a);
+
void *vec3f_sum(Vec3f dest, Vec3f a, Vec3f b);
+
void *vec3s_copy(Vec3s dest, Vec3s src);
+
void *vec3s_set(Vec3s dest, s16 x, s16 y, s16 z);
+
void *vec3s_add(Vec3s dest, Vec3s a);
+
void *vec3s_sum(Vec3s dest, Vec3s a, Vec3s b);
+
void *vec3s_sub(Vec3s dest, Vec3s a);
+
void *vec3s_to_vec3f(Vec3f dest, Vec3s a);
+
void *vec3f_to_vec3s(Vec3s dest, Vec3f a);
+
void *find_vector_perpendicular_to_plane(Vec3f dest, Vec3f a, Vec3f b, Vec3f c);
+
void *vec3f_cross(Vec3f dest, Vec3f a, Vec3f b);
+
void *vec3f_normalize(Vec3f dest);
+
void mtxf_copy(Mat4 dest, Mat4 src);
+
void mtxf_identity(Mat4 mtx);
+
void mtxf_translate(Mat4 dest, Vec3f b);
+
void mtxf_lookat(Mat4 mtx, Vec3f from, Vec3f to, s16 roll);
+
void mtxf_rotate_zxy_and_translate(Mat4 dest, Vec3f translate, Vec3s rotate);
+
void mtxf_rotate_xyz_and_translate(Mat4 dest, Vec3f b, Vec3s c);
+
void mtxf_billboard(Mat4 dest, Mat4 mtx, Vec3f position, s16 angle);
+
void mtxf_align_terrain_normal(Mat4 dest, Vec3f upDir, Vec3f pos, s16 yaw);
+
void mtxf_align_terrain_triangle(Mat4 mtx, Vec3f pos, s16 yaw, f32 radius);
+
void mtxf_mul(Mat4 dest, Mat4 a, Mat4 b);
+
void mtxf_scale_vec3f(Mat4 dest, Mat4 mtx, Vec3f s);
+
void mtxf_mul_vec3s(Mat4 mtx, Vec3s b);
+
void mtxf_mul_vec3f(Mat4 mtx, Vec3f b);
+
void mtxf_to_mtx(Mtx *dest, Mat4 src);
+
void mtxf_rotate_xy(Mtx *mtx, s16 angle);
+
void get_pos_from_transform_mtx(Vec3f dest, Mat4 objMtx, Mat4 camMtx);
+
void vec3f_get_dist_and_angle(Vec3f from, Vec3f to, f32 *dist, s16 *pitch, s16 *yaw);
-void vec3f_set_dist_and_angle(Vec3f from, Vec3f to, f32 dist, s16 pitch, s16 yaw);
+
+void vec3f_set_dist_and_angle(Vec3f from, Vec3f to, f32 dist, s16 pitch, s16 yaw);
+
s32 approach_s32(s32 current, s32 target, s32 inc, s32 dec);
+
f32 approach_f32(f32 current, f32 target, f32 inc, f32 dec);
+
s16 atan2s(f32 y, f32 x);
+
// libsm64: `atan2f()` is not used anywhere and collides with `math.h`'s definition of the function, better to remove it entirely.
// f32 atan2f(f32 a, f32 b);
void spline_get_weights(Vec4f result, f32 t, UNUSED s32 c);
-void anim_spline_init(Vec4s *keyFrames);
+
+void anim_spline_init(Vec4s * keyFrames);
+
s32 anim_spline_poll(Vec3f result);
// From object_helpers.c
void linear_mtxf_mul_vec3f(Mat4 m, Vec3f dst, Vec3f v);
+
void linear_mtxf_transpose_mul_vec3f(Mat4 m, Vec3f dst, Vec3f v);
diff --git a/src/decomp/engine/surface_collision.c b/src/decomp/engine/surface_collision.c
index 94b2ba1..8424c8c 100644
--- a/src/decomp/engine/surface_collision.c
+++ b/src/decomp/engine/surface_collision.c
@@ -8,7 +8,8 @@
/**
* Iterate through the list of ceilings and find the first ceiling over a given point.
*/
-static struct SM64SurfaceCollisionData *find_ceil_from_list( f32 x, f32 y, f32 z, f32 *pheight) {
+static struct SM64SurfaceCollisionData *find_ceil_from_list(f32 x, f32 y, f32 z, f32 *pheight)
+{
register struct SM64SurfaceCollisionData *surf;
register f32 x1, z1, x2, z2, x3, z3;
struct SM64SurfaceCollisionData *ceil = NULL;
@@ -16,74 +17,83 @@ static struct SM64SurfaceCollisionData *find_ceil_from_list( f32 x, f32 y, f32 z
ceil = NULL;
uint32_t groupCount = loaded_surface_iter_group_count();
- for( int i = 0; i < groupCount; ++i ) {
- uint32_t surfCount = loaded_surface_iter_group_size( i );
- for( int j = 0; j < surfCount; ++j ) {
- surf = loaded_surface_iter_get_at_index( i, j );
-
- // libsm64: Weed out surfaces whose triangles are actually line segs. TODO do this at surface load time
- if( !surf->isValid ) continue;
-
- // Do the check normally done in add_surface_to_cell
- if( surf->normal.y >= -0.01f ) continue;
-
- x1 = surf->vertex1[0];
- z1 = surf->vertex1[2];
- z2 = surf->vertex2[2];
- x2 = surf->vertex2[0];
-
- // Checking if point is in bounds of the triangle laterally.
- if ((z1 - z) * (x2 - x1) - (x1 - x) * (z2 - z1) > 0) {
- continue;
- }
-
- // Slight optimization by checking these later.
- x3 = surf->vertex3[0];
- z3 = surf->vertex3[2];
- if ((z2 - z) * (x3 - x2) - (x2 - x) * (z3 - z2) > 0) {
- continue;
- }
- if ((z3 - z) * (x1 - x3) - (x3 - x) * (z1 - z3) > 0) {
- continue;
- }
-
+ for (int i = 0; i < groupCount; ++i)
+ {
+ uint32_t surfCount = loaded_surface_iter_group_size(i);
+ for (int j = 0; j < surfCount; ++j)
{
- f32 nx = surf->normal.x;
- f32 ny = surf->normal.y;
- f32 nz = surf->normal.z;
- f32 oo = surf->originOffset;
- f32 height;
+ surf = loaded_surface_iter_get_at_index(i, j);
- // If a wall, ignore it. Likely a remnant, should never occur.
- if (ny == 0.0f) {
- continue;
- }
+ // libsm64: Weed out surfaces whose triangles are actually line segs. TODO do this at surface load time
+ if (!surf->isValid) continue;
- // Find the ceil height at the specific point.
- height = -(x * nx + nz * z + oo) / ny;
+ // Do the check normally done in add_surface_to_cell
+ if (surf->normal.y >= -0.01f) continue;
- // Checks for ceiling interaction with a 78 unit buffer.
- //! (Exposed Ceilings) Because any point above a ceiling counts
- // as interacting with a ceiling, ceilings far below can cause
- // "invisible walls" that are really just exposed ceilings.
- if (y - (height - -78.0f) > 0.0f) {
- continue;
- }
+ x1 = surf->vertex1[0];
+ z1 = surf->vertex1[2];
+ z2 = surf->vertex2[2];
+ x2 = surf->vertex2[0];
- if( height < *pheight )
+ // Checking if point is in bounds of the triangle laterally.
+ if ((z1 - z) * (x2 - x1) - (x1 - x) * (z2 - z1) > 0)
{
- *pheight = height;
- ceil = surf;
+ continue;
+ }
+
+ // Slight optimization by checking these later.
+ x3 = surf->vertex3[0];
+ z3 = surf->vertex3[2];
+ if ((z2 - z) * (x3 - x2) - (x2 - x) * (z3 - z2) > 0)
+ {
+ continue;
+ }
+ if ((z3 - z) * (x1 - x3) - (x3 - x) * (z1 - z3) > 0)
+ {
+ continue;
+ }
+
+ {
+ f32 nx = surf->normal.x;
+ f32 ny = surf->normal.y;
+ f32 nz = surf->normal.z;
+ f32 oo = surf->originOffset;
+ f32 height;
+
+ // If a wall, ignore it. Likely a remnant, should never occur.
+ if (ny == 0.0f)
+ {
+ continue;
+ }
+
+ // Find the ceil height at the specific point.
+ height = -(x * nx + nz * z + oo) / ny;
+
+ // Checks for ceiling interaction with a 78 unit buffer.
+ //! (Exposed Ceilings) Because any point above a ceiling counts
+ // as interacting with a ceiling, ceilings far below can cause
+ // "invisible walls" that are really just exposed ceilings.
+ if (y - (height - -78.0f) > 0.0f)
+ {
+ continue;
+ }
+
+ if (height < *pheight)
+ {
+ *pheight = height;
+ ceil = surf;
+ }
}
}
- }}
+ }
return ceil;
}
/**
* Iterate through the list of floors and find the first floor under a given point.
*/
-static struct SM64SurfaceCollisionData *find_floor_from_list( f32 x, f32 y, f32 z, f32 *pheight) {
+static struct SM64SurfaceCollisionData *find_floor_from_list(f32 x, f32 y, f32 z, f32 *pheight)
+{
register struct SM64SurfaceCollisionData *surf;
register f32 x1, z1, x2, z2, x3, z3;
f32 nx, ny, nz;
@@ -92,65 +102,74 @@ static struct SM64SurfaceCollisionData *find_floor_from_list( f32 x, f32 y, f32
struct SM64SurfaceCollisionData *floor = NULL;
uint32_t groupCount = loaded_surface_iter_group_count();
- for( int i = 0; i < groupCount; ++i ) {
- uint32_t surfCount = loaded_surface_iter_group_size( i );
- for( int j = 0; j < surfCount; ++j ) {
- surf = loaded_surface_iter_get_at_index( i, j );
-
- // libsm64: Weed out surfaces whose triangles are actually line segs. TODO do this at surface load time
- if( !surf->isValid ) continue;
-
- // Do the check normally done in add_surface_to_cell
- if( surf->normal.y <= 0.01f ) continue;
-
- x1 = surf->vertex1[0];
- z1 = surf->vertex1[2];
- x2 = surf->vertex2[0];
- z2 = surf->vertex2[2];
-
- // Check that the point is within the triangle bounds.
- if ((z1 - z) * (x2 - x1) - (x1 - x) * (z2 - z1) < 0) {
- continue;
- }
-
- // To slightly save on computation time, set this later.
- x3 = surf->vertex3[0];
- z3 = surf->vertex3[2];
-
- if ((z2 - z) * (x3 - x2) - (x2 - x) * (z3 - z2) < 0) {
- continue;
- }
- if ((z3 - z) * (x1 - x3) - (x3 - x) * (z1 - z3) < 0) {
- continue;
- }
-
- nx = surf->normal.x;
- ny = surf->normal.y;
- nz = surf->normal.z;
- oo = surf->originOffset;
-
- // If a wall, ignore it. Likely a remnant, should never occur.
- if (ny == 0.0f) {
- continue;
- }
-
- // Find the height of the floor at a given location.
- height = -(x * nx + nz * z + oo) / ny;
- // Checks for floor interaction with a 78 unit buffer.
- if (y - (height + -78.0f) < 0.0f) {
- continue;
- }
-
- if( height > *pheight )
+ for (int i = 0; i < groupCount; ++i)
+ {
+ uint32_t surfCount = loaded_surface_iter_group_size(i);
+ for (int j = 0; j < surfCount; ++j)
{
- *pheight = height;
- floor = surf;
+ surf = loaded_surface_iter_get_at_index(i, j);
+
+ // libsm64: Weed out surfaces whose triangles are actually line segs. TODO do this at surface load time
+ if (!surf->isValid) continue;
+
+ // Do the check normally done in add_surface_to_cell
+ if (surf->normal.y <= 0.01f) continue;
+
+ x1 = surf->vertex1[0];
+ z1 = surf->vertex1[2];
+ x2 = surf->vertex2[0];
+ z2 = surf->vertex2[2];
+
+ // Check that the point is within the triangle bounds.
+ if ((z1 - z) * (x2 - x1) - (x1 - x) * (z2 - z1) < 0)
+ {
+ continue;
+ }
+
+ // To slightly save on computation time, set this later.
+ x3 = surf->vertex3[0];
+ z3 = surf->vertex3[2];
+
+ if ((z2 - z) * (x3 - x2) - (x2 - x) * (z3 - z2) < 0)
+ {
+ continue;
+ }
+ if ((z3 - z) * (x1 - x3) - (x3 - x) * (z1 - z3) < 0)
+ {
+ continue;
+ }
+
+ nx = surf->normal.x;
+ ny = surf->normal.y;
+ nz = surf->normal.z;
+ oo = surf->originOffset;
+
+ // If a wall, ignore it. Likely a remnant, should never occur.
+ if (ny == 0.0f)
+ {
+ continue;
+ }
+
+ // Find the height of the floor at a given location.
+ height = -(x * nx + nz * z + oo) / ny;
+ // Checks for floor interaction with a 78 unit buffer.
+ if (y - (height + -78.0f) < 0.0f)
+ {
+ continue;
+ }
+
+ if (height > *pheight)
+ {
+ *pheight = height;
+ floor = surf;
+ }
}
- }}
+ }
return floor;
}
-static s32 find_wall_collisions_from_list( struct SM64WallCollisionData *data) {
+static s32 find_wall_collisions_from_list(struct SM64WallCollisionData *data)
+{
register struct SM64SurfaceCollisionData *surf;
register f32 offset;
register f32 radius = data->radius;
@@ -163,129 +182,170 @@ static s32 find_wall_collisions_from_list( struct SM64WallCollisionData *data) {
s32 numCols = 0;
// Max collision radius = 200
- if (radius > 200.0f) {
+ if (radius > 200.0f)
+ {
radius = 200.0f;
}
uint32_t groupCount = loaded_surface_iter_group_count();
- for( int i = 0; i < groupCount; ++i ) {
- uint32_t surfCount = loaded_surface_iter_group_size( i );
- for( int j = 0; j < surfCount; ++j ) {
- surf = loaded_surface_iter_get_at_index( i, j );
+ for (int i = 0; i < groupCount; ++i)
+ {
+ uint32_t surfCount = loaded_surface_iter_group_size(i);
+ for (int j = 0; j < surfCount; ++j)
+ {
+ surf = loaded_surface_iter_get_at_index(i, j);
- // libsm64: Weed out surfaces whose triangles are actually line segs. TODO do this at surface load time
- if( !surf->isValid ) continue;
+ // libsm64: Weed out surfaces whose triangles are actually line segs. TODO do this at surface load time
+ if (!surf->isValid) continue;
- // Do the check normally done in add_surface_to_cell
- if( surf->normal.y < -0.01f || surf->normal.y > 0.01f ) continue;
+ // Do the check normally done in add_surface_to_cell
+ if (surf->normal.y < -0.01f || surf->normal.y > 0.01f) continue;
- if( surf->normal.x < -0.707f || surf->normal.x > 0.707f ) {
- surf->flags |= SURFACE_FLAG_X_PROJECTION;
- }
+ if (surf->normal.x < -0.707f || surf->normal.x > 0.707f)
+ {
+ surf->flags |= SURFACE_FLAG_X_PROJECTION;
+ }
- // Exclude a large number of walls immediately to optimize.
- if (y < surf->lowerY || y > surf->upperY) {
- continue;
- }
+ // Exclude a large number of walls immediately to optimize.
+ if (y < surf->lowerY || y > surf->upperY)
+ {
+ continue;
+ }
- offset = surf->normal.x * x + surf->normal.y * y + surf->normal.z * z + surf->originOffset;
+ offset = surf->normal.x * x + surf->normal.y * y + surf->normal.z * z + surf->originOffset;
- if (offset < -radius || offset > radius) {
- continue;
- }
+ if (offset < -radius || offset > radius)
+ {
+ continue;
+ }
- px = x;
- pz = z;
+ px = x;
+ pz = z;
- //! (Quantum Tunneling) Due to issues with the vertices walls choose and
- // the fact they are floating point, certain floating point positions
- // along the seam of two walls may collide with neither wall or both walls.
- if (surf->flags & SURFACE_FLAG_X_PROJECTION) {
- w1 = -surf->vertex1[2]; w2 = -surf->vertex2[2]; w3 = -surf->vertex3[2];
- y1 = surf->vertex1[1]; y2 = surf->vertex2[1]; y3 = surf->vertex3[1];
+ //! (Quantum Tunneling) Due to issues with the vertices walls choose and
+ // the fact they are floating point, certain floating point positions
+ // along the seam of two walls may collide with neither wall or both walls.
+ if (surf->flags & SURFACE_FLAG_X_PROJECTION)
+ {
+ w1 = -surf->vertex1[2];
+ w2 = -surf->vertex2[2];
+ w3 = -surf->vertex3[2];
+ y1 = surf->vertex1[1];
+ y2 = surf->vertex2[1];
+ y3 = surf->vertex3[1];
- if (surf->normal.x > 0.0f) {
- if ((y1 - y) * (w2 - w1) - (w1 - -pz) * (y2 - y1) > 0.0f) {
- continue;
+ if (surf->normal.x > 0.0f)
+ {
+ if ((y1 - y) * (w2 - w1) - (w1 - -pz) * (y2 - y1) > 0.0f)
+ {
+ continue;
+ }
+ if ((y2 - y) * (w3 - w2) - (w2 - -pz) * (y3 - y2) > 0.0f)
+ {
+ continue;
+ }
+ if ((y3 - y) * (w1 - w3) - (w3 - -pz) * (y1 - y3) > 0.0f)
+ {
+ continue;
+ }
}
- if ((y2 - y) * (w3 - w2) - (w2 - -pz) * (y3 - y2) > 0.0f) {
- continue;
- }
- if ((y3 - y) * (w1 - w3) - (w3 - -pz) * (y1 - y3) > 0.0f) {
- continue;
- }
- } else {
- if ((y1 - y) * (w2 - w1) - (w1 - -pz) * (y2 - y1) < 0.0f) {
- continue;
- }
- if ((y2 - y) * (w3 - w2) - (w2 - -pz) * (y3 - y2) < 0.0f) {
- continue;
- }
- if ((y3 - y) * (w1 - w3) - (w3 - -pz) * (y1 - y3) < 0.0f) {
- continue;
+ else
+ {
+ if ((y1 - y) * (w2 - w1) - (w1 - -pz) * (y2 - y1) < 0.0f)
+ {
+ continue;
+ }
+ if ((y2 - y) * (w3 - w2) - (w2 - -pz) * (y3 - y2) < 0.0f)
+ {
+ continue;
+ }
+ if ((y3 - y) * (w1 - w3) - (w3 - -pz) * (y1 - y3) < 0.0f)
+ {
+ continue;
+ }
}
}
- } else {
- w1 = surf->vertex1[0]; w2 = surf->vertex2[0]; w3 = surf->vertex3[0];
- y1 = surf->vertex1[1]; y2 = surf->vertex2[1]; y3 = surf->vertex3[1];
+ else
+ {
+ w1 = surf->vertex1[0];
+ w2 = surf->vertex2[0];
+ w3 = surf->vertex3[0];
+ y1 = surf->vertex1[1];
+ y2 = surf->vertex2[1];
+ y3 = surf->vertex3[1];
- if (surf->normal.z > 0.0f) {
- if ((y1 - y) * (w2 - w1) - (w1 - px) * (y2 - y1) > 0.0f) {
- continue;
+ if (surf->normal.z > 0.0f)
+ {
+ if ((y1 - y) * (w2 - w1) - (w1 - px) * (y2 - y1) > 0.0f)
+ {
+ continue;
+ }
+ if ((y2 - y) * (w3 - w2) - (w2 - px) * (y3 - y2) > 0.0f)
+ {
+ continue;
+ }
+ if ((y3 - y) * (w1 - w3) - (w3 - px) * (y1 - y3) > 0.0f)
+ {
+ continue;
+ }
}
- if ((y2 - y) * (w3 - w2) - (w2 - px) * (y3 - y2) > 0.0f) {
- continue;
- }
- if ((y3 - y) * (w1 - w3) - (w3 - px) * (y1 - y3) > 0.0f) {
- continue;
- }
- } else {
- if ((y1 - y) * (w2 - w1) - (w1 - px) * (y2 - y1) < 0.0f) {
- continue;
- }
- if ((y2 - y) * (w3 - w2) - (w2 - px) * (y3 - y2) < 0.0f) {
- continue;
- }
- if ((y3 - y) * (w1 - w3) - (w3 - px) * (y1 - y3) < 0.0f) {
- continue;
+ else
+ {
+ if ((y1 - y) * (w2 - w1) - (w1 - px) * (y2 - y1) < 0.0f)
+ {
+ continue;
+ }
+ if ((y2 - y) * (w3 - w2) - (w2 - px) * (y3 - y2) < 0.0f)
+ {
+ continue;
+ }
+ if ((y3 - y) * (w1 - w3) - (w3 - px) * (y1 - y3) < 0.0f)
+ {
+ continue;
+ }
}
}
- }
- // Ignore camera only surfaces.
- if (surf->type == SURFACE_CAMERA_BOUNDARY) {
- continue;
- }
+ // Ignore camera only surfaces.
+ if (surf->type == SURFACE_CAMERA_BOUNDARY)
+ {
+ continue;
+ }
- // If an object can pass through a vanish cap wall, pass through.
- if (surf->type == SURFACE_VANISH_CAP_WALLS) {
// If an object can pass through a vanish cap wall, pass through.
- if (gCurrentObject != NULL
- && (gCurrentObject->activeFlags & ACTIVE_FLAG_MOVE_THROUGH_GRATE)) {
- continue;
+ if (surf->type == SURFACE_VANISH_CAP_WALLS)
+ {
+ // If an object can pass through a vanish cap wall, pass through.
+ if (gCurrentObject != NULL
+ && gCurrentObject->activeFlags & ACTIVE_FLAG_MOVE_THROUGH_GRATE)
+ {
+ continue;
+ }
+
+ // If Mario has a vanish cap, pass through the vanish cap wall.
+ if (gCurrentObject != NULL && gCurrentObject == gMarioObject
+ && gMarioState->flags & MARIO_VANISH_CAP)
+ {
+ continue;
+ }
}
- // If Mario has a vanish cap, pass through the vanish cap wall.
- if (gCurrentObject != NULL && gCurrentObject == gMarioObject
- && (gMarioState->flags & MARIO_VANISH_CAP)) {
- continue;
+ //! (Wall Overlaps) Because this doesn't update the x and z local variables,
+ // multiple walls can push mario more than is required.
+ data->x += surf->normal.x * (radius - offset);
+ data->z += surf->normal.z * (radius - offset);
+
+ //! (Unreferenced Walls) Since this only returns the first four walls,
+ // this can lead to wall interaction being missed. Typically unreferenced walls
+ // come from only using one wall, however.
+ if (data->numWalls < 4)
+ {
+ data->walls[data->numWalls++] = surf;
}
+
+ numCols++;
}
-
- //! (Wall Overlaps) Because this doesn't update the x and z local variables,
- // multiple walls can push mario more than is required.
- data->x += surf->normal.x * (radius - offset);
- data->z += surf->normal.z * (radius - offset);
-
- //! (Unreferenced Walls) Since this only returns the first four walls,
- // this can lead to wall interaction being missed. Typically unreferenced walls
- // come from only using one wall, however.
- if (data->numWalls < 4) {
- data->walls[data->numWalls++] = surf;
- }
-
- numCols++;
- }}
+ }
return numCols;
}
@@ -335,8 +395,8 @@ s32 find_wall_collisions(struct SM64WallCollisionData *colData)
f32 find_ceil(f32 posX, f32 posY, f32 posZ, struct SM64SurfaceCollisionData **pceil)
{
f32 height = CELL_HEIGHT_LIMIT;
- *pceil = find_ceil_from_list( posX, posY, posZ, &height );
- return height;
+ *pceil = find_ceil_from_list(posX, posY, posZ, &height);
+ return height;
}
struct SM64FloorCollisionData sFloorGeo;
@@ -348,7 +408,8 @@ f32 find_floor_height_and_data(f32 xPos, f32 yPos, f32 zPos, struct SM64FloorCol
*floorGeo = NULL;
- if (floor != NULL) {
+ if (floor != NULL)
+ {
sFloorGeo.normalX = floor->normal.x;
sFloorGeo.normalY = floor->normal.y;
sFloorGeo.normalZ = floor->normal.z;
@@ -362,23 +423,23 @@ f32 find_floor_height_and_data(f32 xPos, f32 yPos, f32 zPos, struct SM64FloorCol
f32 find_floor_height(f32 x, f32 y, f32 z)
{
f32 height = FLOOR_LOWER_LIMIT;
- find_floor_from_list( x, y, z, &height );
- return height;
+ find_floor_from_list(x, y, z, &height);
+ return height;
}
f32 find_floor(f32 xPos, f32 yPos, f32 zPos, struct SM64SurfaceCollisionData **pfloor)
{
f32 height = FLOOR_LOWER_LIMIT;
- *pfloor = find_floor_from_list( xPos, yPos, zPos, &height );
- return height;
+ *pfloor = find_floor_from_list(xPos, yPos, zPos, &height);
+ return height;
}
f32 find_water_level(f32 x, f32 z)
{
- return -10000.0f;
+ return -10000.0f;
}
f32 find_poison_gas_level(f32 x, f32 z)
{
- return -10000.0f;
+ return -10000.0f;
}
diff --git a/src/decomp/engine/surface_collision.h b/src/decomp/engine/surface_collision.h
index ee1b958..d9211d6 100644
--- a/src/decomp/engine/surface_collision.h
+++ b/src/decomp/engine/surface_collision.h
@@ -7,18 +7,25 @@
#include "../include/types.h"
#define LEVEL_BOUNDARY_MAX 0x2000
-#define CELL_SIZE 0x400
+#define CELL_SIZE 0x400
#define CELL_HEIGHT_LIMIT 100000.f
#define FLOOR_LOWER_LIMIT -110000.f
s32 f32_find_wall_collision(f32 *xPtr, f32 *yPtr, f32 *zPtr, f32 offsetY, f32 radius);
+
s32 find_wall_collisions(struct SM64WallCollisionData *colData);
+
f32 find_ceil(f32 posX, f32 posY, f32 posZ, struct SM64SurfaceCollisionData **pceil);
+
f32 find_floor_height_and_data(f32 xPos, f32 yPos, f32 zPos, struct SM64FloorCollisionData **floorGeo);
+
f32 find_floor_height(f32 x, f32 y, f32 z);
+
f32 find_floor(f32 xPos, f32 yPos, f32 zPos, struct SM64SurfaceCollisionData **pfloor);
+
f32 find_water_level(f32 x, f32 z);
+
f32 find_poison_gas_level(f32 x, f32 z);
#endif // SURFACE_COLLISION_H
diff --git a/src/decomp/game/area.h b/src/decomp/game/area.h
index 84b05d6..31981b7 100644
--- a/src/decomp/game/area.h
+++ b/src/decomp/game/area.h
@@ -9,17 +9,24 @@
struct WarpNode
{
- /*00*/ u8 id;
- /*01*/ u8 destLevel;
- /*02*/ u8 destArea;
- /*03*/ u8 destNode;
+ /*00*/
+ u8 id;
+ /*01*/
+ u8 destLevel;
+ /*02*/
+ u8 destArea;
+ /*03*/
+ u8 destNode;
};
struct ObjectWarpNode
{
- /*0x00*/ struct WarpNode node;
- /*0x04*/ struct Object *object;
- /*0x08*/ struct ObjectWarpNode *next;
+ /*0x00*/
+ struct WarpNode node;
+ /*0x04*/
+ struct Object *object;
+ /*0x08*/
+ struct ObjectWarpNode *next;
};
// From Surface 0x1B to 0x1E
@@ -28,74 +35,118 @@ struct ObjectWarpNode
struct InstantWarp
{
- /*0x00*/ u8 id; // 0 = 0x1B / 1 = 0x1C / 2 = 0x1D / 3 = 0x1E
- /*0x01*/ u8 area;
- /*0x02*/ Vec3s displacement;
+ /*0x00*/
+ u8 id; // 0 = 0x1B / 1 = 0x1C / 2 = 0x1D / 3 = 0x1E
+ /*0x01*/
+ u8 area;
+ /*0x02*/
+ Vec3s displacement;
};
struct SpawnInfo
{
- /*0x00*/ Vec3f startPos;
- /*0x06*/ Vec3s startAngle;
- /*0x0C*/ s8 areaIndex;
- /*0x0D*/ s8 activeAreaIndex;
- /*0x10*/ u32 behaviorArg;
- /*0x14*/ void *behaviorScript;
- /*0x18*/ struct GraphNode *unk18;
- /*0x1C*/ struct SpawnInfo *next;
+ /*0x00*/
+ Vec3f startPos;
+ /*0x06*/
+ Vec3s startAngle;
+ /*0x0C*/
+ s8 areaIndex;
+ /*0x0D*/
+ s8 activeAreaIndex;
+ /*0x10*/
+ u32 behaviorArg;
+ /*0x14*/
+ void *behaviorScript;
+ /*0x18*/
+ struct GraphNode *unk18;
+ /*0x1C*/
+ struct SpawnInfo *next;
};
struct UnusedArea28
{
- /*0x00*/ s16 unk00;
- /*0x02*/ s16 unk02;
- /*0x04*/ s16 unk04;
- /*0x06*/ s16 unk06;
- /*0x08*/ s16 unk08;
+ /*0x00*/
+ s16 unk00;
+ /*0x02*/
+ s16 unk02;
+ /*0x04*/
+ s16 unk04;
+ /*0x06*/
+ s16 unk06;
+ /*0x08*/
+ s16 unk08;
};
struct Whirlpool
{
- /*0x00*/ Vec3s pos;
- /*0x03*/ s16 strength;
+ /*0x00*/
+ Vec3s pos;
+ /*0x03*/
+ s16 strength;
};
struct Area
{
- /*0x00*/ s8 index;
- /*0x01*/ s8 flags; // Only has 1 flag: 0x01 = Is this the active area?
-// /*0x02*/ u16 terrainType; // default terrain of the level (set from level script cmd 0x31) ; in libsm64 terrain is defined in the Surface struct
- /*0x04*/ struct GraphNodeRoot *unk04; // geometry layout data
- /*0x08*/ s16 *terrainData; // collision data (set from level script cmd 0x2E)
- /*0x0C*/ s8 *surfaceRooms; // (set from level script cmd 0x2F)
- /*0x10*/ s16 *macroObjects; // Macro Objects Ptr (set from level script cmd 0x39)
- /*0x14*/ struct ObjectWarpNode *warpNodes;
- /*0x18*/ struct WarpNode *paintingWarpNodes;
- /*0x1C*/ struct InstantWarp *instantWarps;
- /*0x20*/ struct SpawnInfo *objectSpawnInfos;
- /*0x24*/ struct Camera *camera;
- /*0x28*/ struct UnusedArea28 *unused28; // Filled by level script 0x3A, but is unused.
- /*0x2C*/ struct Whirlpool *whirlpools[2];
- /*0x34*/ u8 dialog[2]; // Level start dialog number (set by level script cmd 0x30)
- /*0x36*/ u16 musicParam;
- /*0x38*/ u16 musicParam2;
+ /*0x00*/
+ s8 index;
+ /*0x01*/
+ s8 flags; // Only has 1 flag: 0x01 = Is this the active area?
+ // /*0x02*/ u16 terrainType; // default terrain of the level (set from level script cmd 0x31) ; in libsm64 terrain is defined in the Surface struct
+ /*0x04*/
+ struct GraphNodeRoot *unk04; // geometry layout data
+ /*0x08*/
+ s16 *terrainData; // collision data (set from level script cmd 0x2E)
+ /*0x0C*/
+ s8 *surfaceRooms; // (set from level script cmd 0x2F)
+ /*0x10*/
+ s16 *macroObjects; // Macro Objects Ptr (set from level script cmd 0x39)
+ /*0x14*/
+ struct ObjectWarpNode *warpNodes;
+ /*0x18*/
+ struct WarpNode *paintingWarpNodes;
+ /*0x1C*/
+ struct InstantWarp *instantWarps;
+ /*0x20*/
+ struct SpawnInfo *objectSpawnInfos;
+ /*0x24*/
+ struct Camera *camera;
+ /*0x28*/
+ struct UnusedArea28 *unused28; // Filled by level script 0x3A, but is unused.
+ /*0x2C*/
+ struct Whirlpool *whirlpools[2];
+ /*0x34*/
+ u8 dialog[2]; // Level start dialog number (set by level script cmd 0x30)
+ /*0x36*/
+ u16 musicParam;
+ /*0x38*/
+ u16 musicParam2;
};
// All the transition data to be used in screen_transition.c
struct WarpTransitionData
{
- /*0x00*/ u8 red;
- /*0x01*/ u8 green;
- /*0x02*/ u8 blue;
+ /*0x00*/
+ u8 red;
+ /*0x01*/
+ u8 green;
+ /*0x02*/
+ u8 blue;
- /*0x04*/ s16 startTexRadius;
- /*0x06*/ s16 endTexRadius;
- /*0x08*/ s16 startTexX;
- /*0x0A*/ s16 startTexY;
- /*0x0C*/ s16 endTexX;
- /*0x0E*/ s16 endTexY;
+ /*0x04*/
+ s16 startTexRadius;
+ /*0x06*/
+ s16 endTexRadius;
+ /*0x08*/
+ s16 startTexX;
+ /*0x0A*/
+ s16 startTexY;
+ /*0x0C*/
+ s16 endTexX;
+ /*0x0E*/
+ s16 endTexY;
- /*0x10*/ s16 texTimer; // always 0, does seems to affect transition when disabled
+ /*0x10*/
+ s16 texTimer; // always 0, does seems to affect transition when disabled
};
#define WARP_TRANSITION_FADE_FROM_COLOR 0x00
@@ -111,11 +162,16 @@ struct WarpTransitionData
struct WarpTransition
{
- /*0x00*/ u8 isActive; // Is the transition active. (either TRUE or FALSE)
- /*0x01*/ u8 type; // Determines the type of transition to use (circle, star, etc.)
- /*0x02*/ u8 time; // Amount of time to complete the transition (in frames)
- /*0x03*/ u8 pauseRendering; // Should the game stop rendering. (either TRUE or FALSE)
- /*0x04*/ struct WarpTransitionData data;
+ /*0x00*/
+ u8 isActive; // Is the transition active. (either TRUE or FALSE)
+ /*0x01*/
+ u8 type; // Determines the type of transition to use (circle, star, etc.)
+ /*0x02*/
+ u8 time; // Amount of time to complete the transition (in frames)
+ /*0x03*/
+ u8 pauseRendering; // Should the game stop rendering. (either TRUE or FALSE)
+ /*0x04*/
+ struct WarpTransitionData data;
};
// extern struct GraphNode **gLoadedGraphNodes;
diff --git a/src/decomp/game/behavior_actions.c b/src/decomp/game/behavior_actions.c
index 2f07389..34425ef 100644
--- a/src/decomp/game/behavior_actions.c
+++ b/src/decomp/game/behavior_actions.c
@@ -4,13 +4,16 @@
#include "../shim.h"
// not sure what this is doing here. not in a behavior file.
-Gfx *geo_move_mario_part_from_parent(s32 run, UNUSED struct GraphNode *node, Mat4 mtx) {
+Gfx *geo_move_mario_part_from_parent(s32 run, UNUSED struct GraphNode *node, Mat4 mtx)
+{
Mat4 sp20;
struct Object *sp1C;
- if (run == TRUE) {
- sp1C = (struct Object *) gCurGraphNodeObject;
- if (sp1C == gMarioObject && sp1C->prevObj != NULL) {
+ if (run == TRUE)
+ {
+ sp1C = (struct Object *)gCurGraphNodeObject;
+ if (sp1C == gMarioObject && sp1C->prevObj != NULL)
+ {
create_transformation_from_matrices(sp20, mtx, *gCurGraphNodeCamera->matrixPtr);
obj_update_pos_from_parent_transformation(sp20, sp1C->prevObj);
obj_set_gfx_pos_from_pos(sp1C->prevObj);
diff --git a/src/decomp/game/camera.h b/src/decomp/game/camera.h
index 0d35181..a2b118f 100644
--- a/src/decomp/game/camera.h
+++ b/src/decomp/game/camera.h
@@ -32,7 +32,7 @@
* Because a mask is used by two levels, the pattern will repeat when more than 4 areas are used by a level.
*/
#define ZOOMOUT_AREA_MASK(level1Area1, level1Area2, level1Area3, level1Area4, \
- level2Area1, level2Area2, level2Area3, level2Area4) \
+ level2Area1, level2Area2, level2Area3, level2Area4) \
((level2Area4) << 7 | \
(level2Area3) << 6 | \
(level2Area2) << 5 | \
@@ -300,17 +300,24 @@ struct PlayerCameraState
/**
* Mario's action on this frame.
*/
- /*0x00*/ u32 action;
- /*0x04*/ Vec3f pos;
- /*0x10*/ Vec3s faceAngle;
- /*0x16*/ Vec3s headRotation;
- /*0x1C*/ s16 unused;
+ /*0x00*/
+ u32 action;
+ /*0x04*/
+ Vec3f pos;
+ /*0x10*/
+ Vec3s faceAngle;
+ /*0x16*/
+ Vec3s headRotation;
+ /*0x1C*/
+ s16 unused;
/**
* Set to nonzero when an event, such as entering a door, starting the credits, or throwing bowser,
* has happened on this frame.
*/
- /*0x1E*/ s16 cameraEvent;
- /*0x20*/ struct Object *usedObj;
+ /*0x1E*/
+ s16 cameraEvent;
+ /*0x20*/
+ struct Object *usedObj;
};
/**
@@ -319,15 +326,24 @@ struct PlayerCameraState
*/
struct TransitionInfo
{
- /*0x00*/ s16 posPitch;
- /*0x02*/ s16 posYaw;
- /*0x04*/ f32 posDist;
- /*0x08*/ s16 focPitch;
- /*0x0A*/ s16 focYaw;
- /*0x0C*/ f32 focDist;
- /*0x10*/ s32 framesLeft;
- /*0x14*/ Vec3f marioPos;
- /*0x20*/ u8 pad; // for the structs to align, there has to be an extra unused variable here. type is unknown.
+ /*0x00*/
+ s16 posPitch;
+ /*0x02*/
+ s16 posYaw;
+ /*0x04*/
+ f32 posDist;
+ /*0x08*/
+ s16 focPitch;
+ /*0x0A*/
+ s16 focYaw;
+ /*0x0C*/
+ f32 focDist;
+ /*0x10*/
+ s32 framesLeft;
+ /*0x14*/
+ Vec3f marioPos;
+ /*0x20*/
+ u8 pad; // for the structs to align, there has to be an extra unused variable here. type is unknown.
};
/**
@@ -336,9 +352,12 @@ struct TransitionInfo
*/
struct HandheldShakePoint
{
- /*0x00*/ s8 index; // only set to -1
- /*0x04 (aligned)*/ u32 pad;
- /*0x08*/ Vec3s point;
+ /*0x00*/
+ s8 index; // only set to -1
+ /*0x04 (aligned)*/
+ u32 pad;
+ /*0x08*/
+ Vec3s point;
}; // size = 0x10
struct Camera;
@@ -347,7 +366,8 @@ struct Camera;
* A function that is called by CameraTriggers and cutscene shots.
* These are concurrent: multiple CameraEvents can occur on the same frame.
*/
-typedef BAD_RETURN(s32) (*CameraEvent)(struct Camera *c);
+typedef BAD_RETURN (s32)(*CameraEvent)(struct Camera *c);
+
/**
* The same type as a CameraEvent, but because these are generally longer, and happen in sequential
* order, they're are called "shots," a term taken from cinematography.
@@ -403,24 +423,32 @@ struct Cutscene
struct CameraFOVStatus
{
/// The current function being used to set the camera's field of view (before any fov shake is applied).
- /*0x00*/ u8 fovFunc;
+ /*0x00*/
+ u8 fovFunc;
/// The current field of view in degrees
- /*0x04*/ f32 fov;
+ /*0x04*/
+ f32 fov;
// Fields used by shake_camera_fov()
/// The amount to change the current fov by in the fov shake effect.
- /*0x08*/ f32 fovOffset;
+ /*0x08*/
+ f32 fovOffset;
/// A bool set in fov_default() but unused otherwise
- /*0x0C*/ u32 unusedIsSleeping;
+ /*0x0C*/
+ u32 unusedIsSleeping;
/// The range in degrees to shake fov
- /*0x10*/ f32 shakeAmplitude;
+ /*0x10*/
+ f32 shakeAmplitude;
/// Used to calculate fovOffset, the phase through the shake's period.
- /*0x14*/ s16 shakePhase;
+ /*0x14*/
+ s16 shakePhase;
/// How much to progress through the shake period
- /*0x16*/ s16 shakeSpeed;
+ /*0x16*/
+ s16 shakeSpeed;
/// How much to decrease shakeAmplitude each frame.
- /*0x18*/ s16 decay;
+ /*0x18*/
+ s16 decay;
};
/**
@@ -443,20 +471,33 @@ struct CutsceneSplinePoint
*/
struct PlayerGeometry
{
- /*0x00*/ struct SM64SurfaceCollisionData *currFloor;
- /*0x04*/ f32 currFloorHeight;
- /*0x08*/ s16 currFloorType;
- /*0x0C*/ struct SM64SurfaceCollisionData *currCeil;
- /*0x10*/ s16 currCeilType;
- /*0x14*/ f32 currCeilHeight;
- /*0x18*/ struct SM64SurfaceCollisionData *prevFloor;
- /*0x1C*/ f32 prevFloorHeight;
- /*0x20*/ s16 prevFloorType;
- /*0x24*/ struct SM64SurfaceCollisionData *prevCeil;
- /*0x28*/ f32 prevCeilHeight;
- /*0x2C*/ s16 prevCeilType;
+ /*0x00*/
+ struct SM64SurfaceCollisionData *currFloor;
+ /*0x04*/
+ f32 currFloorHeight;
+ /*0x08*/
+ s16 currFloorType;
+ /*0x0C*/
+ struct SM64SurfaceCollisionData *currCeil;
+ /*0x10*/
+ s16 currCeilType;
+ /*0x14*/
+ f32 currCeilHeight;
+ /*0x18*/
+ struct SM64SurfaceCollisionData *prevFloor;
+ /*0x1C*/
+ f32 prevFloorHeight;
+ /*0x20*/
+ s16 prevFloorType;
+ /*0x24*/
+ struct SM64SurfaceCollisionData *prevCeil;
+ /*0x28*/
+ f32 prevCeilHeight;
+ /*0x2C*/
+ s16 prevCeilType;
/// Unused, but recalculated every frame
- /*0x30*/ f32 waterHeight;
+ /*0x30*/
+ f32 waterHeight;
};
/**
@@ -504,10 +545,14 @@ struct ParallelTrackingPoint
*/
struct CameraStoredInfo
{
- /*0x00*/ Vec3f pos;
- /*0x0C*/ Vec3f focus;
- /*0x18*/ f32 panDist;
- /*0x1C*/ f32 cannonYOffset;
+ /*0x00*/
+ Vec3f pos;
+ /*0x0C*/
+ Vec3f focus;
+ /*0x18*/
+ f32 panDist;
+ /*0x1C*/
+ f32 cannonYOffset;
};
/**
@@ -533,8 +578,10 @@ struct CutsceneVariable
*/
struct Camera
{
- /*0x00*/ u8 mode; // What type of mode the camera uses (see defines above)
- /*0x01*/ u8 defMode;
+ /*0x00*/
+ u8 mode; // What type of mode the camera uses (see defines above)
+ /*0x01*/
+ u8 defMode;
/**
* Determines what direction Mario moves in when the analog stick is moved.
*
@@ -543,24 +590,36 @@ struct Camera
* be. It's effectively the opposite of the camera's actual yaw. Use
* vec3f_get_dist_and_angle() if you need the camera's yaw.
*/
- /*0x02*/ s16 yaw;
- /*0x04*/ Vec3f focus;
- /*0x10*/ Vec3f pos;
- /*0x1C*/ Vec3f unusedVec1;
+ /*0x02*/
+ s16 yaw;
+ /*0x04*/
+ Vec3f focus;
+ /*0x10*/
+ Vec3f pos;
+ /*0x1C*/
+ Vec3f unusedVec1;
/// The x coordinate of the "center" of the area. The camera will rotate around this point.
/// For example, this is what makes the camera rotate around the hill in BoB
- /*0x28*/ f32 areaCenX;
+ /*0x28*/
+ f32 areaCenX;
/// The z coordinate of the "center" of the area. The camera will rotate around this point.
/// For example, this is what makes the camera rotate around the hill in BoB
- /*0x2C*/ f32 areaCenZ;
- /*0x30*/ u8 cutscene;
- /*0x31*/ u8 filler31[0x8];
- /*0x3A*/ s16 nextYaw;
- /*0x3C*/ u8 filler3C[0x28];
- /*0x64*/ u8 doorStatus;
+ /*0x2C*/
+ f32 areaCenZ;
+ /*0x30*/
+ u8 cutscene;
+ /*0x31*/
+ u8 filler31[0x8];
+ /*0x3A*/
+ s16 nextYaw;
+ /*0x3C*/
+ u8 filler3C[0x28];
+ /*0x64*/
+ u8 doorStatus;
/// The y coordinate of the "center" of the area. Unlike areaCenX and areaCenZ, this is only used
/// when paused. See zoom_out_if_paused_and_outside
- /*0x68*/ f32 areaCenY;
+ /*0x68*/
+ f32 areaCenY;
};
/**
@@ -576,85 +635,122 @@ struct LakituState
/**
* Lakitu's position, which (when CAM_FLAG_SMOOTH_MOVEMENT is set), approaches his goalPos every frame.
*/
- /*0x00*/ Vec3f curFocus;
+ /*0x00*/
+ Vec3f curFocus;
/**
* Lakitu's focus, which (when CAM_FLAG_SMOOTH_MOVEMENT is set), approaches his goalFocus every frame.
*/
- /*0x0C*/ Vec3f curPos;
+ /*0x0C*/
+ Vec3f curPos;
/**
* The focus point that lakitu turns towards every frame.
* If CAM_FLAG_SMOOTH_MOVEMENT is unset, this is the same as curFocus.
*/
- /*0x18*/ Vec3f goalFocus;
+ /*0x18*/
+ Vec3f goalFocus;
/**
* The point that lakitu flies towards every frame.
* If CAM_FLAG_SMOOTH_MOVEMENT is unset, this is the same as curPos.
*/
- /*0x24*/ Vec3f goalPos;
+ /*0x24*/
+ Vec3f goalPos;
- /*0x30*/ u8 filler30[12]; // extra unused Vec3f?
+ /*0x30*/
+ u8 filler30[12]; // extra unused Vec3f?
/// Copy of the active camera mode
- /*0x3C*/ u8 mode;
+ /*0x3C*/
+ u8 mode;
/// Copy of the default camera mode
- /*0x3D*/ u8 defMode;
+ /*0x3D*/
+ u8 defMode;
- /*0x3E*/ u8 filler3E[10];
+ /*0x3E*/
+ u8 filler3E[10];
- /*0x48*/ f32 focusDistance; // unused
- /*0x4C*/ s16 oldPitch; // unused
- /*0x4E*/ s16 oldYaw; // unused
- /*0x50*/ s16 oldRoll; // unused
+ /*0x48*/
+ f32 focusDistance; // unused
+ /*0x4C*/
+ s16 oldPitch; // unused
+ /*0x4E*/
+ s16 oldYaw; // unused
+ /*0x50*/
+ s16 oldRoll; // unused
/// The angular offsets added to lakitu's pitch, yaw, and roll
- /*0x52*/ Vec3s shakeMagnitude;
+ /*0x52*/
+ Vec3s shakeMagnitude;
// shake pitch, yaw, and roll phase: The progression through the camera shake (a cosine wave).
// shake pitch, yaw, and roll vel: The speed of the camera shake.
// shake pitch, yaw, and roll decay: The shake's deceleration.
- /*0x58*/ s16 shakePitchPhase;
- /*0x5A*/ s16 shakePitchVel;
- /*0x5C*/ s16 shakePitchDecay;
+ /*0x58*/
+ s16 shakePitchPhase;
+ /*0x5A*/
+ s16 shakePitchVel;
+ /*0x5C*/
+ s16 shakePitchDecay;
- /*0x60*/ Vec3f unusedVec1;
- /*0x6C*/ Vec3s unusedVec2;
- /*0x72*/ u8 filler72[8];
+ /*0x60*/
+ Vec3f unusedVec1;
+ /*0x6C*/
+ Vec3s unusedVec2;
+ /*0x72*/
+ u8 filler72[8];
/// Used to rotate the screen when rendering.
- /*0x7A*/ s16 roll;
+ /*0x7A*/
+ s16 roll;
/// Copy of the camera's yaw.
- /*0x7C*/ s16 yaw;
+ /*0x7C*/
+ s16 yaw;
/// Copy of the camera's next yaw.
- /*0x7E*/ s16 nextYaw;
+ /*0x7E*/
+ s16 nextYaw;
/// The actual focus point the game uses to render.
- /*0x80*/ Vec3f focus;
+ /*0x80*/
+ Vec3f focus;
/// The actual position the game is rendered from.
- /*0x8C*/ Vec3f pos;
+ /*0x8C*/
+ Vec3f pos;
// Shake variables: See above description
- /*0x98*/ s16 shakeRollPhase;
- /*0x9A*/ s16 shakeRollVel;
- /*0x9C*/ s16 shakeRollDecay;
- /*0x9E*/ s16 shakeYawPhase;
- /*0xA0*/ s16 shakeYawVel;
- /*0xA2*/ s16 shakeYawDecay;
+ /*0x98*/
+ s16 shakeRollPhase;
+ /*0x9A*/
+ s16 shakeRollVel;
+ /*0x9C*/
+ s16 shakeRollDecay;
+ /*0x9E*/
+ s16 shakeYawPhase;
+ /*0xA0*/
+ s16 shakeYawVel;
+ /*0xA2*/
+ s16 shakeYawDecay;
// focH,Vspeed: how fast lakitu turns towards his goalFocus.
/// By default HSpeed is 0.8, so lakitu turns 80% of the horz distance to his goal each frame.
- /*0xA4*/ f32 focHSpeed;
+ /*0xA4*/
+ f32 focHSpeed;
/// By default VSpeed is 0.3, so lakitu turns 30% of the vert distance to his goal each frame.
- /*0xA8*/ f32 focVSpeed;
+ /*0xA8*/
+ f32 focVSpeed;
// posH,Vspeed: How fast lakitu flies towards his goalPos.
/// By default they are 0.3, so lakitu will fly 30% of the way towards his goal each frame.
- /*0xAC*/ f32 posHSpeed;
- /*0xB0*/ f32 posVSpeed;
+ /*0xAC*/
+ f32 posHSpeed;
+ /*0xB0*/
+ f32 posVSpeed;
/// The roll offset applied during part of the key dance cutscene
- /*0xB4*/ s16 keyDanceRoll;
+ /*0xB4*/
+ s16 keyDanceRoll;
/// Mario's action from the previous frame. Only used to determine if Mario just finished a dive.
- /*0xB8*/ u32 lastFrameAction;
- /*0xBC*/ s16 unused;
+ /*0xB8*/
+ u32 lastFrameAction;
+ /*0xBC*/
+ s16 unused;
};
diff --git a/src/decomp/game/interaction.c b/src/decomp/game/interaction.c
index 5e4be0b..cdd1aa2 100644
--- a/src/decomp/game/interaction.c
+++ b/src/decomp/game/interaction.c
@@ -58,59 +58,62 @@
// u8 sDelayInvincTimer;
// s16 sInvulnerable;
-struct InteractionHandler {
+struct InteractionHandler
+{
u32 interactType;
+
u32 (*handler)(struct MarioState *, u32, struct Object *);
};
-static u32 interact_noop(struct MarioState *m, u32 interactType, struct Object *o) {
+static u32 interact_noop(struct MarioState *m, u32 interactType, struct Object *o)
+{
return FALSE;
}
static struct InteractionHandler sInteractionHandlers[] = {
- { INTERACT_COIN, interact_noop },
- { INTERACT_WATER_RING, interact_noop },
- { INTERACT_STAR_OR_KEY, interact_noop },
- { INTERACT_BBH_ENTRANCE, interact_noop },
- { INTERACT_WARP, interact_noop },
- { INTERACT_WARP_DOOR, interact_noop },
- { INTERACT_DOOR, interact_noop },
- { INTERACT_CANNON_BASE, interact_noop },
- { INTERACT_IGLOO_BARRIER, interact_noop },
- { INTERACT_TORNADO, interact_noop },
- { INTERACT_WHIRLPOOL, interact_noop },
- { INTERACT_STRONG_WIND, interact_noop },
- { INTERACT_FLAME, interact_noop },
- { INTERACT_SNUFIT_BULLET, interact_noop },
- { INTERACT_CLAM_OR_BUBBA, interact_noop },
- { INTERACT_BULLY, interact_noop },
- { INTERACT_SHOCK, interact_noop },
- { INTERACT_BOUNCE_TOP2, interact_noop },
- { INTERACT_MR_BLIZZARD, interact_noop },
- { INTERACT_HIT_FROM_BELOW, interact_noop },
- { INTERACT_BOUNCE_TOP, interact_noop },
- { INTERACT_DAMAGE, interact_noop },
- { INTERACT_POLE, interact_noop },
- { INTERACT_HOOT, interact_noop },
- { INTERACT_BREAKABLE, interact_noop },
- { INTERACT_KOOPA, interact_noop },
- { INTERACT_KOOPA_SHELL, interact_noop },
- { INTERACT_UNKNOWN_08, interact_noop },
- { INTERACT_CAP, interact_noop },
- { INTERACT_GRABBABLE, interact_noop },
- { INTERACT_TEXT, interact_noop },
+ {INTERACT_COIN, interact_noop},
+ {INTERACT_WATER_RING, interact_noop},
+ {INTERACT_STAR_OR_KEY, interact_noop},
+ {INTERACT_BBH_ENTRANCE, interact_noop},
+ {INTERACT_WARP, interact_noop},
+ {INTERACT_WARP_DOOR, interact_noop},
+ {INTERACT_DOOR, interact_noop},
+ {INTERACT_CANNON_BASE, interact_noop},
+ {INTERACT_IGLOO_BARRIER, interact_noop},
+ {INTERACT_TORNADO, interact_noop},
+ {INTERACT_WHIRLPOOL, interact_noop},
+ {INTERACT_STRONG_WIND, interact_noop},
+ {INTERACT_FLAME, interact_noop},
+ {INTERACT_SNUFIT_BULLET, interact_noop},
+ {INTERACT_CLAM_OR_BUBBA, interact_noop},
+ {INTERACT_BULLY, interact_noop},
+ {INTERACT_SHOCK, interact_noop},
+ {INTERACT_BOUNCE_TOP2, interact_noop},
+ {INTERACT_MR_BLIZZARD, interact_noop},
+ {INTERACT_HIT_FROM_BELOW, interact_noop},
+ {INTERACT_BOUNCE_TOP, interact_noop},
+ {INTERACT_DAMAGE, interact_noop},
+ {INTERACT_POLE, interact_noop},
+ {INTERACT_HOOT, interact_noop},
+ {INTERACT_BREAKABLE, interact_noop},
+ {INTERACT_KOOPA, interact_noop},
+ {INTERACT_KOOPA_SHELL, interact_noop},
+ {INTERACT_UNKNOWN_08, interact_noop},
+ {INTERACT_CAP, interact_noop},
+ {INTERACT_GRABBABLE, interact_noop},
+ {INTERACT_TEXT, interact_noop},
};
static u32 sForwardKnockbackActions[][3] = {
- { ACT_SOFT_FORWARD_GROUND_KB, ACT_FORWARD_GROUND_KB, ACT_HARD_FORWARD_GROUND_KB },
- { ACT_FORWARD_AIR_KB, ACT_FORWARD_AIR_KB, ACT_HARD_FORWARD_AIR_KB },
- { ACT_FORWARD_WATER_KB, ACT_FORWARD_WATER_KB, ACT_FORWARD_WATER_KB },
+ {ACT_SOFT_FORWARD_GROUND_KB, ACT_FORWARD_GROUND_KB, ACT_HARD_FORWARD_GROUND_KB},
+ {ACT_FORWARD_AIR_KB, ACT_FORWARD_AIR_KB, ACT_HARD_FORWARD_AIR_KB},
+ {ACT_FORWARD_WATER_KB, ACT_FORWARD_WATER_KB, ACT_FORWARD_WATER_KB},
};
static u32 sBackwardKnockbackActions[][3] = {
- { ACT_SOFT_BACKWARD_GROUND_KB, ACT_BACKWARD_GROUND_KB, ACT_HARD_BACKWARD_GROUND_KB },
- { ACT_BACKWARD_AIR_KB, ACT_BACKWARD_AIR_KB, ACT_HARD_BACKWARD_AIR_KB },
- { ACT_BACKWARD_WATER_KB, ACT_BACKWARD_WATER_KB, ACT_BACKWARD_WATER_KB },
+ {ACT_SOFT_BACKWARD_GROUND_KB, ACT_BACKWARD_GROUND_KB, ACT_HARD_BACKWARD_GROUND_KB},
+ {ACT_BACKWARD_AIR_KB, ACT_BACKWARD_AIR_KB, ACT_HARD_BACKWARD_AIR_KB},
+ {ACT_BACKWARD_WATER_KB, ACT_BACKWARD_WATER_KB, ACT_BACKWARD_WATER_KB},
};
static u8 sDisplayingDoorText = FALSE;
@@ -120,20 +123,20 @@ static u8 sPssSlideStarted = FALSE;
/**
* Returns the type of cap Mario is wearing.
*/
-u32 get_mario_cap_flag(struct Object *capObject) {
-
+u32 get_mario_cap_flag(struct Object *capObject)
+{
return MARIO_NORMAL_CAP;
-// const BehaviorScript *script = virtual_to_segmented(0x13, capObject->behavior);
-// if (script == bhvNormalCap) {
-// return MARIO_NORMAL_CAP;
-// } else if (script == bhvMetalCap) {
-// return MARIO_METAL_CAP;
-// } else if (script == bhvWingCap) {
-// return MARIO_WING_CAP;
-// } else if (script == bhvVanishCap) {
-// return MARIO_VANISH_CAP;
-// }
+ // const BehaviorScript *script = virtual_to_segmented(0x13, capObject->behavior);
+ // if (script == bhvNormalCap) {
+ // return MARIO_NORMAL_CAP;
+ // } else if (script == bhvMetalCap) {
+ // return MARIO_METAL_CAP;
+ // } else if (script == bhvWingCap) {
+ // return MARIO_WING_CAP;
+ // } else if (script == bhvVanishCap) {
+ // return MARIO_VANISH_CAP;
+ // }
return 0;
}
@@ -142,21 +145,24 @@ u32 get_mario_cap_flag(struct Object *capObject) {
* Returns true if the passed in object has a moving angle yaw
* in the angular range given towards Mario.
*/
-u32 object_facing_mario(struct MarioState *m, struct Object *o, s16 angleRange) {
+u32 object_facing_mario(struct MarioState *m, struct Object *o, s16 angleRange)
+{
f32 dx = m->pos[0] - o->oPosX;
f32 dz = m->pos[2] - o->oPosZ;
s16 angleToMario = atan2s(dz, dx);
s16 dAngle = angleToMario - o->oMoveAngleYaw;
- if (-angleRange <= dAngle && dAngle <= angleRange) {
+ if (-angleRange <= dAngle && dAngle <= angleRange)
+ {
return TRUE;
}
return FALSE;
}
-s16 mario_obj_angle_to_object(struct MarioState *m, struct Object *o) {
+s16 mario_obj_angle_to_object(struct MarioState *m, struct Object *o)
+{
f32 dx = o->oPosX - m->pos[0];
f32 dz = o->oPosZ - m->pos[2];
@@ -167,49 +173,70 @@ s16 mario_obj_angle_to_object(struct MarioState *m, struct Object *o) {
* Determines Mario's interaction with a given object depending on their proximity,
* action, speed, and position.
*/
-u32 determine_interaction(struct MarioState *m, struct Object *o) {
+u32 determine_interaction(struct MarioState *m, struct Object *o)
+{
u32 interaction = 0;
u32 action = m->action;
- if (action & ACT_FLAG_ATTACKING) {
- if (action == ACT_PUNCHING || action == ACT_MOVE_PUNCHING || action == ACT_JUMP_KICK) {
+ if (action & ACT_FLAG_ATTACKING)
+ {
+ if (action == ACT_PUNCHING || action == ACT_MOVE_PUNCHING || action == ACT_JUMP_KICK)
+ {
s16 dYawToObject = mario_obj_angle_to_object(m, o) - m->faceAngle[1];
- if (m->flags & MARIO_PUNCHING) {
+ if (m->flags & MARIO_PUNCHING)
+ {
// 120 degrees total, or 60 each way
- if (-0x2AAA <= dYawToObject && dYawToObject <= 0x2AAA) {
+ if (-0x2AAA <= dYawToObject && dYawToObject <= 0x2AAA)
+ {
interaction = INT_PUNCH;
}
}
- if (m->flags & MARIO_KICKING) {
+ if (m->flags & MARIO_KICKING)
+ {
// 120 degrees total, or 60 each way
- if (-0x2AAA <= dYawToObject && dYawToObject <= 0x2AAA) {
+ if (-0x2AAA <= dYawToObject && dYawToObject <= 0x2AAA)
+ {
interaction = INT_KICK;
}
}
- if (m->flags & MARIO_TRIPPING) {
+ if (m->flags & MARIO_TRIPPING)
+ {
// 180 degrees total, or 90 each way
- if (-0x4000 <= dYawToObject && dYawToObject <= 0x4000) {
+ if (-0x4000 <= dYawToObject && dYawToObject <= 0x4000)
+ {
interaction = INT_TRIP;
}
}
- } else if (action == ACT_GROUND_POUND || action == ACT_TWIRLING) {
- if (m->vel[1] < 0.0f) {
+ }
+ else if (action == ACT_GROUND_POUND || action == ACT_TWIRLING)
+ {
+ if (m->vel[1] < 0.0f)
+ {
interaction = INT_GROUND_POUND_OR_TWIRL;
}
- } else if (action == ACT_GROUND_POUND_LAND || action == ACT_TWIRL_LAND) {
+ }
+ else if (action == ACT_GROUND_POUND_LAND || action == ACT_TWIRL_LAND)
+ {
// Neither ground pounding nor twirling change Mario's vertical speed on landing.,
// so the speed check is nearly always true (perhaps not if you land while going upwards?)
// Additionally, actionState it set on each first thing in their action, so this is
// only true prior to the very first frame (i.e. active 1 frame prior to it run).
- if (m->vel[1] < 0.0f && m->actionState == 0) {
+ if (m->vel[1] < 0.0f && m->actionState == 0)
+ {
interaction = INT_GROUND_POUND_OR_TWIRL;
}
- } else if (action == ACT_SLIDE_KICK || action == ACT_SLIDE_KICK_SLIDE) {
+ }
+ else if (action == ACT_SLIDE_KICK || action == ACT_SLIDE_KICK_SLIDE)
+ {
interaction = INT_SLIDE_KICK;
- } else if (action & ACT_FLAG_RIDING_SHELL) {
+ }
+ else if (action & ACT_FLAG_RIDING_SHELL)
+ {
interaction = INT_FAST_ATTACK_OR_SHELL;
- } else if (m->forwardVel <= -26.0f || 26.0f <= m->forwardVel) {
+ }
+ else if (m->forwardVel <= -26.0f || 26.0f <= m->forwardVel)
+ {
interaction = INT_FAST_ATTACK_OR_SHELL;
}
}
@@ -217,13 +244,19 @@ u32 determine_interaction(struct MarioState *m, struct Object *o) {
// Prior to this, the interaction type could be overwritten. This requires, however,
// that the interaction not be set prior. This specifically overrides turning a ground
// pound into just a bounce.
- if (interaction == 0 && (action & ACT_FLAG_AIR)) {
- if (m->vel[1] < 0.0f) {
- if (m->pos[1] > o->oPosY) {
+ if (interaction == 0 && action & ACT_FLAG_AIR)
+ {
+ if (m->vel[1] < 0.0f)
+ {
+ if (m->pos[1] > o->oPosY)
+ {
interaction = INT_HIT_FROM_ABOVE;
}
- } else {
- if (m->pos[1] < o->oPosY) {
+ }
+ else
+ {
+ if (m->pos[1] < o->oPosY)
+ {
interaction = INT_HIT_FROM_BELOW;
}
}
@@ -235,10 +268,12 @@ u32 determine_interaction(struct MarioState *m, struct Object *o) {
/**
* Sets the interaction types for INT_STATUS_INTERACTED, INT_STATUS_WAS_ATTACKED
*/
-u32 attack_object(struct Object *o, s32 interaction) {
+u32 attack_object(struct Object *o, s32 interaction)
+{
u32 attackType = 0;
- switch (interaction) {
+ switch (interaction)
+ {
case INT_GROUND_POUND_OR_TWIRL:
attackType = ATTACK_GROUND_POUND_OR_TWIRL;
break;
@@ -265,28 +300,34 @@ u32 attack_object(struct Object *o, s32 interaction) {
return attackType;
}
-void mario_stop_riding_object(struct MarioState *m) {
- if (m->riddenObj != NULL) {
+void mario_stop_riding_object(struct MarioState *m)
+{
+ if (m->riddenObj != NULL)
+ {
m->riddenObj->oInteractStatus = INT_STATUS_STOP_RIDING;
stop_shell_music();
m->riddenObj = NULL;
}
}
-void mario_grab_used_object(struct MarioState *m) {
- if (m->heldObj == NULL) {
+void mario_grab_used_object(struct MarioState *m)
+{
+ if (m->heldObj == NULL)
+ {
m->heldObj = m->usedObj;
-// obj_set_held_state(m->heldObj, bhvCarrySomething3);
+ // obj_set_held_state(m->heldObj, bhvCarrySomething3);
}
}
-void mario_drop_held_object(struct MarioState *m) {
- if (m->heldObj != NULL) {
- // if (m->heldObj->behavior == segmented_to_virtual(bhvKoopaShellUnderwater)) {
- // stop_shell_music();
- // }
+void mario_drop_held_object(struct MarioState *m)
+{
+ if (m->heldObj != NULL)
+ {
+ // if (m->heldObj->behavior == segmented_to_virtual(bhvKoopaShellUnderwater)) {
+ // stop_shell_music();
+ // }
- // obj_set_held_state(m->heldObj, bhvCarrySomething4);
+ // obj_set_held_state(m->heldObj, bhvCarrySomething4);
// ! When dropping an object instead of throwing it, it will be put at Mario's
// y-positon instead of the HOLP's y-position. This fact is often exploited when
@@ -301,13 +342,15 @@ void mario_drop_held_object(struct MarioState *m) {
}
}
-void mario_throw_held_object(struct MarioState *m) {
- if (m->heldObj != NULL) {
- // if (m->heldObj->behavior == segmented_to_virtual(bhvKoopaShellUnderwater)) {
- // stop_shell_music();
- // }
+void mario_throw_held_object(struct MarioState *m)
+{
+ if (m->heldObj != NULL)
+ {
+ // if (m->heldObj->behavior == segmented_to_virtual(bhvKoopaShellUnderwater)) {
+ // stop_shell_music();
+ // }
- // obj_set_held_state(m->heldObj, bhvCarrySomething5);
+ // obj_set_held_state(m->heldObj, bhvCarrySomething5);
m->heldObj->oPosX = m->marioBodyState->heldObjLastPosition[0] + 32.0f * sins(m->faceAngle[1]);
m->heldObj->oPosY = m->marioBodyState->heldObjLastPosition[1];
@@ -319,44 +362,50 @@ void mario_throw_held_object(struct MarioState *m) {
}
}
-void mario_stop_riding_and_holding(struct MarioState *m) {
+void mario_stop_riding_and_holding(struct MarioState *m)
+{
mario_drop_held_object(m);
mario_stop_riding_object(m);
- if (m->action == ACT_RIDING_HOOT) {
+ if (m->action == ACT_RIDING_HOOT)
+ {
m->usedObj->oInteractStatus = 0;
m->usedObj->oHootMarioReleaseTime = gGlobalTimer;
}
}
-u32 does_mario_have_normal_cap_on_head(struct MarioState *m) {
+u32 does_mario_have_normal_cap_on_head(struct MarioState *m)
+{
return (m->flags & (MARIO_CAPS | MARIO_CAP_ON_HEAD)) == (MARIO_NORMAL_CAP | MARIO_CAP_ON_HEAD);
}
-void mario_blow_off_cap(struct MarioState *m, f32 capSpeed) {
-// struct Object *capObject;
+void mario_blow_off_cap(struct MarioState *m, f32 capSpeed)
+{
+ // struct Object *capObject;
-// if (does_mario_have_normal_cap_on_head(m)) {
-// save_file_set_cap_pos(m->pos[0], m->pos[1], m->pos[2]);
+ // if (does_mario_have_normal_cap_on_head(m)) {
+ // save_file_set_cap_pos(m->pos[0], m->pos[1], m->pos[2]);
-// m->flags &= ~(MARIO_NORMAL_CAP | MARIO_CAP_ON_HEAD);
+ // m->flags &= ~(MARIO_NORMAL_CAP | MARIO_CAP_ON_HEAD);
-// capObject = spawn_object(m->marioObj, MODEL_MARIOS_CAP, bhvNormalCap);
+ // capObject = spawn_object(m->marioObj, MODEL_MARIOS_CAP, bhvNormalCap);
-// capObject->oPosY += (m->action & ACT_FLAG_SHORT_HITBOX) ? 120.0f : 180.0f;
-// capObject->oForwardVel = capSpeed;
-// capObject->oMoveAngleYaw = (s16)(m->faceAngle[1] + 0x400);
+ // capObject->oPosY += (m->action & ACT_FLAG_SHORT_HITBOX) ? 120.0f : 180.0f;
+ // capObject->oForwardVel = capSpeed;
+ // capObject->oMoveAngleYaw = (s16)(m->faceAngle[1] + 0x400);
-// if (m->forwardVel < 0.0f) {
-// capObject->oMoveAngleYaw = (s16)(capObject->oMoveAngleYaw + 0x8000);
-// }
-// }
+ // if (m->forwardVel < 0.0f) {
+ // capObject->oMoveAngleYaw = (s16)(capObject->oMoveAngleYaw + 0x8000);
+ // }
+ // }
}
-u32 mario_lose_cap_to_enemy(u32 arg) {
+u32 mario_lose_cap_to_enemy(u32 arg)
+{
u32 wasWearingCap = FALSE;
- if (does_mario_have_normal_cap_on_head(gMarioState)) {
+ if (does_mario_have_normal_cap_on_head(gMarioState))
+ {
save_file_set_flags(arg == 1 ? SAVE_FLAG_CAP_ON_KLEPTO : SAVE_FLAG_CAP_ON_UKIKI);
gMarioState->flags &= ~(MARIO_NORMAL_CAP | MARIO_CAP_ON_HEAD);
wasWearingCap = TRUE;
@@ -365,22 +414,29 @@ u32 mario_lose_cap_to_enemy(u32 arg) {
return wasWearingCap;
}
-void mario_retrieve_cap(void) {
+void mario_retrieve_cap(void)
+{
mario_drop_held_object(gMarioState);
save_file_clear_flags(SAVE_FLAG_CAP_ON_KLEPTO | SAVE_FLAG_CAP_ON_UKIKI);
gMarioState->flags &= ~MARIO_CAP_ON_HEAD;
gMarioState->flags |= MARIO_NORMAL_CAP | MARIO_CAP_IN_HAND;
}
-u32 able_to_grab_object(struct MarioState *m, UNUSED struct Object *o) {
+u32 able_to_grab_object(struct MarioState *m, UNUSED struct Object *o)
+{
u32 action = m->action;
- if (action == ACT_DIVE_SLIDE || action == ACT_DIVE) {
- if (!(o->oInteractionSubtype & INT_SUBTYPE_GRABS_MARIO)) {
+ if (action == ACT_DIVE_SLIDE || action == ACT_DIVE)
+ {
+ if (!(o->oInteractionSubtype & INT_SUBTYPE_GRABS_MARIO))
+ {
return TRUE;
}
- } else if (action == ACT_PUNCHING || action == ACT_MOVE_PUNCHING) {
- if (m->actionArg < 2) {
+ }
+ else if (action == ACT_PUNCHING || action == ACT_MOVE_PUNCHING)
+ {
+ if (m->actionArg < 2)
+ {
return TRUE;
}
}
@@ -388,14 +444,17 @@ u32 able_to_grab_object(struct MarioState *m, UNUSED struct Object *o) {
return FALSE;
}
-struct Object *mario_get_collided_object(struct MarioState *m, u32 interactType) {
+struct Object *mario_get_collided_object(struct MarioState *m, u32 interactType)
+{
s32 i;
struct Object *object;
- for (i = 0; i < m->marioObj->numCollidedObjs; i++) {
+ for (i = 0; i < m->marioObj->numCollidedObjs; i++)
+ {
object = m->marioObj->collidedObjs[i];
- if (object->oInteractType == interactType) {
+ if (object->oInteractType == interactType)
+ {
return object;
}
}
@@ -403,39 +462,44 @@ struct Object *mario_get_collided_object(struct MarioState *m, u32 interactType)
return NULL;
}
-u32 mario_check_object_grab(struct MarioState *m) {
+u32 mario_check_object_grab(struct MarioState *m)
+{
u32 result = FALSE;
-// const BehaviorScript *script;
+ // const BehaviorScript *script;
- if (m->input & INPUT_INTERACT_OBJ_GRABBABLE) {
-// script = virtual_to_segmented(0x13, m->interactObj->behavior);
+ if (m->input & INPUT_INTERACT_OBJ_GRABBABLE)
+ {
+ // script = virtual_to_segmented(0x13, m->interactObj->behavior);
-// if (script == bhvBowser) {
-// s16 facingDYaw = m->faceAngle[1] - m->interactObj->oMoveAngleYaw;
-// if (facingDYaw >= -0x5555 && facingDYaw <= 0x5555) {
-// m->faceAngle[1] = m->interactObj->oMoveAngleYaw;
-// m->usedObj = m->interactObj;
-// result = set_mario_action(m, ACT_PICKING_UP_BOWSER, 0);
-// }
-// } else {
- s16 facingDYaw = mario_obj_angle_to_object(m, m->interactObj) - m->faceAngle[1];
- if (facingDYaw >= -0x2AAA && facingDYaw <= 0x2AAA) {
- m->usedObj = m->interactObj;
+ // if (script == bhvBowser) {
+ // s16 facingDYaw = m->faceAngle[1] - m->interactObj->oMoveAngleYaw;
+ // if (facingDYaw >= -0x5555 && facingDYaw <= 0x5555) {
+ // m->faceAngle[1] = m->interactObj->oMoveAngleYaw;
+ // m->usedObj = m->interactObj;
+ // result = set_mario_action(m, ACT_PICKING_UP_BOWSER, 0);
+ // }
+ // } else {
+ s16 facingDYaw = mario_obj_angle_to_object(m, m->interactObj) - m->faceAngle[1];
+ if (facingDYaw >= -0x2AAA && facingDYaw <= 0x2AAA)
+ {
+ m->usedObj = m->interactObj;
- if (!(m->action & ACT_FLAG_AIR)) {
- set_mario_action(
- m, (m->action & ACT_FLAG_DIVING) ? ACT_DIVE_PICKING_UP : ACT_PICKING_UP, 0);
- }
-
- result = TRUE;
+ if (!(m->action & ACT_FLAG_AIR))
+ {
+ set_mario_action(
+ m, m->action & ACT_FLAG_DIVING ? ACT_DIVE_PICKING_UP : ACT_PICKING_UP, 0);
}
-// }
+
+ result = TRUE;
+ }
+ // }
}
return result;
}
-u32 bully_knock_back_mario(struct MarioState *mario) {
+u32 bully_knock_back_mario(struct MarioState *mario)
+{
struct BullyCollisionData marioData;
struct BullyCollisionData bullyData;
s16 newMarioYaw;
@@ -458,9 +522,12 @@ u32 bully_knock_back_mario(struct MarioState *mario) {
init_bully_collision_data(&bullyData, bully->oPosX, bully->oPosZ, bully->oForwardVel,
bully->oMoveAngleYaw, marioToBullyRatio, bully->hitboxRadius + 2.0f);
- if (mario->forwardVel != 0.0f) {
+ if (mario->forwardVel != 0.0f)
+ {
transfer_bully_speed(&marioData, &bullyData);
- } else {
+ }
+ else
+ {
transfer_bully_speed(&bullyData, &marioData);
}
@@ -480,19 +547,28 @@ u32 bully_knock_back_mario(struct MarioState *mario) {
bully->oPosX = bullyData.posX;
bully->oPosZ = bullyData.posZ;
- if (marioDYaw < -0x4000 || marioDYaw > 0x4000) {
+ if (marioDYaw < -0x4000 || marioDYaw > 0x4000)
+ {
mario->faceAngle[1] += 0x8000;
mario->forwardVel *= -1.0f;
- if (mario->action & ACT_FLAG_AIR) {
+ if (mario->action & ACT_FLAG_AIR)
+ {
bonkAction = ACT_BACKWARD_AIR_KB;
- } else {
+ }
+ else
+ {
bonkAction = ACT_SOFT_BACKWARD_GROUND_KB;
}
- } else {
- if (mario->action & ACT_FLAG_AIR) {
+ }
+ else
+ {
+ if (mario->action & ACT_FLAG_AIR)
+ {
bonkAction = ACT_FORWARD_AIR_KB;
- } else {
+ }
+ else
+ {
bonkAction = ACT_SOFT_FORWARD_GROUND_KB;
}
}
@@ -500,7 +576,8 @@ u32 bully_knock_back_mario(struct MarioState *mario) {
return bonkAction;
}
-void bounce_off_object(struct MarioState *m, struct Object *o, f32 velY) {
+void bounce_off_object(struct MarioState *m, struct Object *o, f32 velY)
+{
m->pos[1] = o->oPosY + o->hitboxHeight;
m->vel[1] = velY;
@@ -509,7 +586,8 @@ void bounce_off_object(struct MarioState *m, struct Object *o, f32 velY) {
play_sound(SOUND_ACTION_BOUNCE_OFF_OBJECT, m->marioObj->header.gfx.cameraToObject);
}
-void hit_object_from_below(struct MarioState *m, UNUSED struct Object *o) {
+void hit_object_from_below(struct MarioState *m, UNUSED struct Object *o)
+{
m->vel[1] = 0.0f;
set_camera_shake_from_hit(SHAKE_HIT_FROM_BELOW);
}
@@ -518,13 +596,13 @@ void hit_object_from_below(struct MarioState *m, UNUSED struct Object *o) {
// u32 bonkAction;
// s16 angleToObject = mario_obj_angle_to_object(m, m->interactObj);
// s16 facingDYaw = angleToObject - m->faceAngle[1];
-//
+//
// if (m->forwardVel < 16.0f) {
// m->forwardVel = 16.0f;
// }
-//
+//
// m->faceAngle[1] = angleToObject;
-//
+//
// if (facingDYaw >= -0x4000 && facingDYaw <= 0x4000) {
// m->forwardVel *= -1.0f;
// if (m->action & (ACT_FLAG_AIR | ACT_FLAG_ON_POLE | ACT_FLAG_HANGING)) {
@@ -540,11 +618,12 @@ void hit_object_from_below(struct MarioState *m, UNUSED struct Object *o) {
// bonkAction = ACT_SOFT_FORWARD_GROUND_KB;
// }
// }
-//
+//
// return bonkAction;
// }
-u32 determine_knockback_action(struct MarioState *m, UNUSED s32 arg) {
+u32 determine_knockback_action(struct MarioState *m, UNUSED s32 arg)
+{
u32 bonkAction;
s16 terrainIndex = 0; // 1 = air, 2 = water, 0 = default
@@ -554,46 +633,67 @@ u32 determine_knockback_action(struct MarioState *m, UNUSED s32 arg) {
s16 facingDYaw = angleToObject - m->faceAngle[1];
s16 remainingHealth = m->health - 0x40 * m->hurtCounter;
- if (m->action & (ACT_FLAG_SWIMMING | ACT_FLAG_METAL_WATER)) {
+ if (m->action & (ACT_FLAG_SWIMMING | ACT_FLAG_METAL_WATER))
+ {
terrainIndex = 2;
- } else if (m->action & (ACT_FLAG_AIR | ACT_FLAG_ON_POLE | ACT_FLAG_HANGING)) {
+ }
+ else if (m->action & (ACT_FLAG_AIR | ACT_FLAG_ON_POLE | ACT_FLAG_HANGING))
+ {
terrainIndex = 1;
}
- if (remainingHealth < 0x100) {
+ if (remainingHealth < 0x100)
+ {
strengthIndex = 2;
- } else if (m->interactObj->oDamageOrCoinValue >= 4) {
+ }
+ else if (m->interactObj->oDamageOrCoinValue >= 4)
+ {
strengthIndex = 2;
- } else if (m->interactObj->oDamageOrCoinValue >= 2) {
+ }
+ else if (m->interactObj->oDamageOrCoinValue >= 2)
+ {
strengthIndex = 1;
}
m->faceAngle[1] = angleToObject;
- if (terrainIndex == 2) {
- if (m->forwardVel < 28.0f) {
+ if (terrainIndex == 2)
+ {
+ if (m->forwardVel < 28.0f)
+ {
mario_set_forward_vel(m, 28.0f);
}
- if (m->pos[1] >= m->interactObj->oPosY) {
- if (m->vel[1] < 20.0f) {
+ if (m->pos[1] >= m->interactObj->oPosY)
+ {
+ if (m->vel[1] < 20.0f)
+ {
m->vel[1] = 20.0f;
}
- } else {
- if (m->vel[1] > 0.0f) {
+ }
+ else
+ {
+ if (m->vel[1] > 0.0f)
+ {
m->vel[1] = 0.0f;
}
}
- } else {
- if (m->forwardVel < 16.0f) {
+ }
+ else
+ {
+ if (m->forwardVel < 16.0f)
+ {
mario_set_forward_vel(m, 16.0f);
}
}
- if (-0x4000 <= facingDYaw && facingDYaw <= 0x4000) {
+ if (-0x4000 <= facingDYaw && facingDYaw <= 0x4000)
+ {
m->forwardVel *= -1.0f;
bonkAction = sBackwardKnockbackActions[terrainIndex][strengthIndex];
- } else {
+ }
+ else
+ {
m->faceAngle[1] += 0x8000;
bonkAction = sForwardKnockbackActions[terrainIndex][strengthIndex];
}
@@ -601,22 +701,27 @@ u32 determine_knockback_action(struct MarioState *m, UNUSED s32 arg) {
return bonkAction;
}
-void push_mario_out_of_object(struct MarioState *m, struct Object *o, f32 padding) {
+void push_mario_out_of_object(struct MarioState *m, struct Object *o, f32 padding)
+{
f32 minDistance = o->hitboxRadius + m->marioObj->hitboxRadius + padding;
f32 offsetX = m->pos[0] - o->oPosX;
f32 offsetZ = m->pos[2] - o->oPosZ;
f32 distance = sqrtf(offsetX * offsetX + offsetZ * offsetZ);
- if (distance < minDistance) {
+ if (distance < minDistance)
+ {
struct SM64SurfaceCollisionData *floor;
s16 pushAngle;
f32 newMarioX;
f32 newMarioZ;
- if (distance == 0.0f) {
+ if (distance == 0.0f)
+ {
pushAngle = m->faceAngle[1];
- } else {
+ }
+ else
+ {
pushAngle = atan2s(offsetZ, offsetX);
}
@@ -626,7 +731,8 @@ void push_mario_out_of_object(struct MarioState *m, struct Object *o, f32 paddin
f32_find_wall_collision(&newMarioX, &m->pos[1], &newMarioZ, 60.0f, 50.0f);
find_floor(newMarioX, m->pos[1], newMarioZ, &floor);
- if (floor != NULL) {
+ if (floor != NULL)
+ {
//! Doesn't update Mario's referenced floor (allows oob death when
// an object pushes you into a steep slope while in a ground action)
m->pos[0] = newMarioX;
@@ -635,15 +741,21 @@ void push_mario_out_of_object(struct MarioState *m, struct Object *o, f32 paddin
}
}
-void bounce_back_from_attack(struct MarioState *m, u32 interaction) {
- if (interaction & (INT_PUNCH | INT_KICK | INT_TRIP)) {
- if (m->action == ACT_PUNCHING) {
+void bounce_back_from_attack(struct MarioState *m, u32 interaction)
+{
+ if (interaction & (INT_PUNCH | INT_KICK | INT_TRIP))
+ {
+ if (m->action == ACT_PUNCHING)
+ {
m->action = ACT_MOVE_PUNCHING;
}
- if (m->action & ACT_FLAG_AIR) {
+ if (m->action & ACT_FLAG_AIR)
+ {
mario_set_forward_vel(m, -16.0f);
- } else {
+ }
+ else
+ {
mario_set_forward_vel(m, -48.0f);
}
@@ -651,88 +763,100 @@ void bounce_back_from_attack(struct MarioState *m, u32 interaction) {
m->particleFlags |= PARTICLE_TRIANGLE;
}
- if (interaction & (INT_PUNCH | INT_KICK | INT_TRIP | INT_FAST_ATTACK_OR_SHELL)) {
+ if (interaction & (INT_PUNCH | INT_KICK | INT_TRIP | INT_FAST_ATTACK_OR_SHELL))
+ {
play_sound(SOUND_ACTION_HIT_2, m->marioObj->header.gfx.cameraToObject);
}
}
-u32 should_push_or_pull_door(struct MarioState *m, struct Object *o) {
+u32 should_push_or_pull_door(struct MarioState *m, struct Object *o)
+{
f32 dx = o->oPosX - m->pos[0];
f32 dz = o->oPosZ - m->pos[2];
s16 dYaw = o->oMoveAngleYaw - atan2s(dz, dx);
- return (dYaw >= -0x4000 && dYaw <= 0x4000) ? 0x00000001 : 0x00000002;
+ return dYaw >= -0x4000 && dYaw <= 0x4000 ? 0x00000001 : 0x00000002;
}
-u32 take_damage_from_interact_object(struct MarioState *m) {
-// s32 shake;
+u32 take_damage_from_interact_object(struct MarioState *m)
+{
+ // s32 shake;
s32 damage = m->interactObj->oDamageOrCoinValue;
-// if (damage >= 4) {
-// shake = SHAKE_LARGE_DAMAGE;
-// } else if (damage >= 2) {
-// shake = SHAKE_MED_DAMAGE;
-// } else {
-// shake = SHAKE_SMALL_DAMAGE;
-// }
+ // if (damage >= 4) {
+ // shake = SHAKE_LARGE_DAMAGE;
+ // } else if (damage >= 2) {
+ // shake = SHAKE_MED_DAMAGE;
+ // } else {
+ // shake = SHAKE_SMALL_DAMAGE;
+ // }
- if (!(m->flags & MARIO_CAP_ON_HEAD)) {
+ if (!(m->flags & MARIO_CAP_ON_HEAD))
+ {
damage += (damage + 1) / 2;
}
- if (m->flags & MARIO_METAL_CAP) {
+ if (m->flags & MARIO_METAL_CAP)
+ {
damage = 0;
}
m->hurtCounter += 4 * damage;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
queue_rumble_data(5, 80);
-#endif
-// set_camera_shake_from_hit(shake);
+ #endif
+ // set_camera_shake_from_hit(shake);
return damage;
}
-u32 take_damage_and_knock_back(struct MarioState *m, struct Object *o) {
+u32 take_damage_and_knock_back(struct MarioState *m, struct Object *o)
+{
u32 damage;
if (!sInvulnerable && !(m->flags & MARIO_VANISH_CAP)
- && !(o->oInteractionSubtype & INT_SUBTYPE_DELAY_INVINCIBILITY)) {
+ && !(o->oInteractionSubtype & INT_SUBTYPE_DELAY_INVINCIBILITY))
+ {
o->oInteractStatus = INT_STATUS_INTERACTED | INT_STATUS_ATTACKED_MARIO;
m->interactObj = o;
damage = take_damage_from_interact_object(m);
- if (o->oInteractionSubtype & INT_SUBTYPE_BIG_KNOCKBACK) {
+ if (o->oInteractionSubtype & INT_SUBTYPE_BIG_KNOCKBACK)
+ {
m->forwardVel = 40.0f;
}
- if (o->oDamageOrCoinValue > 0) {
+ if (o->oDamageOrCoinValue > 0)
+ {
play_sound(SOUND_MARIO_ATTACKED, m->marioObj->header.gfx.cameraToObject);
}
update_mario_sound_and_camera(m);
- return drop_and_set_mario_action(m, determine_knockback_action(m, o->oDamageOrCoinValue),
- damage);
+ return drop_and_set_mario_action(m, determine_knockback_action(m, o->oDamageOrCoinValue), damage);
}
return FALSE;
}
-void reset_mario_pitch(struct MarioState *m) {
- if (m->action == ACT_WATER_JUMP || m->action == ACT_SHOT_FROM_CANNON || m->action == ACT_FLYING) {
+void reset_mario_pitch(struct MarioState *m)
+{
+ if (m->action == ACT_WATER_JUMP || m->action == ACT_SHOT_FROM_CANNON || m->action == ACT_FLYING)
+ {
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
m->faceAngle[0] = 0;
}
}
-u32 check_object_grab_mario(struct MarioState *m, UNUSED u32 interactType, struct Object *o) {
- if ((!(m->action & (ACT_FLAG_AIR | ACT_FLAG_INVULNERABLE | ACT_FLAG_ATTACKING)) || !sInvulnerable)
- && (o->oInteractionSubtype & INT_SUBTYPE_GRABS_MARIO)) {
- if (object_facing_mario(m, o, 0x2AAA)) {
+u32 check_object_grab_mario(struct MarioState *m, UNUSED u32 interactType, struct Object *o)
+{
+ if ((!(m->action & (ACT_FLAG_AIR | ACT_FLAG_INVULNERABLE | ACT_FLAG_ATTACKING)) || !sInvulnerable) && o->oInteractionSubtype & INT_SUBTYPE_GRABS_MARIO)
+ {
+ if (object_facing_mario(m, o, 0x2AAA))
+ {
mario_stop_riding_and_holding(m);
o->oInteractStatus = INT_STATUS_INTERACTED | INT_STATUS_GRABBED_MARIO;
@@ -742,9 +866,9 @@ u32 check_object_grab_mario(struct MarioState *m, UNUSED u32 interactType, struc
update_mario_sound_and_camera(m);
play_sound(SOUND_MARIO_OOOF, m->marioObj->header.gfx.cameraToObject);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
queue_rumble_data(5, 80);
-#endif
+ #endif
return set_mario_action(m, ACT_GRABBED, 0);
}
}
@@ -754,21 +878,26 @@ u32 check_object_grab_mario(struct MarioState *m, UNUSED u32 interactType, struc
}
-u32 mario_can_talk(struct MarioState *m, u32 arg) {
+u32 mario_can_talk(struct MarioState *m, u32 arg)
+{
s16 val6;
- if ((m->action & ACT_FLAG_IDLE) != 0x00000000) {
+ if ((m->action & ACT_FLAG_IDLE) != 0x00000000)
+ {
return TRUE;
}
- if (m->action == ACT_WALKING) {
- if (arg) {
+ if (m->action == ACT_WALKING)
+ {
+ if (arg)
+ {
return TRUE;
}
val6 = m->marioObj->header.gfx.animInfo.animID;
- if (val6 == 0x0080 || val6 == 0x007F || val6 == 0x006C) {
+ if (val6 == 0x0080 || val6 == 0x007F || val6 == 0x006C)
+ {
return TRUE;
}
}
@@ -788,10 +917,13 @@ u32 mario_can_talk(struct MarioState *m, u32 arg) {
#define SIGN_RANGE 0x4000
#endif
-u32 check_read_sign(struct MarioState *m, struct Object *o) {
- if ((m->input & READ_MASK) && mario_can_talk(m, 0) && object_facing_mario(m, o, SIGN_RANGE)) {
+u32 check_read_sign(struct MarioState *m, struct Object *o)
+{
+ if (m->input & READ_MASK && mario_can_talk(m, 0) && object_facing_mario(m, o, SIGN_RANGE))
+ {
s16 facingDYaw = (s16)(o->oMoveAngleYaw + 0x8000) - m->faceAngle[1];
- if (facingDYaw >= -SIGN_RANGE && facingDYaw <= SIGN_RANGE) {
+ if (facingDYaw >= -SIGN_RANGE && facingDYaw <= SIGN_RANGE)
+ {
f32 targetX = o->oPosX + 105.0f * sins(o->oMoveAngleYaw);
f32 targetZ = o->oPosZ + 105.0f * coss(o->oMoveAngleYaw);
@@ -808,10 +940,13 @@ u32 check_read_sign(struct MarioState *m, struct Object *o) {
return FALSE;
}
-u32 check_npc_talk(struct MarioState *m, struct Object *o) {
- if ((m->input & READ_MASK) && mario_can_talk(m, 1)) {
+u32 check_npc_talk(struct MarioState *m, struct Object *o)
+{
+ if (m->input & READ_MASK && mario_can_talk(m, 1))
+ {
s16 facingDYaw = mario_obj_angle_to_object(m, o) - m->faceAngle[1];
- if (facingDYaw >= -0x4000 && facingDYaw <= 0x4000) {
+ if (facingDYaw >= -0x4000 && facingDYaw <= 0x4000)
+ {
o->oInteractStatus = INT_STATUS_INTERACTED;
m->interactObj = o;
@@ -826,23 +961,30 @@ u32 check_npc_talk(struct MarioState *m, struct Object *o) {
return FALSE;
}
-void check_kick_or_punch_wall(struct MarioState *m) {
- if (m->flags & (MARIO_PUNCHING | MARIO_KICKING | MARIO_TRIPPING)) {
+void check_kick_or_punch_wall(struct MarioState *m)
+{
+ if (m->flags & (MARIO_PUNCHING | MARIO_KICKING | MARIO_TRIPPING))
+ {
Vec3f detector;
detector[0] = m->pos[0] + 50.0f * sins(m->faceAngle[1]);
detector[2] = m->pos[2] + 50.0f * coss(m->faceAngle[1]);
detector[1] = m->pos[1];
- if (resolve_and_return_wall_collisions(detector, 80.0f, 5.0f) != NULL) {
- if (m->action != ACT_MOVE_PUNCHING || m->forwardVel >= 0.0f) {
- if (m->action == ACT_PUNCHING) {
+ if (resolve_and_return_wall_collisions(detector, 80.0f, 5.0f) != NULL)
+ {
+ if (m->action != ACT_MOVE_PUNCHING || m->forwardVel >= 0.0f)
+ {
+ if (m->action == ACT_PUNCHING)
+ {
m->action = ACT_MOVE_PUNCHING;
}
mario_set_forward_vel(m, -48.0f);
play_sound(SOUND_ACTION_HIT_2, m->marioObj->header.gfx.cameraToObject);
m->particleFlags |= PARTICLE_TRIANGLE;
- } else if (m->action & ACT_FLAG_AIR) {
+ }
+ else if (m->action & ACT_FLAG_AIR)
+ {
mario_set_forward_vel(m, -16.0f);
play_sound(SOUND_ACTION_HIT_2, m->marioObj->header.gfx.cameraToObject);
m->particleFlags |= PARTICLE_TRIANGLE;
@@ -851,21 +993,26 @@ void check_kick_or_punch_wall(struct MarioState *m) {
}
}
-void mario_process_interactions(struct MarioState *m) {
+void mario_process_interactions(struct MarioState *m)
+{
sDelayInvincTimer = FALSE;
- sInvulnerable = (m->action & ACT_FLAG_INVULNERABLE) || m->invincTimer != 0;
+ sInvulnerable = m->action & ACT_FLAG_INVULNERABLE || m->invincTimer != 0;
- if (!(m->action & ACT_FLAG_INTANGIBLE) && m->collidedObjInteractTypes != 0) {
- s32 i;
- for (i = 0; i < 31; i++) {
+ if (!(m->action & ACT_FLAG_INTANGIBLE) && m->collidedObjInteractTypes != 0)
+ {
+ for (s32 i = 0; i < 31; i++)
+ {
u32 interactType = sInteractionHandlers[i].interactType;
- if (m->collidedObjInteractTypes & interactType) {
+ if (m->collidedObjInteractTypes & interactType)
+ {
struct Object *object = mario_get_collided_object(m, interactType);
m->collidedObjInteractTypes &= ~interactType;
- if (!(object->oInteractStatus & INT_STATUS_INTERACTED)) {
- if (sInteractionHandlers[i].handler(m, interactType, object)) {
+ if (!(object->oInteractStatus & INT_STATUS_INTERACTED))
+ {
+ if (sInteractionHandlers[i].handler(m, interactType, object))
+ {
break;
}
}
@@ -873,7 +1020,8 @@ void mario_process_interactions(struct MarioState *m) {
}
}
- if (m->invincTimer > 0 && !sDelayInvincTimer) {
+ if (m->invincTimer > 0 && !sDelayInvincTimer)
+ {
m->invincTimer -= 1;
}
@@ -882,26 +1030,34 @@ void mario_process_interactions(struct MarioState *m) {
check_kick_or_punch_wall(m);
m->flags &= ~MARIO_PUNCHING & ~MARIO_KICKING & ~MARIO_TRIPPING;
- if (!(m->marioObj->collidedObjInteractTypes & (INTERACT_WARP_DOOR | INTERACT_DOOR))) {
+ if (!(m->marioObj->collidedObjInteractTypes & (INTERACT_WARP_DOOR | INTERACT_DOOR)))
+ {
sDisplayingDoorText = FALSE;
}
- if (!(m->marioObj->collidedObjInteractTypes & INTERACT_WARP)) {
+ if (!(m->marioObj->collidedObjInteractTypes & INTERACT_WARP))
+ {
sJustTeleported = FALSE;
}
}
-void check_death_barrier(struct MarioState *m) {
- if (m->pos[1] < m->floorHeight + 2048.0f) {
- if (level_trigger_warp(m, WARP_OP_WARP_FLOOR) == 20 && !(m->flags & MARIO_UNKNOWN_18)) {
+void check_death_barrier(struct MarioState *m)
+{
+ if (m->pos[1] < m->floorHeight + 2048.0f)
+ {
+ if (level_trigger_warp(m, WARP_OP_WARP_FLOOR) == 20 && !(m->flags & MARIO_UNKNOWN_18))
+ {
play_sound(SOUND_MARIO_WAAAOOOW, m->marioObj->header.gfx.cameraToObject);
}
}
}
-void check_lava_boost(struct MarioState *m) {
- if (!(m->action & ACT_FLAG_RIDING_SHELL) && m->pos[1] < m->floorHeight + 10.0f) {
- if (!(m->flags & MARIO_METAL_CAP)) {
- m->hurtCounter += (m->flags & MARIO_CAP_ON_HEAD) ? 12 : 18;
+void check_lava_boost(struct MarioState *m)
+{
+ if (!(m->action & ACT_FLAG_RIDING_SHELL) && m->pos[1] < m->floorHeight + 10.0f)
+ {
+ if (!(m->flags & MARIO_METAL_CAP))
+ {
+ m->hurtCounter += m->flags & MARIO_CAP_ON_HEAD ? 12 : 18;
}
update_mario_sound_and_camera(m);
@@ -909,42 +1065,50 @@ void check_lava_boost(struct MarioState *m) {
}
}
-void pss_begin_slide(UNUSED struct MarioState *m) {
-// if (!(gHudDisplay.flags & HUD_DISPLAY_FLAG_TIMER)) {
-// level_control_timer(TIMER_CONTROL_SHOW);
-// level_control_timer(TIMER_CONTROL_START);
-// sPssSlideStarted = TRUE;
-// }
+void pss_begin_slide(UNUSED struct MarioState *m)
+{
+ // if (!(gHudDisplay.flags & HUD_DISPLAY_FLAG_TIMER)) {
+ // level_control_timer(TIMER_CONTROL_SHOW);
+ // level_control_timer(TIMER_CONTROL_START);
+ // sPssSlideStarted = TRUE;
+ // }
}
-void pss_end_slide(struct MarioState *m) {
+void pss_end_slide(struct MarioState *m)
+{
//! This flag isn't set on death or level entry, allowing double star spawn
- if (sPssSlideStarted) {
+ if (sPssSlideStarted)
+ {
u16 slideTime = level_control_timer(TIMER_CONTROL_STOP);
- if (slideTime < 630) {
- m->marioObj->oBehParams = (1 << 24);
+ if (slideTime < 630)
+ {
+ m->marioObj->oBehParams = 1 << 24;
spawn_default_star(-6358.0f, -4300.0f, 4700.0f);
}
sPssSlideStarted = FALSE;
}
}
-void mario_handle_special_floors(struct MarioState *m) {
- if ((m->action & ACT_GROUP_MASK) == ACT_GROUP_CUTSCENE) {
+void mario_handle_special_floors(struct MarioState *m)
+{
+ if ((m->action & ACT_GROUP_MASK) == ACT_GROUP_CUTSCENE)
+ {
return;
}
- if (m->floor != NULL) {
+ if (m->floor != NULL)
+ {
s32 floorType = m->floor->type;
- switch (floorType) {
+ switch (floorType)
+ {
case SURFACE_DEATH_PLANE:
case SURFACE_VERTICAL_WIND:
check_death_barrier(m);
break;
case SURFACE_WARP:
-// level_trigger_warp(m, WARP_OP_WARP_FLOOR);
+ // level_trigger_warp(m, WARP_OP_WARP_FLOOR);
break;
case SURFACE_TIMER_START:
@@ -956,8 +1120,10 @@ void mario_handle_special_floors(struct MarioState *m) {
break;
}
- if (!(m->action & ACT_FLAG_AIR) && !(m->action & ACT_FLAG_SWIMMING)) {
- switch (floorType) {
+ if (!(m->action & ACT_FLAG_AIR) && !(m->action & ACT_FLAG_SWIMMING))
+ {
+ switch (floorType)
+ {
case SURFACE_BURNING:
check_lava_boost(m);
break;
diff --git a/src/decomp/game/interaction.h b/src/decomp/game/interaction.h
index b913ccc..9d3e2e9 100644
--- a/src/decomp/game/interaction.h
+++ b/src/decomp/game/interaction.h
@@ -99,19 +99,33 @@
s16 mario_obj_angle_to_object(struct MarioState *m, struct Object *o);
+
void mario_stop_riding_object(struct MarioState *m);
+
void mario_grab_used_object(struct MarioState *m);
+
void mario_drop_held_object(struct MarioState *m);
+
void mario_throw_held_object(struct MarioState *m);
+
void mario_stop_riding_and_holding(struct MarioState *m);
+
u32 does_mario_have_normal_cap_on_head(struct MarioState *m);
+
void mario_blow_off_cap(struct MarioState *m, f32 capSpeed);
+
u32 mario_lose_cap_to_enemy(u32 arg);
+
void mario_retrieve_cap(void);
+
struct Object *mario_get_collided_object(struct MarioState *m, u32 interactType);
+
u32 mario_check_object_grab(struct MarioState *m);
+
u32 get_door_save_file_flag(struct Object *door);
+
void mario_process_interactions(struct MarioState *m);
+
void mario_handle_special_floors(struct MarioState *m);
#endif // INTERACTION_H
diff --git a/src/decomp/game/level_update.h b/src/decomp/game/level_update.h
index 9d17aa0..f752a85 100644
--- a/src/decomp/game/level_update.h
+++ b/src/decomp/game/level_update.h
@@ -88,21 +88,30 @@
// extern s32 sDelayedWarpArg;
// extern u8 unused4[2];
// extern s8 sTimerRunning;
-
-struct HudDisplay {
- /*0x00*/ s16 lives;
- /*0x02*/ s16 coins;
- /*0x04*/ s16 stars;
- /*0x06*/ s16 wedges;
- /*0x08*/ s16 keys;
- /*0x0A*/ s16 flags;
- /*0x0C*/ u16 timer;
+
+struct HudDisplay
+{
+ /*0x00*/
+ s16 lives;
+ /*0x02*/
+ s16 coins;
+ /*0x04*/
+ s16 stars;
+ /*0x06*/
+ s16 wedges;
+ /*0x08*/
+ s16 keys;
+ /*0x0A*/
+ s16 flags;
+ /*0x0C*/
+ u16 timer;
};
-
+
// extern struct HudDisplay gHudDisplay;
// extern s8 gNeverEnteredCastle;
-enum HUDDisplayFlag {
+enum HUDDisplayFlag
+{
HUD_DISPLAY_FLAG_LIVES = 0x0001,
HUD_DISPLAY_FLAG_COIN_COUNT = 0x0002,
HUD_DISPLAY_FLAG_STAR_COUNT = 0x0004,
@@ -111,10 +120,10 @@ enum HUDDisplayFlag {
HUD_DISPLAY_FLAG_UNKNOWN_0020 = 0x0020,
HUD_DISPLAY_FLAG_TIMER = 0x0040,
HUD_DISPLAY_FLAG_EMPHASIZE_POWER = 0x8000,
-
HUD_DISPLAY_NONE = 0x0000,
HUD_DISPLAY_DEFAULT = HUD_DISPLAY_FLAG_LIVES | HUD_DISPLAY_FLAG_COIN_COUNT | HUD_DISPLAY_FLAG_STAR_COUNT | HUD_DISPLAY_FLAG_CAMERA_AND_POWER | HUD_DISPLAY_FLAG_KEYS | HUD_DISPLAY_FLAG_UNKNOWN_0020
};
+
//
//
// u16 level_control_timer(s32 timerOp);
diff --git a/src/decomp/game/mario.c b/src/decomp/game/mario.c
index 250215f..8b2c37c 100644
--- a/src/decomp/game/mario.c
+++ b/src/decomp/game/mario.c
@@ -40,7 +40,7 @@
#include "../../load_anim_data.h"
-static f32 gDefaultSoundArgs[3] = { 0.0f, 0.0f, 0.0f };
+static f32 gDefaultSoundArgs[3] = {0.0f, 0.0f, 0.0f};
/**************************************************
@@ -50,25 +50,28 @@ static f32 gDefaultSoundArgs[3] = { 0.0f, 0.0f, 0.0f };
/**
* Checks if Mario's animation has reached its end point.
*/
-s32 is_anim_at_end(struct MarioState *m) {
+s32 is_anim_at_end(struct MarioState *m)
+{
struct Object *o = m->marioObj;
- return (o->header.gfx.animInfo.animFrame + 1) == o->header.gfx.animInfo.curAnim->loopEnd;
+ return o->header.gfx.animInfo.animFrame + 1 == o->header.gfx.animInfo.curAnim->loopEnd;
}
/**
* Checks if Mario's animation has surpassed 2 frames before its end point.
*/
-s32 is_anim_past_end(struct MarioState *m) {
+s32 is_anim_past_end(struct MarioState *m)
+{
struct Object *o = m->marioObj;
- return o->header.gfx.animInfo.animFrame >= (o->header.gfx.animInfo.curAnim->loopEnd - 2);
+ return o->header.gfx.animInfo.animFrame >= o->header.gfx.animInfo.curAnim->loopEnd - 2;
}
/**
* Sets Mario's animation without any acceleration, running at its default rate.
*/
-s16 set_mario_animation(struct MarioState *m, s32 targetAnimID) {
+s16 set_mario_animation(struct MarioState *m, s32 targetAnimID)
+{
struct Object *o = m->marioObj;
load_mario_animation(m->animation, targetAnimID);
@@ -78,18 +81,25 @@ s16 set_mario_animation(struct MarioState *m, s32 targetAnimID) {
// targetAnim->index = (void *) VIRTUAL_TO_PHYSICAL((u8 *) targetAnim + (uintptr_t) targetAnim->index);
//}
- if (o->header.gfx.animInfo.animID != targetAnimID) {
+ if (o->header.gfx.animInfo.animID != targetAnimID)
+ {
o->header.gfx.animInfo.animID = targetAnimID;
o->header.gfx.animInfo.curAnim = targetAnim;
o->header.gfx.animInfo.animAccel = 0;
o->header.gfx.animInfo.animYTrans = m->unkB0;
- if (targetAnim->flags & ANIM_FLAG_2) {
+ if (targetAnim->flags & ANIM_FLAG_2)
+ {
o->header.gfx.animInfo.animFrame = targetAnim->startFrame;
- } else {
- if (targetAnim->flags & ANIM_FLAG_FORWARD) {
+ }
+ else
+ {
+ if (targetAnim->flags & ANIM_FLAG_FORWARD)
+ {
o->header.gfx.animInfo.animFrame = targetAnim->startFrame + 1;
- } else {
+ }
+ else
+ {
o->header.gfx.animInfo.animFrame = targetAnim->startFrame - 1;
}
}
@@ -102,7 +112,8 @@ s16 set_mario_animation(struct MarioState *m, s32 targetAnimID) {
* Sets Mario's animation where the animation is sped up or
* slowed down via acceleration.
*/
-s16 set_mario_anim_with_accel(struct MarioState *m, s32 targetAnimID, s32 accel) {
+s16 set_mario_anim_with_accel(struct MarioState *m, s32 targetAnimID, s32 accel)
+{
struct Object *o = m->marioObj;
load_mario_animation(m->animation, targetAnimID);
@@ -112,22 +123,29 @@ s16 set_mario_anim_with_accel(struct MarioState *m, s32 targetAnimID, s32 accel)
// targetAnim->index = (void *) VIRTUAL_TO_PHYSICAL((u8 *) targetAnim + (uintptr_t) targetAnim->index);
//}
- if (o->header.gfx.animInfo.animID != targetAnimID) {
+ if (o->header.gfx.animInfo.animID != targetAnimID)
+ {
o->header.gfx.animInfo.animID = targetAnimID;
o->header.gfx.animInfo.curAnim = targetAnim;
o->header.gfx.animInfo.animYTrans = m->unkB0;
- if (targetAnim->flags & ANIM_FLAG_2) {
- o->header.gfx.animInfo.animFrameAccelAssist = (targetAnim->startFrame << 0x10);
- } else {
- if (targetAnim->flags & ANIM_FLAG_FORWARD) {
+ if (targetAnim->flags & ANIM_FLAG_2)
+ {
+ o->header.gfx.animInfo.animFrameAccelAssist = targetAnim->startFrame << 0x10;
+ }
+ else
+ {
+ if (targetAnim->flags & ANIM_FLAG_FORWARD)
+ {
o->header.gfx.animInfo.animFrameAccelAssist = (targetAnim->startFrame << 0x10) + accel;
- } else {
+ }
+ else
+ {
o->header.gfx.animInfo.animFrameAccelAssist = (targetAnim->startFrame << 0x10) - accel;
}
}
- o->header.gfx.animInfo.animFrame = (o->header.gfx.animInfo.animFrameAccelAssist >> 0x10);
+ o->header.gfx.animInfo.animFrame = o->header.gfx.animInfo.animFrameAccelAssist >> 0x10;
}
o->header.gfx.animInfo.animAccel = accel;
@@ -138,46 +156,66 @@ s16 set_mario_anim_with_accel(struct MarioState *m, s32 targetAnimID, s32 accel)
/**
* Sets the animation to a specific "next" frame from the frame given.
*/
-void set_anim_to_frame(struct MarioState *m, s16 animFrame) {
+void set_anim_to_frame(struct MarioState *m, s16 animFrame)
+{
struct AnimInfo *animInfo = &m->marioObj->header.gfx.animInfo;
struct Animation *curAnim = animInfo->curAnim;
- if (animInfo->animAccel) {
- if (curAnim->flags & ANIM_FLAG_FORWARD) {
+ if (animInfo->animAccel)
+ {
+ if (curAnim->flags & ANIM_FLAG_FORWARD)
+ {
animInfo->animFrameAccelAssist = (animFrame << 0x10) + animInfo->animAccel;
- } else {
+ }
+ else
+ {
animInfo->animFrameAccelAssist = (animFrame << 0x10) - animInfo->animAccel;
}
- } else {
- if (curAnim->flags & ANIM_FLAG_FORWARD) {
+ }
+ else
+ {
+ if (curAnim->flags & ANIM_FLAG_FORWARD)
+ {
animInfo->animFrame = animFrame + 1;
- } else {
+ }
+ else
+ {
animInfo->animFrame = animFrame - 1;
}
}
}
-s32 is_anim_past_frame(struct MarioState *m, s16 animFrame) {
+s32 is_anim_past_frame(struct MarioState *m, s16 animFrame)
+{
s32 isPastFrame;
s32 acceleratedFrame = animFrame << 0x10;
struct AnimInfo *animInfo = &m->marioObj->header.gfx.animInfo;
struct Animation *curAnim = animInfo->curAnim;
- if (animInfo->animAccel) {
- if (curAnim->flags & ANIM_FLAG_FORWARD) {
+ if (animInfo->animAccel)
+ {
+ if (curAnim->flags & ANIM_FLAG_FORWARD)
+ {
isPastFrame =
- (animInfo->animFrameAccelAssist > acceleratedFrame)
- && (acceleratedFrame >= (animInfo->animFrameAccelAssist - animInfo->animAccel));
- } else {
- isPastFrame =
- (animInfo->animFrameAccelAssist < acceleratedFrame)
- && (acceleratedFrame <= (animInfo->animFrameAccelAssist + animInfo->animAccel));
+ animInfo->animFrameAccelAssist > acceleratedFrame
+ && acceleratedFrame >= animInfo->animFrameAccelAssist - animInfo->animAccel;
}
- } else {
- if (curAnim->flags & ANIM_FLAG_FORWARD) {
- isPastFrame = (animInfo->animFrame == (animFrame + 1));
- } else {
- isPastFrame = ((animInfo->animFrame + 1) == animFrame);
+ else
+ {
+ isPastFrame =
+ animInfo->animFrameAccelAssist < acceleratedFrame
+ && acceleratedFrame <= animInfo->animFrameAccelAssist + animInfo->animAccel;
+ }
+ }
+ else
+ {
+ if (curAnim->flags & ANIM_FLAG_FORWARD)
+ {
+ isPastFrame = animInfo->animFrame == animFrame + 1;
+ }
+ else
+ {
+ isPastFrame = animInfo->animFrame + 1 == animFrame;
}
}
@@ -188,24 +226,25 @@ s32 is_anim_past_frame(struct MarioState *m, s16 animFrame) {
* Rotates the animation's translation into the global coordinate system
* and returns the animation's flags.
*/
-s16 find_mario_anim_flags_and_translation(struct Object *obj, s32 yaw, Vec3s translation) {
+s16 find_mario_anim_flags_and_translation(struct Object *obj, s32 yaw, Vec3s translation)
+{
f32 dx;
f32 dz;
- struct Animation *curAnim = (void *) obj->header.gfx.animInfo.curAnim;
+ struct Animation *curAnim = (void *)obj->header.gfx.animInfo.curAnim;
s16 animFrame = geo_update_animation_frame(&obj->header.gfx.animInfo, NULL);
- u16 *animIndex = segmented_to_virtual((void *) curAnim->index);
- s16 *animValues = segmented_to_virtual((void *) curAnim->values);
+ u16 *animIndex = segmented_to_virtual(curAnim->index);
+ s16 *animValues = segmented_to_virtual(curAnim->values);
- f32 s = (f32) sins(yaw);
- f32 c = (f32) coss(yaw);
+ f32 s = sins(yaw);
+ f32 c = coss(yaw);
- dx = *(animValues + (retrieve_animation_index(animFrame, &animIndex))) / 4.0f;
- translation[1] = *(animValues + (retrieve_animation_index(animFrame, &animIndex))) / 4.0f;
- dz = *(animValues + (retrieve_animation_index(animFrame, &animIndex))) / 4.0f;
+ dx = *(animValues + retrieve_animation_index(animFrame, &animIndex)) / 4.0f;
+ translation[1] = *(animValues + retrieve_animation_index(animFrame, &animIndex)) / 4.0f;
+ dz = *(animValues + retrieve_animation_index(animFrame, &animIndex)) / 4.0f;
- translation[0] = (dx * c) + (dz * s);
- translation[2] = (-dx * s) + (dz * c);
+ translation[0] = dx * c + dz * s;
+ translation[2] = -dx * s + dz * c;
return curAnim->flags;
}
@@ -213,26 +252,30 @@ s16 find_mario_anim_flags_and_translation(struct Object *obj, s32 yaw, Vec3s tra
/**
* Updates Mario's position from his animation's translation.
*/
-void update_mario_pos_for_anim(struct MarioState *m) {
+void update_mario_pos_for_anim(struct MarioState *m)
+{
Vec3s translation;
s16 flags;
flags = find_mario_anim_flags_and_translation(m->marioObj, m->faceAngle[1], translation);
- if (flags & (ANIM_FLAG_HOR_TRANS | ANIM_FLAG_6)) {
- m->pos[0] += (f32) translation[0];
- m->pos[2] += (f32) translation[2];
+ if (flags & (ANIM_FLAG_HOR_TRANS | ANIM_FLAG_6))
+ {
+ m->pos[0] += (f32)translation[0];
+ m->pos[2] += (f32)translation[2];
}
- if (flags & (ANIM_FLAG_VERT_TRANS | ANIM_FLAG_6)) {
- m->pos[1] += (f32) translation[1];
+ if (flags & (ANIM_FLAG_VERT_TRANS | ANIM_FLAG_6))
+ {
+ m->pos[1] += (f32)translation[1];
}
}
/**
* Finds the vertical translation from Mario's animation.
*/
-s16 return_mario_anim_y_translation(struct MarioState *m) {
+s16 return_mario_anim_y_translation(struct MarioState *m)
+{
Vec3s translation;
find_mario_anim_flags_and_translation(m->marioObj, 0, translation);
@@ -246,8 +289,10 @@ s16 return_mario_anim_y_translation(struct MarioState *m) {
/**
* Plays a sound if if Mario doesn't have the flag being checked.
*/
-void play_sound_if_no_flag(struct MarioState *m, u32 soundBits, u32 flags) {
- if (!(m->flags & flags)) {
+void play_sound_if_no_flag(struct MarioState *m, u32 soundBits, u32 flags)
+{
+ if (!(m->flags & flags))
+ {
play_sound(soundBits, m->marioObj->header.gfx.cameraToObject);
m->flags |= flags;
}
@@ -256,19 +301,24 @@ void play_sound_if_no_flag(struct MarioState *m, u32 soundBits, u32 flags) {
/**
* Plays a jump sound if one has not been played since the last action change.
*/
-void play_mario_jump_sound(struct MarioState *m) {
- if (!(m->flags & MARIO_MARIO_SOUND_PLAYED)) {
-#ifndef VERSION_JP
- if (m->action == ACT_TRIPLE_JUMP) {
+void play_mario_jump_sound(struct MarioState *m)
+{
+ if (!(m->flags & MARIO_MARIO_SOUND_PLAYED))
+ {
+ #ifndef VERSION_JP
+ if (m->action == ACT_TRIPLE_JUMP)
+ {
play_sound(SOUND_MARIO_YAHOO_WAHA_YIPPEE + ((gAudioRandom % 5) << 16),
m->marioObj->header.gfx.cameraToObject);
- } else {
-#endif
+ }
+ else
+ {
+ #endif
play_sound(SOUND_MARIO_YAH_WAH_HOO + ((gAudioRandom % 3) << 16),
m->marioObj->header.gfx.cameraToObject);
-#ifndef VERSION_JP
+ #ifndef VERSION_JP
}
-#endif
+ #endif
m->flags |= MARIO_MARIO_SOUND_PLAYED;
}
}
@@ -276,33 +326,47 @@ void play_mario_jump_sound(struct MarioState *m) {
/**
* Adjusts the volume/pitch of sounds from Mario's speed.
*/
-void adjust_sound_for_speed(struct MarioState *m) {
- s32 absForwardVel = (m->forwardVel > 0.0f) ? m->forwardVel : -m->forwardVel;
- func_80320A4C(1, (absForwardVel > 100) ? 100 : absForwardVel);
+void adjust_sound_for_speed(struct MarioState *m)
+{
+ s32 absForwardVel = m->forwardVel > 0.0f ? m->forwardVel : -m->forwardVel;
+ func_80320A4C(1, absForwardVel > 100 ? 100 : absForwardVel);
}
/**
* Spawns particles if the step sound says to, then either plays a step sound or relevant other sound.
*/
-void play_sound_and_spawn_particles(struct MarioState *m, u32 soundBits, u32 waveParticleType) {
- if (m->terrainSoundAddend == (SOUND_TERRAIN_WATER << 16)) {
- if (waveParticleType != 0) {
+void play_sound_and_spawn_particles(struct MarioState *m, u32 soundBits, u32 waveParticleType)
+{
+ if (m->terrainSoundAddend == SOUND_TERRAIN_WATER << 16)
+ {
+ if (waveParticleType != 0)
+ {
m->particleFlags |= PARTICLE_SHALLOW_WATER_SPLASH;
- } else {
+ }
+ else
+ {
m->particleFlags |= PARTICLE_SHALLOW_WATER_WAVE;
}
- } else {
- if (m->terrainSoundAddend == (SOUND_TERRAIN_SAND << 16)) {
+ }
+ else
+ {
+ if (m->terrainSoundAddend == SOUND_TERRAIN_SAND << 16)
+ {
m->particleFlags |= PARTICLE_DIRT;
- } else if (m->terrainSoundAddend == (SOUND_TERRAIN_SNOW << 16)) {
+ }
+ else if (m->terrainSoundAddend == SOUND_TERRAIN_SNOW << 16)
+ {
m->particleFlags |= PARTICLE_SNOW;
}
}
- if ((m->flags & MARIO_METAL_CAP) || soundBits == SOUND_ACTION_UNSTUCK_FROM_GROUND
- || soundBits == SOUND_MARIO_PUNCH_HOO) {
+ if (m->flags & MARIO_METAL_CAP || soundBits == SOUND_ACTION_UNSTUCK_FROM_GROUND
+ || soundBits == SOUND_MARIO_PUNCH_HOO)
+ {
play_sound(soundBits, m->marioObj->header.gfx.cameraToObject);
- } else {
+ }
+ else
+ {
play_sound(m->terrainSoundAddend + soundBits, m->marioObj->header.gfx.cameraToObject);
}
}
@@ -310,8 +374,10 @@ void play_sound_and_spawn_particles(struct MarioState *m, u32 soundBits, u32 wav
/**
* Plays an environmental sound if one has not been played since the last action change.
*/
-void play_mario_action_sound(struct MarioState *m, u32 soundBits, u32 waveParticleType) {
- if (!(m->flags & MARIO_ACTION_SOUND_PLAYED)) {
+void play_mario_action_sound(struct MarioState *m, u32 soundBits, u32 waveParticleType)
+{
+ if (!(m->flags & MARIO_ACTION_SOUND_PLAYED))
+ {
play_sound_and_spawn_particles(m, soundBits, waveParticleType);
m->flags |= MARIO_ACTION_SOUND_PLAYED;
}
@@ -320,9 +386,10 @@ void play_mario_action_sound(struct MarioState *m, u32 soundBits, u32 wavePartic
/**
* Plays a landing sound, accounting for metal cap.
*/
-void play_mario_landing_sound(struct MarioState *m, u32 soundBits) {
+void play_mario_landing_sound(struct MarioState *m, u32 soundBits)
+{
play_sound_and_spawn_particles(
- m, (m->flags & MARIO_METAL_CAP) ? SOUND_ACTION_METAL_LANDING : soundBits, 1);
+ m, m->flags & MARIO_METAL_CAP ? SOUND_ACTION_METAL_LANDING : soundBits, 1);
}
/**
@@ -330,17 +397,19 @@ void play_mario_landing_sound(struct MarioState *m, u32 soundBits) {
* this function uses play_mario_action_sound, making sure the sound is only
* played once per action.
*/
-void play_mario_landing_sound_once(struct MarioState *m, u32 soundBits) {
+void play_mario_landing_sound_once(struct MarioState *m, u32 soundBits)
+{
play_mario_action_sound(
- m, (m->flags & MARIO_METAL_CAP) ? SOUND_ACTION_METAL_LANDING : soundBits, 1);
+ m, m->flags & MARIO_METAL_CAP ? SOUND_ACTION_METAL_LANDING : soundBits, 1);
}
/**
* Plays a heavy landing (ground pound, etc.) sound, accounting for metal cap.
*/
-void play_mario_heavy_landing_sound(struct MarioState *m, u32 soundBits) {
+void play_mario_heavy_landing_sound(struct MarioState *m, u32 soundBits)
+{
play_sound_and_spawn_particles(
- m, (m->flags & MARIO_METAL_CAP) ? SOUND_ACTION_METAL_HEAVY_LANDING : soundBits, 1);
+ m, m->flags & MARIO_METAL_CAP ? SOUND_ACTION_METAL_HEAVY_LANDING : soundBits, 1);
}
/**
@@ -348,27 +417,35 @@ void play_mario_heavy_landing_sound(struct MarioState *m, u32 soundBits) {
* Unlike play_mario_heavy_landing_sound, this function uses play_mario_action_sound,
* making sure the sound is only played once per action.
*/
-void play_mario_heavy_landing_sound_once(struct MarioState *m, u32 soundBits) {
+void play_mario_heavy_landing_sound_once(struct MarioState *m, u32 soundBits)
+{
play_mario_action_sound(
- m, (m->flags & MARIO_METAL_CAP) ? SOUND_ACTION_METAL_HEAVY_LANDING : soundBits, 1);
+ m, m->flags & MARIO_METAL_CAP ? SOUND_ACTION_METAL_HEAVY_LANDING : soundBits, 1);
}
/**
* Plays action and Mario sounds relevant to what was passed into the function.
*/
-void play_mario_sound(struct MarioState *m, s32 actionSound, s32 marioSound) {
- if (actionSound == SOUND_ACTION_TERRAIN_JUMP) {
- play_mario_action_sound(m, (m->flags & MARIO_METAL_CAP) ? (s32) SOUND_ACTION_METAL_JUMP
- : (s32) SOUND_ACTION_TERRAIN_JUMP, 1);
- } else {
+void play_mario_sound(struct MarioState *m, s32 actionSound, s32 marioSound)
+{
+ if (actionSound == SOUND_ACTION_TERRAIN_JUMP)
+ {
+ play_mario_action_sound(m, m->flags & MARIO_METAL_CAP
+ ? (s32)SOUND_ACTION_METAL_JUMP
+ : (s32)SOUND_ACTION_TERRAIN_JUMP, 1);
+ }
+ else
+ {
play_sound_if_no_flag(m, actionSound, MARIO_ACTION_SOUND_PLAYED);
}
- if (marioSound == 0) {
+ if (marioSound == 0)
+ {
play_mario_jump_sound(m);
}
- if (marioSound != -1) {
+ if (marioSound != -1)
+ {
play_sound_if_no_flag(m, marioSound, MARIO_MARIO_SOUND_PLAYED);
}
}
@@ -380,33 +457,40 @@ void play_mario_sound(struct MarioState *m, s32 actionSound, s32 marioSound) {
/**
* Sets Mario's other velocities from his forward speed.
*/
-void mario_set_forward_vel(struct MarioState *m, f32 forwardVel) {
+void mario_set_forward_vel(struct MarioState *m, f32 forwardVel)
+{
m->forwardVel = forwardVel;
m->slideVelX = sins(m->faceAngle[1]) * m->forwardVel;
m->slideVelZ = coss(m->faceAngle[1]) * m->forwardVel;
- m->vel[0] = (f32) m->slideVelX;
- m->vel[2] = (f32) m->slideVelZ;
+ m->vel[0] = m->slideVelX;
+ m->vel[2] = m->slideVelZ;
}
/**
* Returns the slipperiness class of Mario's floor.
*/
-s32 mario_get_floor_class(struct MarioState *m) {
+s32 mario_get_floor_class(struct MarioState *m)
+{
s32 floorClass;
// The slide terrain type defaults to slide slipperiness.
// This doesn't matter too much since normally the slide terrain
// is checked for anyways.
- if (m->curTerrain == TERRAIN_SLIDE) {
+ if (m->curTerrain == TERRAIN_SLIDE)
+ {
floorClass = SURFACE_CLASS_VERY_SLIPPERY;
- } else {
+ }
+ else
+ {
floorClass = SURFACE_CLASS_DEFAULT;
}
- if (m->floor != NULL) {
- switch (m->floor->type) {
+ if (m->floor != NULL)
+ {
+ switch (m->floor->type)
+ {
case SURFACE_NOT_SLIPPERY:
case SURFACE_HARD_NOT_SLIPPERY:
case SURFACE_SWITCH:
@@ -433,7 +517,8 @@ s32 mario_get_floor_class(struct MarioState *m) {
}
// Crawling allows Mario to not slide on certain steeper surfaces.
- if (m->action == ACT_CRAWLING && m->floor->normal.y > 0.5f && floorClass == SURFACE_CLASS_DEFAULT) {
+ if (m->action == ACT_CRAWLING && m->floor->normal.y > 0.5f && floorClass == SURFACE_CLASS_DEFAULT)
+ {
floorClass = SURFACE_CLASS_NOT_SLIPPERY;
}
@@ -465,22 +550,30 @@ s8 sTerrainSounds[7][6] = {
* Computes a value that should be added to terrain sounds before playing them.
* This depends on surfaces and terrain.
*/
-u32 mario_get_terrain_sound_addend(struct MarioState *m) {
+u32 mario_get_terrain_sound_addend(struct MarioState *m)
+{
s16 floorSoundType;
s32 ret = SOUND_TERRAIN_DEFAULT << 16;
s32 floorType;
- if (m->floor != NULL) {
+ if (m->floor != NULL)
+ {
floorType = m->floor->type;
s16 terrainType = m->curTerrain;
- if ((gCurrLevelNum != LEVEL_LLL) && (m->floorHeight < (m->waterLevel - 10))) {
+ if (gCurrLevelNum != LEVEL_LLL && m->floorHeight < m->waterLevel - 10)
+ {
// Water terrain sound, excluding LLL since it uses water in the volcano.
ret = SOUND_TERRAIN_WATER << 16;
- } else if (SURFACE_IS_QUICKSAND(floorType)) {
+ }
+ else if (SURFACE_IS_QUICKSAND(floorType))
+ {
ret = SOUND_TERRAIN_SAND << 16;
- } else {
- switch (floorType) {
+ }
+ else
+ {
+ switch (floorType)
+ {
default:
floorSoundType = 0;
break;
@@ -527,7 +620,8 @@ u32 mario_get_terrain_sound_addend(struct MarioState *m) {
/**
* Collides with walls and returns the most recent wall.
*/
-struct SM64SurfaceCollisionData *resolve_and_return_wall_collisions(Vec3f pos, f32 offset, f32 radius) {
+struct SM64SurfaceCollisionData *resolve_and_return_wall_collisions(Vec3f pos, f32 offset, f32 radius)
+{
struct SM64WallCollisionData collisionData;
struct SM64SurfaceCollisionData *wall = NULL;
@@ -537,7 +631,8 @@ struct SM64SurfaceCollisionData *resolve_and_return_wall_collisions(Vec3f pos, f
collisionData.radius = radius;
collisionData.offsetY = offset;
- if (find_wall_collisions(&collisionData)) {
+ if (find_wall_collisions(&collisionData))
+ {
wall = collisionData.walls[collisionData.numWalls - 1];
}
@@ -553,7 +648,8 @@ struct SM64SurfaceCollisionData *resolve_and_return_wall_collisions(Vec3f pos, f
/**
* Finds the ceiling from a vec3f horizontally and a height (with 80 vertical buffer).
*/
-f32 vec3f_find_ceil(Vec3f pos, f32 height, struct SM64SurfaceCollisionData **ceil) {
+f32 vec3f_find_ceil(Vec3f pos, f32 height, struct SM64SurfaceCollisionData **ceil)
+{
UNUSED f32 unused;
return find_ceil(pos[0], height + 80.0f, pos[2], ceil);
@@ -562,33 +658,38 @@ f32 vec3f_find_ceil(Vec3f pos, f32 height, struct SM64SurfaceCollisionData **cei
/**
* Determines if Mario is facing "downhill."
*/
-s32 mario_facing_downhill(struct MarioState *m, s32 turnYaw) {
+s32 mario_facing_downhill(struct MarioState *m, s32 turnYaw)
+{
s16 faceAngleYaw = m->faceAngle[1];
// This is never used in practice, as turnYaw is
// always passed as zero.
- if (turnYaw && m->forwardVel < 0.0f) {
+ if (turnYaw && m->forwardVel < 0.0f)
+ {
faceAngleYaw += 0x8000;
}
faceAngleYaw = m->floorAngle - faceAngleYaw;
- return (-0x4000 < faceAngleYaw) && (faceAngleYaw < 0x4000);
+ return -0x4000 < faceAngleYaw && faceAngleYaw < 0x4000;
}
/**
* Determines if a surface is slippery based on the surface class.
*/
-u32 mario_floor_is_slippery(struct MarioState *m) {
+u32 mario_floor_is_slippery(struct MarioState *m)
+{
f32 normY;
if (m->curTerrain == TERRAIN_SLIDE
&& m->floor->normal.y < 0.9998477f //~cos(1 deg)
- ) {
+ )
+ {
return TRUE;
}
- switch (mario_get_floor_class(m)) {
+ switch (mario_get_floor_class(m))
+ {
case SURFACE_VERY_SLIPPERY:
normY = 0.9848077f; //~cos(10 deg)
break;
@@ -612,15 +713,18 @@ u32 mario_floor_is_slippery(struct MarioState *m) {
/**
* Determines if a surface is a slope based on the surface class.
*/
-s32 mario_floor_is_slope(struct MarioState *m) {
+s32 mario_floor_is_slope(struct MarioState *m)
+{
f32 normY;
if (m->curTerrain == TERRAIN_SLIDE
- && m->floor->normal.y < 0.9998477f) { // ~cos(1 deg)
+ && m->floor->normal.y < 0.9998477f)
+ { // ~cos(1 deg)
return TRUE;
}
- switch (mario_get_floor_class(m)) {
+ switch (mario_get_floor_class(m))
+ {
case SURFACE_VERY_SLIPPERY:
normY = 0.9961947f; // ~cos(5 deg)
break;
@@ -644,7 +748,8 @@ s32 mario_floor_is_slope(struct MarioState *m) {
/**
* Determines if a surface is steep based on the surface class.
*/
-s32 mario_floor_is_steep(struct MarioState *m) {
+s32 mario_floor_is_steep(struct MarioState *m)
+{
f32 normY;
s32 result = FALSE;
@@ -652,8 +757,10 @@ s32 mario_floor_is_steep(struct MarioState *m) {
// slide terrain type. This means that steep behavior persists for
// non-slippery and slippery surfaces.
// This does not matter in vanilla game practice.
- if (!mario_facing_downhill(m, FALSE)) {
- switch (mario_get_floor_class(m)) {
+ if (!mario_facing_downhill(m, FALSE))
+ {
+ switch (mario_get_floor_class(m))
+ {
case SURFACE_VERY_SLIPPERY:
normY = 0.9659258f; // ~cos(15 deg)
break;
@@ -680,7 +787,8 @@ s32 mario_floor_is_steep(struct MarioState *m) {
/**
* Finds the floor height relative from Mario given polar displacement.
*/
-f32 find_floor_height_relative_polar(struct MarioState *m, s16 angleFromMario, f32 distFromMario) {
+f32 find_floor_height_relative_polar(struct MarioState *m, s16 angleFromMario, f32 distFromMario)
+{
struct SM64SurfaceCollisionData *floor;
f32 floorY;
@@ -695,7 +803,8 @@ f32 find_floor_height_relative_polar(struct MarioState *m, s16 angleFromMario, f
/**
* Returns the slope of the floor based off points around Mario.
*/
-s16 find_floor_slope(struct MarioState *m, s16 yawOffset) {
+s16 find_floor_slope(struct MarioState *m, s16 yawOffset)
+{
struct SM64SurfaceCollisionData *floor;
f32 forwardFloorY, backwardFloorY;
f32 forwardYDelta, backwardYDelta;
@@ -712,9 +821,12 @@ s16 find_floor_slope(struct MarioState *m, s16 yawOffset) {
forwardYDelta = forwardFloorY - m->pos[1];
backwardYDelta = m->pos[1] - backwardFloorY;
- if (forwardYDelta * forwardYDelta < backwardYDelta * backwardYDelta) {
+ if (forwardYDelta * forwardYDelta < backwardYDelta * backwardYDelta)
+ {
result = atan2s(5.0f, forwardYDelta);
- } else {
+ }
+ else
+ {
result = atan2s(5.0f, backwardYDelta);
}
@@ -724,21 +836,27 @@ s16 find_floor_slope(struct MarioState *m, s16 yawOffset) {
/**
* Adjusts Mario's camera and sound based on his action status.
*/
-void update_mario_sound_and_camera(struct MarioState *m) {
+void update_mario_sound_and_camera(struct MarioState *m)
+{
u32 action = m->action;
s32 camPreset = m->area->camera->mode;
- if (action == ACT_FIRST_PERSON) {
+ if (action == ACT_FIRST_PERSON)
+ {
raise_background_noise(2);
gCameraMovementFlags &= ~CAM_MOVE_C_UP_MODE;
// Go back to the last camera mode
set_camera_mode(m->area->camera, -1, 1);
- } else if (action == ACT_SLEEPING) {
+ }
+ else if (action == ACT_SLEEPING)
+ {
raise_background_noise(2);
}
- if (!(action & (ACT_FLAG_SWIMMING | ACT_FLAG_METAL_WATER))) {
- if (camPreset == CAMERA_MODE_BEHIND_MARIO || camPreset == CAMERA_MODE_WATER_SURFACE) {
+ if (!(action & (ACT_FLAG_SWIMMING | ACT_FLAG_METAL_WATER)))
+ {
+ if (camPreset == CAMERA_MODE_BEHIND_MARIO || camPreset == CAMERA_MODE_WATER_SURFACE)
+ {
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
}
}
@@ -747,10 +865,12 @@ void update_mario_sound_and_camera(struct MarioState *m) {
/**
* Transitions Mario to a steep jump action.
*/
-void set_steep_jump_action(struct MarioState *m) {
+void set_steep_jump_action(struct MarioState *m)
+{
m->marioObj->oMarioSteepJumpYaw = m->faceAngle[1];
- if (m->forwardVel > 0.0f) {
+ if (m->forwardVel > 0.0f)
+ {
//! ((s16)0x8000) has undefined behavior. Therefore, this downcast has
// undefined behavior if m->floorAngle >= 0.
s16 angleTemp = m->floorAngle + 0x8000;
@@ -769,12 +889,14 @@ void set_steep_jump_action(struct MarioState *m) {
/**
* Sets Mario's vertical speed from his forward speed.
*/
-static void set_mario_y_vel_based_on_fspeed(struct MarioState *m, f32 initialVelY, f32 multiplier) {
+static void set_mario_y_vel_based_on_fspeed(struct MarioState *m, f32 initialVelY, f32 multiplier)
+{
// get_additive_y_vel_for_jumps is always 0 and a stubbed function.
// It was likely trampoline related based on code location.
m->vel[1] = initialVelY + get_additive_y_vel_for_jumps() + m->forwardVel * multiplier;
- if (m->squishTimer != 0 || m->quicksandDepth > 1.0f) {
+ if (m->squishTimer != 0 || m->quicksandDepth > 1.0f)
+ {
m->vel[1] *= 0.5f;
}
}
@@ -782,15 +904,18 @@ static void set_mario_y_vel_based_on_fspeed(struct MarioState *m, f32 initialVel
/**
* Transitions for a variety of airborne actions.
*/
-static u32 set_mario_action_airborne(struct MarioState *m, u32 action, u32 actionArg) {
+static u32 set_mario_action_airborne(struct MarioState *m, u32 action, u32 actionArg)
+{
f32 fowardVel;
if ((m->squishTimer != 0 || m->quicksandDepth >= 1.0f)
- && (action == ACT_DOUBLE_JUMP || action == ACT_TWIRLING)) {
+ && (action == ACT_DOUBLE_JUMP || action == ACT_TWIRLING))
+ {
action = ACT_JUMP;
}
- switch (action) {
+ switch (action)
+ {
case ACT_DOUBLE_JUMP:
set_mario_y_vel_based_on_fspeed(m, 52.0f, 0.25f);
m->forwardVel *= 0.8f;
@@ -813,7 +938,8 @@ static u32 set_mario_action_airborne(struct MarioState *m, u32 action, u32 actio
case ACT_WATER_JUMP:
case ACT_HOLD_WATER_JUMP:
- if (actionArg == 0) {
+ if (actionArg == 0)
+ {
set_mario_y_vel_based_on_fspeed(m, 42.0f, 0.0f);
}
break;
@@ -837,7 +963,8 @@ static u32 set_mario_action_airborne(struct MarioState *m, u32 action, u32 actio
case ACT_WALL_KICK_AIR:
case ACT_TOP_OF_POLE_JUMP:
set_mario_y_vel_based_on_fspeed(m, 62.0f, 0.0f);
- if (m->forwardVel < 24.0f) {
+ if (m->forwardVel < 24.0f)
+ {
m->forwardVel = 24.0f;
}
m->wallKickTimer = 0;
@@ -857,13 +984,15 @@ static u32 set_mario_action_airborne(struct MarioState *m, u32 action, u32 actio
case ACT_LAVA_BOOST:
m->vel[1] = 84.0f;
- if (actionArg == 0) {
+ if (actionArg == 0)
+ {
m->forwardVel = 0.0f;
}
break;
case ACT_DIVE:
- if ((fowardVel = m->forwardVel + 15.0f) > 48.0f) {
+ if ((fowardVel = m->forwardVel + 15.0f) > 48.0f)
+ {
fowardVel = 48.0f;
}
mario_set_forward_vel(m, fowardVel);
@@ -876,14 +1005,16 @@ static u32 set_mario_action_airborne(struct MarioState *m, u32 action, u32 actio
//! (BLJ's) This properly handles long jumps from getting forward speed with
// too much velocity, but misses backwards longs allowing high negative speeds.
- if ((m->forwardVel *= 1.5f) > 48.0f) {
+ if ((m->forwardVel *= 1.5f) > 48.0f)
+ {
m->forwardVel = 48.0f;
}
break;
case ACT_SLIDE_KICK:
m->vel[1] = 12.0f;
- if (m->forwardVel < 32.0f) {
+ if (m->forwardVel < 32.0f)
+ {
m->forwardVel = 32.0f;
}
break;
@@ -902,15 +1033,19 @@ static u32 set_mario_action_airborne(struct MarioState *m, u32 action, u32 actio
/**
* Transitions for a variety of moving actions.
*/
-static u32 set_mario_action_moving(struct MarioState *m, u32 action, UNUSED u32 actionArg) {
+static u32 set_mario_action_moving(struct MarioState *m, u32 action, UNUSED u32 actionArg)
+{
s16 floorClass = mario_get_floor_class(m);
f32 forwardVel = m->forwardVel;
f32 mag = min(m->intendedMag, 8.0f);
- switch (action) {
+ switch (action)
+ {
case ACT_WALKING:
- if (floorClass != SURFACE_CLASS_VERY_SLIPPERY) {
- if (0.0f <= forwardVel && forwardVel < mag) {
+ if (floorClass != SURFACE_CLASS_VERY_SLIPPERY)
+ {
+ if (0.0f <= forwardVel && forwardVel < mag)
+ {
m->forwardVel = mag;
}
}
@@ -919,23 +1054,30 @@ static u32 set_mario_action_moving(struct MarioState *m, u32 action, UNUSED u32
break;
case ACT_HOLD_WALKING:
- if (0.0f <= forwardVel && forwardVel < mag / 2.0f) {
+ if (0.0f <= forwardVel && forwardVel < mag / 2.0f)
+ {
m->forwardVel = mag / 2.0f;
}
break;
case ACT_BEGIN_SLIDING:
- if (mario_facing_downhill(m, FALSE)) {
+ if (mario_facing_downhill(m, FALSE))
+ {
action = ACT_BUTT_SLIDE;
- } else {
+ }
+ else
+ {
action = ACT_STOMACH_SLIDE;
}
break;
case ACT_HOLD_BEGIN_SLIDING:
- if (mario_facing_downhill(m, FALSE)) {
+ if (mario_facing_downhill(m, FALSE))
+ {
action = ACT_HOLD_BUTT_SLIDE;
- } else {
+ }
+ else
+ {
action = ACT_HOLD_STOMACH_SLIDE;
}
break;
@@ -947,8 +1089,10 @@ static u32 set_mario_action_moving(struct MarioState *m, u32 action, UNUSED u32
/**
* Transition for certain submerged actions, which is actually just the metal jump actions.
*/
-static u32 set_mario_action_submerged(struct MarioState *m, u32 action, UNUSED u32 actionArg) {
- if (action == ACT_METAL_WATER_JUMP || action == ACT_HOLD_METAL_WATER_JUMP) {
+static u32 set_mario_action_submerged(struct MarioState *m, u32 action, UNUSED u32 actionArg)
+{
+ if (action == ACT_METAL_WATER_JUMP || action == ACT_HOLD_METAL_WATER_JUMP)
+ {
m->vel[1] = 32.0f;
}
@@ -958,8 +1102,10 @@ static u32 set_mario_action_submerged(struct MarioState *m, u32 action, UNUSED u
/**
* Transitions for a variety of cutscene actions.
*/
-static u32 set_mario_action_cutscene(struct MarioState *m, u32 action, UNUSED u32 actionArg) {
- switch (action) {
+static u32 set_mario_action_cutscene(struct MarioState *m, u32 action, UNUSED u32 actionArg)
+{
+ switch (action)
+ {
case ACT_EMERGE_FROM_PIPE:
m->vel[1] = 52.0f;
break;
@@ -985,8 +1131,10 @@ static u32 set_mario_action_cutscene(struct MarioState *m, u32 action, UNUSED u3
* Puts Mario into a given action, putting Mario through the appropriate
* specific function if needed.
*/
-u32 set_mario_action(struct MarioState *m, u32 action, u32 actionArg) {
- switch (action & ACT_GROUP_MASK) {
+u32 set_mario_action(struct MarioState *m, u32 action, u32 actionArg)
+{
+ switch (action & ACT_GROUP_MASK)
+ {
case ACT_GROUP_MOVING:
action = set_mario_action_moving(m, action, actionArg);
break;
@@ -1007,7 +1155,8 @@ u32 set_mario_action(struct MarioState *m, u32 action, u32 actionArg) {
// Resets the sound played flags, meaning Mario can play those sound types again.
m->flags &= ~(MARIO_ACTION_SOUND_PLAYED | MARIO_MARIO_SOUND_PLAYED);
- if (!(m->action & ACT_FLAG_AIR)) {
+ if (!(m->action & ACT_FLAG_AIR))
+ {
m->flags &= ~MARIO_UNKNOWN_18;
}
@@ -1024,22 +1173,34 @@ u32 set_mario_action(struct MarioState *m, u32 action, u32 actionArg) {
/**
* Puts Mario into a specific jumping action from a landing action.
*/
-s32 set_jump_from_landing(struct MarioState *m) {
- if (m->quicksandDepth >= 11.0f) {
- if (m->heldObj == NULL) {
+s32 set_jump_from_landing(struct MarioState *m)
+{
+ if (m->quicksandDepth >= 11.0f)
+ {
+ if (m->heldObj == NULL)
+ {
return set_mario_action(m, ACT_QUICKSAND_JUMP_LAND, 0);
- } else {
+ }
+ else
+ {
return set_mario_action(m, ACT_HOLD_QUICKSAND_JUMP_LAND, 0);
}
}
- if (mario_floor_is_steep(m)) {
+ if (mario_floor_is_steep(m))
+ {
set_steep_jump_action(m);
- } else {
- if ((m->doubleJumpTimer == 0) || (m->squishTimer != 0)) {
+ }
+ else
+ {
+ if (m->doubleJumpTimer == 0 || m->squishTimer != 0)
+ {
set_mario_action(m, ACT_JUMP, 0);
- } else {
- switch (m->prevAction) {
+ }
+ else
+ {
+ switch (m->prevAction)
+ {
case ACT_JUMP_LAND:
set_mario_action(m, ACT_DOUBLE_JUMP, 0);
break;
@@ -1055,11 +1216,16 @@ s32 set_jump_from_landing(struct MarioState *m) {
case ACT_DOUBLE_JUMP_LAND:
// If Mario has a wing cap, he ignores the typical speed
// requirement for a triple jump.
- if (m->flags & MARIO_WING_CAP) {
+ if (m->flags & MARIO_WING_CAP)
+ {
set_mario_action(m, ACT_FLYING_TRIPLE_JUMP, 0);
- } else if (m->forwardVel > 20.0f) {
+ }
+ else if (m->forwardVel > 20.0f)
+ {
set_mario_action(m, ACT_TRIPLE_JUMP, 0);
- } else {
+ }
+ else
+ {
set_mario_action(m, ACT_JUMP, 0);
}
break;
@@ -1080,21 +1246,29 @@ s32 set_jump_from_landing(struct MarioState *m) {
* Puts Mario in a given action, as long as it is not overruled by
* either a quicksand or steep jump.
*/
-s32 set_jumping_action(struct MarioState *m, u32 action, u32 actionArg) {
+s32 set_jumping_action(struct MarioState *m, u32 action, u32 actionArg)
+{
UNUSED u32 currAction = m->action;
- if (m->quicksandDepth >= 11.0f) {
+ if (m->quicksandDepth >= 11.0f)
+ {
// Checks whether Mario is holding an object or not.
- if (m->heldObj == NULL) {
+ if (m->heldObj == NULL)
+ {
return set_mario_action(m, ACT_QUICKSAND_JUMP_LAND, 0);
- } else {
+ }
+ else
+ {
return set_mario_action(m, ACT_HOLD_QUICKSAND_JUMP_LAND, 0);
}
}
- if (mario_floor_is_steep(m)) {
+ if (mario_floor_is_steep(m))
+ {
set_steep_jump_action(m);
- } else {
+ }
+ else
+ {
set_mario_action(m, action, actionArg);
}
@@ -1104,7 +1278,8 @@ s32 set_jumping_action(struct MarioState *m, u32 action, u32 actionArg) {
/**
* Drop anything Mario is holding and set a new action.
*/
-s32 drop_and_set_mario_action(struct MarioState *m, u32 action, u32 actionArg) {
+s32 drop_and_set_mario_action(struct MarioState *m, u32 action, u32 actionArg)
+{
mario_stop_riding_and_holding(m);
return set_mario_action(m, action, actionArg);
@@ -1113,7 +1288,8 @@ s32 drop_and_set_mario_action(struct MarioState *m, u32 action, u32 actionArg) {
/**
* Increment Mario's hurt counter and set a new action.
*/
-s32 hurt_and_set_mario_action(struct MarioState *m, u32 action, u32 actionArg, s16 hurtCounter) {
+s32 hurt_and_set_mario_action(struct MarioState *m, u32 action, u32 actionArg, s16 hurtCounter)
+{
m->hurtCounter = hurtCounter;
return set_mario_action(m, action, actionArg);
@@ -1123,17 +1299,22 @@ s32 hurt_and_set_mario_action(struct MarioState *m, u32 action, u32 actionArg, s
* Checks a variety of inputs for common transitions between many different
* actions. A common variant of the below function.
*/
-s32 check_common_action_exits(struct MarioState *m) {
- if (m->input & INPUT_A_PRESSED) {
+s32 check_common_action_exits(struct MarioState *m)
+{
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_mario_action(m, ACT_JUMP, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->input & INPUT_NONZERO_ANALOG) {
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
return set_mario_action(m, ACT_WALKING, 0);
}
- if (m->input & INPUT_ABOVE_SLIDE) {
+ if (m->input & INPUT_ABOVE_SLIDE)
+ {
return set_mario_action(m, ACT_BEGIN_SLIDING, 0);
}
@@ -1144,17 +1325,22 @@ s32 check_common_action_exits(struct MarioState *m) {
* Checks a variety of inputs for common transitions between many different
* object holding actions. A holding variant of the above function.
*/
-s32 check_common_hold_action_exits(struct MarioState *m) {
- if (m->input & INPUT_A_PRESSED) {
+s32 check_common_hold_action_exits(struct MarioState *m)
+{
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_mario_action(m, ACT_HOLD_JUMP, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return set_mario_action(m, ACT_HOLD_FREEFALL, 0);
}
- if (m->input & INPUT_NONZERO_ANALOG) {
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
return set_mario_action(m, ACT_HOLD_WALKING, 0);
}
- if (m->input & INPUT_ABOVE_SLIDE) {
+ if (m->input & INPUT_ABOVE_SLIDE)
+ {
return set_mario_action(m, ACT_HOLD_BEGIN_SLIDING, 0);
}
@@ -1164,14 +1350,18 @@ s32 check_common_hold_action_exits(struct MarioState *m) {
/**
* Transitions Mario from a submerged action to a walking action.
*/
-s32 transition_submerged_to_walking(struct MarioState *m) {
+s32 transition_submerged_to_walking(struct MarioState *m)
+{
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
vec3s_set(m->angleVel, 0, 0, 0);
- if (m->heldObj == NULL) {
+ if (m->heldObj == NULL)
+ {
return set_mario_action(m, ACT_WALKING, 0);
- } else {
+ }
+ else
+ {
return set_mario_action(m, ACT_HOLD_WALKING, 0);
}
}
@@ -1180,7 +1370,8 @@ s32 transition_submerged_to_walking(struct MarioState *m) {
* This is the transition function typically for entering a submerged action for a
* non-submerged action. This also applies the water surface camera preset.
*/
-s32 set_water_plunge_action(struct MarioState *m) {
+s32 set_water_plunge_action(struct MarioState *m)
+{
m->forwardVel = m->forwardVel / 4.0f;
m->vel[1] = m->vel[1] / 2.0f;
@@ -1190,11 +1381,13 @@ s32 set_water_plunge_action(struct MarioState *m) {
vec3s_set(m->angleVel, 0, 0, 0);
- if (!(m->action & ACT_FLAG_DIVING)) {
+ if (!(m->action & ACT_FLAG_DIVING))
+ {
m->faceAngle[0] = 0;
}
- if (m->area->camera->mode != CAMERA_MODE_WATER_SURFACE) {
+ if (m->area->camera->mode != CAMERA_MODE_WATER_SURFACE)
+ {
set_camera_mode(m->area->camera, CAMERA_MODE_WATER_SURFACE, 1);
}
@@ -1205,29 +1398,37 @@ s32 set_water_plunge_action(struct MarioState *m) {
* These are the scaling values for the x and z axis for Mario
* when he is close to unsquishing.
*/
-u8 sSquishScaleOverTime[16] = { 0x46, 0x32, 0x32, 0x3C, 0x46, 0x50, 0x50, 0x3C,
- 0x28, 0x14, 0x14, 0x1E, 0x32, 0x3C, 0x3C, 0x28 };
+u8 sSquishScaleOverTime[16] = {
+ 0x46, 0x32, 0x32, 0x3C, 0x46, 0x50, 0x50, 0x3C,
+ 0x28, 0x14, 0x14, 0x1E, 0x32, 0x3C, 0x3C, 0x28
+};
/**
* Applies the squish to Mario's model via scaling.
*/
-void squish_mario_model(struct MarioState *m) {
- if (m->squishTimer != 0xFF) {
+void squish_mario_model(struct MarioState *m)
+{
+ if (m->squishTimer != 0xFF)
+ {
// If no longer squished, scale back to default.
- if (m->squishTimer == 0) {
+ if (m->squishTimer == 0)
+ {
vec3f_set(m->marioObj->header.gfx.scale, 1.0f, 1.0f, 1.0f);
}
// If timer is less than 16, rubber-band Mario's size scale up and down.
- else if (m->squishTimer <= 16) {
+ else if (m->squishTimer <= 16)
+ {
m->squishTimer -= 1;
m->marioObj->header.gfx.scale[1] =
- 1.0f - ((sSquishScaleOverTime[15 - m->squishTimer] * 0.6f) / 100.0f);
+ 1.0f - sSquishScaleOverTime[15 - m->squishTimer] * 0.6f / 100.0f;
m->marioObj->header.gfx.scale[0] =
- ((sSquishScaleOverTime[15 - m->squishTimer] * 0.4f) / 100.0f) + 1.0f;
+ sSquishScaleOverTime[15 - m->squishTimer] * 0.4f / 100.0f + 1.0f;
m->marioObj->header.gfx.scale[2] = m->marioObj->header.gfx.scale[0];
- } else {
+ }
+ else
+ {
m->squishTimer -= 1;
vec3f_set(m->marioObj->header.gfx.scale, 1.4f, 0.4f, 1.4f);
@@ -1238,60 +1439,75 @@ void squish_mario_model(struct MarioState *m) {
/**
* Debug function that prints floor normal, velocity, and action information.
*/
-void debug_print_speed_action_normal(struct MarioState *m) {
+void debug_print_speed_action_normal(struct MarioState *m)
+{
f32 steepness;
f32 floor_nY;
- if (gShowDebugText) {
+ if (gShowDebugText)
+ {
steepness = sqrtf(
- ((m->floor->normal.x * m->floor->normal.x) + (m->floor->normal.z * m->floor->normal.z)));
+ m->floor->normal.x * m->floor->normal.x + m->floor->normal.z * m->floor->normal.z);
floor_nY = m->floor->normal.y;
- print_text_fmt_int(210, 88, "ANG %d", (atan2s(floor_nY, steepness) * 180.0f) / 32768.0f);
+ print_text_fmt_int(210, 88, "ANG %d", atan2s(floor_nY, steepness) * 180.0f / 32768.0f);
print_text_fmt_int(210, 72, "SPD %d", m->forwardVel);
// STA short for "status," the official action name via SMS map.
- print_text_fmt_int(210, 56, "STA %x", (m->action & ACT_ID_MASK));
+ print_text_fmt_int(210, 56, "STA %x", m->action & ACT_ID_MASK);
}
}
/**
* Update the button inputs for Mario.
*/
-void update_mario_button_inputs(struct MarioState *m) {
- if (m->controller->buttonPressed & A_BUTTON) {
+void update_mario_button_inputs(struct MarioState *m)
+{
+ if (m->controller->buttonPressed & A_BUTTON)
+ {
m->input |= INPUT_A_PRESSED;
}
- if (m->controller->buttonDown & A_BUTTON) {
+ if (m->controller->buttonDown & A_BUTTON)
+ {
m->input |= INPUT_A_DOWN;
}
// Don't update for these buttons if squished.
- if (m->squishTimer == 0) {
- if (m->controller->buttonPressed & B_BUTTON) {
+ if (m->squishTimer == 0)
+ {
+ if (m->controller->buttonPressed & B_BUTTON)
+ {
m->input |= INPUT_B_PRESSED;
}
- if (m->controller->buttonDown & Z_TRIG) {
+ if (m->controller->buttonDown & Z_TRIG)
+ {
m->input |= INPUT_Z_DOWN;
}
- if (m->controller->buttonPressed & Z_TRIG) {
+ if (m->controller->buttonPressed & Z_TRIG)
+ {
m->input |= INPUT_Z_PRESSED;
}
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
m->framesSinceA = 0;
- } else if (m->framesSinceA < 0xFF) {
+ }
+ else if (m->framesSinceA < 0xFF)
+ {
m->framesSinceA += 1;
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
m->framesSinceB = 0;
- } else if (m->framesSinceB < 0xFF) {
+ }
+ else if (m->framesSinceB < 0xFF)
+ {
m->framesSinceB += 1;
}
}
@@ -1299,20 +1515,27 @@ void update_mario_button_inputs(struct MarioState *m) {
/**
* Updates the joystick intended magnitude.
*/
-void update_mario_joystick_inputs(struct MarioState *m) {
+void update_mario_joystick_inputs(struct MarioState *m)
+{
struct Controller *controller = m->controller;
- f32 mag = ((controller->stickMag / 64.0f) * (controller->stickMag / 64.0f)) * 64.0f;
+ f32 mag = controller->stickMag / 64.0f * (controller->stickMag / 64.0f) * 64.0f;
- if (m->squishTimer == 0) {
+ if (m->squishTimer == 0)
+ {
m->intendedMag = mag / 2.0f;
- } else {
+ }
+ else
+ {
m->intendedMag = mag / 8.0f;
}
- if (m->intendedMag > 0.0f) {
+ if (m->intendedMag > 0.0f)
+ {
m->intendedYaw = atan2s(-controller->stickY, controller->stickX) + m->area->camera->yaw;
m->input |= INPUT_NONZERO_ANALOG;
- } else {
+ }
+ else
+ {
m->intendedYaw = m->faceAngle[1];
}
}
@@ -1320,7 +1543,8 @@ void update_mario_joystick_inputs(struct MarioState *m) {
/**
* Resolves wall collisions, and updates a variety of inputs.
*/
-void update_mario_geometry_inputs(struct MarioState *m) {
+void update_mario_geometry_inputs(struct MarioState *m)
+{
//f32 gasLevel;
f32 ceilToFloorDist;
@@ -1329,15 +1553,17 @@ void update_mario_geometry_inputs(struct MarioState *m) {
m->floorHeight = find_floor(m->pos[0], m->pos[1], m->pos[2], &m->floor);
- if(m->floor != NULL) {
- m->curTerrain = m->floor->terrain;
- }
+ if (m->floor != NULL)
+ {
+ m->curTerrain = m->floor->terrain;
+ }
// If Mario is OOB, move his position to his graphical position (which was not updated)
// and check for the floor there.
// This can cause errant behavior when combined with astral projection,
// since the graphical position was not Mario's previous location.
- if (m->floor == NULL) {
+ if (m->floor == NULL)
+ {
vec3f_copy(m->pos, m->marioObj->header.gfx.pos);
m->floorHeight = find_floor(m->pos[0], m->pos[1], m->pos[2], &m->floor);
}
@@ -1346,36 +1572,44 @@ void update_mario_geometry_inputs(struct MarioState *m) {
//gasLevel = find_poison_gas_level(m->pos[0], m->pos[2]);
//m->waterLevel = find_water_level(m->pos[0], m->pos[2]);
- if (m->floor != NULL) {
+ if (m->floor != NULL)
+ {
m->floorAngle = atan2s(m->floor->normal.z, m->floor->normal.x);
m->terrainSoundAddend = mario_get_terrain_sound_addend(m);
- if ((m->pos[1] > m->waterLevel - 40) && mario_floor_is_slippery(m)) {
+ if (m->pos[1] > m->waterLevel - 40 && mario_floor_is_slippery(m))
+ {
m->input |= INPUT_ABOVE_SLIDE;
}
- if ((m->floor->flags & SURFACE_FLAG_DYNAMIC)
- || (m->ceil && m->ceil->flags & SURFACE_FLAG_DYNAMIC)) {
+ if (m->floor->flags & SURFACE_FLAG_DYNAMIC
+ || (m->ceil && m->ceil->flags & SURFACE_FLAG_DYNAMIC))
+ {
ceilToFloorDist = m->ceilHeight - m->floorHeight;
- if ((0.0f <= ceilToFloorDist) && (ceilToFloorDist <= 150.0f)) {
+ if (0.0f <= ceilToFloorDist && ceilToFloorDist <= 150.0f)
+ {
m->input |= INPUT_SQUISHED;
}
}
- if (m->pos[1] > m->floorHeight + 100.0f) {
+ if (m->pos[1] > m->floorHeight + 100.0f)
+ {
m->input |= INPUT_OFF_FLOOR;
}
- if (m->pos[1] < (m->waterLevel - 10)) {
+ if (m->pos[1] < m->waterLevel - 10)
+ {
m->input |= INPUT_IN_WATER;
}
- if (m->pos[1] < (m->gasLevel - 100.0f)) {
+ if (m->pos[1] < m->gasLevel - 100.0f)
+ {
m->input |= INPUT_IN_POISON_GAS;
}
-
- } else {
+ }
+ else
+ {
level_trigger_warp(m, WARP_OP_DEATH);
}
}
@@ -1383,7 +1617,8 @@ void update_mario_geometry_inputs(struct MarioState *m) {
/**
* Handles Mario's input flags as well as a couple timers.
*/
-void update_mario_inputs(struct MarioState *m) {
+void update_mario_inputs(struct MarioState *m)
+{
m->particleFlags = 0;
m->input = 0;
m->collidedObjInteractTypes = m->marioObj->collidedObjInteractTypes;
@@ -1395,20 +1630,26 @@ void update_mario_inputs(struct MarioState *m) {
debug_print_speed_action_normal(m);
- if (gCameraMovementFlags & CAM_MOVE_C_UP_MODE) {
- if (m->action & ACT_FLAG_ALLOW_FIRST_PERSON) {
+ if (gCameraMovementFlags & CAM_MOVE_C_UP_MODE)
+ {
+ if (m->action & ACT_FLAG_ALLOW_FIRST_PERSON)
+ {
m->input |= INPUT_FIRST_PERSON;
- } else {
+ }
+ else
+ {
gCameraMovementFlags &= ~CAM_MOVE_C_UP_MODE;
}
}
- if (!(m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED))) {
+ if (!(m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED)))
+ {
m->input |= INPUT_UNKNOWN_5;
}
if (m->marioObj->oInteractStatus
- & (INT_STATUS_HOOT_GRABBED_BY_MARIO | INT_STATUS_MARIO_UNK1 | INT_STATUS_HIT_BY_SHOCKWAVE)) {
+ & (INT_STATUS_HOOT_GRABBED_BY_MARIO | INT_STATUS_MARIO_UNK1 | INT_STATUS_HIT_BY_SHOCKWAVE))
+ {
m->input |= INPUT_UNKNOWN_10;
}
@@ -1416,11 +1657,13 @@ void update_mario_inputs(struct MarioState *m) {
// perhaps logically grouped here with the timers.
stub_mario_step_1(m);
- if (m->wallKickTimer > 0) {
+ if (m->wallKickTimer > 0)
+ {
m->wallKickTimer--;
}
- if (m->doubleJumpTimer > 0) {
+ if (m->doubleJumpTimer > 0)
+ {
m->doubleJumpTimer--;
}
}
@@ -1428,31 +1671,41 @@ void update_mario_inputs(struct MarioState *m) {
/**
* Set's the camera preset for submerged action behaviors.
*/
-void set_submerged_cam_preset_and_spawn_bubbles(struct MarioState *m) {
+void set_submerged_cam_preset_and_spawn_bubbles(struct MarioState *m)
+{
f32 heightBelowWater;
s16 camPreset;
- if ((m->action & ACT_GROUP_MASK) == ACT_GROUP_SUBMERGED) {
+ if ((m->action & ACT_GROUP_MASK) == ACT_GROUP_SUBMERGED)
+ {
heightBelowWater = (f32)(m->waterLevel - 80) - m->pos[1];
camPreset = m->area->camera->mode;
- if (m->action & ACT_FLAG_METAL_WATER) {
- if (camPreset != CAMERA_MODE_CLOSE) {
+ if (m->action & ACT_FLAG_METAL_WATER)
+ {
+ if (camPreset != CAMERA_MODE_CLOSE)
+ {
set_camera_mode(m->area->camera, CAMERA_MODE_CLOSE, 1);
}
- } else {
- if ((heightBelowWater > 800.0f) && (camPreset != CAMERA_MODE_BEHIND_MARIO)) {
+ }
+ else
+ {
+ if (heightBelowWater > 800.0f && camPreset != CAMERA_MODE_BEHIND_MARIO)
+ {
set_camera_mode(m->area->camera, CAMERA_MODE_BEHIND_MARIO, 1);
}
- if ((heightBelowWater < 400.0f) && (camPreset != CAMERA_MODE_WATER_SURFACE)) {
+ if (heightBelowWater < 400.0f && camPreset != CAMERA_MODE_WATER_SURFACE)
+ {
set_camera_mode(m->area->camera, CAMERA_MODE_WATER_SURFACE, 1);
}
// As long as Mario isn't drowning or at the top
// of the water with his head out, spawn bubbles.
- if (!(m->action & ACT_FLAG_INTANGIBLE)) {
- if ((m->pos[1] < (f32)(m->waterLevel - 160)) || (m->faceAngle[0] < -0x800)) {
+ if (!(m->action & ACT_FLAG_INTANGIBLE))
+ {
+ if (m->pos[1] < (f32)(m->waterLevel - 160) || m->faceAngle[0] < -0x800)
+ {
m->particleFlags |= PARTICLE_BUBBLE;
}
}
@@ -1464,61 +1717,79 @@ void set_submerged_cam_preset_and_spawn_bubbles(struct MarioState *m) {
/**
* Both increments and decrements Mario's HP.
*/
-void update_mario_health(struct MarioState *m) {
+void update_mario_health(struct MarioState *m)
+{
s32 terrainIsSnow;
- if (m->health >= 0x100) {
+ if (m->health >= 0x100)
+ {
// When already healing or hurting Mario, Mario's HP is not changed any more here.
- if (((u32) m->healCounter | (u32) m->hurtCounter) == 0) {
- if ((m->input & INPUT_IN_POISON_GAS) && !(m->action & ACT_FLAG_INTANGIBLE)) {
- if (!(m->flags & MARIO_METAL_CAP) && !gDebugLevelSelect) {
+ if (((u32)m->healCounter | (u32)m->hurtCounter) == 0)
+ {
+ if (m->input & INPUT_IN_POISON_GAS && !(m->action & ACT_FLAG_INTANGIBLE))
+ {
+ if (!(m->flags & MARIO_METAL_CAP) && !gDebugLevelSelect)
+ {
m->health -= 4;
}
- } else {
- if ((m->action & ACT_FLAG_SWIMMING) && !(m->action & ACT_FLAG_INTANGIBLE)) {
+ }
+ else
+ {
+ if (m->action & ACT_FLAG_SWIMMING && !(m->action & ACT_FLAG_INTANGIBLE))
+ {
terrainIsSnow = m->floor != NULL && m->curTerrain == TERRAIN_SNOW;
// When Mario is near the water surface, recover health (unless in snow),
// when in snow terrains lose 3 health.
// If using the debug level select, do not lose any HP to water.
- if ((m->pos[1] >= (m->waterLevel - 140)) && !terrainIsSnow) {
+ if (m->pos[1] >= m->waterLevel - 140 && !terrainIsSnow)
+ {
m->health += 0x1A;
- } else if (!gDebugLevelSelect) {
- m->health -= (terrainIsSnow ? 3 : 1);
+ }
+ else if (!gDebugLevelSelect)
+ {
+ m->health -= terrainIsSnow ? 3 : 1;
}
}
}
}
- if (m->healCounter > 0) {
+ if (m->healCounter > 0)
+ {
m->health += 0x40;
m->healCounter--;
}
- if (m->hurtCounter > 0) {
+ if (m->hurtCounter > 0)
+ {
m->health -= 0x40;
m->hurtCounter--;
}
- if (m->health > 0x880) {
+ if (m->health > 0x880)
+ {
m->health = 0x880;
}
- if (m->health < 0x100) {
+ if (m->health < 0x100)
+ {
m->health = 0xFF;
}
// Play a noise to alert the player when Mario is close to drowning.
- if (((m->action & ACT_GROUP_MASK) == ACT_GROUP_SUBMERGED) && (m->health < 0x300)) {
+ if ((m->action & ACT_GROUP_MASK) == ACT_GROUP_SUBMERGED && m->health < 0x300)
+ {
play_sound(SOUND_MOVING_ALMOST_DROWNING, gDefaultSoundArgs);
-#ifdef VERSION_SH
- if (!gRumblePakTimer) {
+ #ifdef VERSION_SH
+ if (!gRumblePakTimer)
+ {
gRumblePakTimer = 36;
- if (is_rumble_finished_and_queue_empty()) {
+ if (is_rumble_finished_and_queue_empty())
+ {
queue_rumble_data(3, 30);
}
}
} else {
- gRumblePakTimer = 0;
-#endif
+ gRumblePakTimer = 0;
+ #endif
}
}
}
@@ -1526,21 +1797,23 @@ void update_mario_health(struct MarioState *m) {
/**
* Updates some basic info for camera usage. Also update body state action.
*/
-void update_mario_info_for_cam(struct MarioState *m) {
+void update_mario_info_for_cam(struct MarioState *m)
+{
m->marioBodyState->action = m->action;
-// m->statusForCamera->action = m->action;
+ // m->statusForCamera->action = m->action;
-// vec3s_copy(m->statusForCamera->faceAngle, m->faceAngle);
+ // vec3s_copy(m->statusForCamera->faceAngle, m->faceAngle);
-// if (!(m->flags & MARIO_UNKNOWN_25)) {
-// vec3f_copy(m->statusForCamera->pos, m->pos);
-// }
+ // if (!(m->flags & MARIO_UNKNOWN_25)) {
+ // vec3f_copy(m->statusForCamera->pos, m->pos);
+ // }
}
/**
* Resets Mario's model, done every time an action is executed.
*/
-void mario_reset_bodystate(struct MarioState *m) {
+void mario_reset_bodystate(struct MarioState *m)
+{
struct MarioBodyState *bodyState = m->marioBodyState;
bodyState->capState = MARIO_HAS_DEFAULT_CAP_OFF;
@@ -1555,10 +1828,12 @@ void mario_reset_bodystate(struct MarioState *m) {
/**
* Adjusts Mario's graphical height for quicksand.
*/
-void sink_mario_in_quicksand(struct MarioState *m) {
+void sink_mario_in_quicksand(struct MarioState *m)
+{
struct Object *o = m->marioObj;
- if (o->header.gfx.throwMatrix) {
+ if (o->header.gfx.throwMatrix)
+ {
(*o->header.gfx.throwMatrix)[3][1] -= m->quicksandDepth;
}
@@ -1577,37 +1852,45 @@ u64 sCapFlickerFrames = 0x4444449249255555;
/**
* Updates the cap flags mainly based on the cap timer.
*/
-u32 update_and_return_cap_flags(struct MarioState *m) {
+u32 update_and_return_cap_flags(struct MarioState *m)
+{
u32 flags = m->flags;
u32 action;
- if (m->capTimer > 0) {
+ if (m->capTimer > 0)
+ {
action = m->action;
- if ((m->capTimer <= 60)
- || ((action != ACT_READING_AUTOMATIC_DIALOG) && (action != ACT_READING_NPC_DIALOG)
- && (action != ACT_READING_SIGN) && (action != ACT_IN_CANNON))) {
+ if (m->capTimer <= 60
+ || (action != ACT_READING_AUTOMATIC_DIALOG && action != ACT_READING_NPC_DIALOG
+ && action != ACT_READING_SIGN && action != ACT_IN_CANNON))
+ {
m->capTimer -= 1;
}
- if (m->capTimer == 0) {
+ if (m->capTimer == 0)
+ {
stop_cap_music();
m->flags &= ~MARIO_SPECIAL_CAPS;
- if (!(m->flags & MARIO_CAPS)) {
+ if (!(m->flags & MARIO_CAPS))
+ {
m->flags &= ~MARIO_CAP_ON_HEAD;
}
}
- if (m->capTimer == 60) {
+ if (m->capTimer == 60)
+ {
fadeout_cap_music();
}
// This code flickers the cap through a long binary string, increasing in how
// common it flickers near the end.
- if ((m->capTimer < 64) && ((1ULL << m->capTimer) & sCapFlickerFrames)) {
+ if (m->capTimer < 64 && 1ULL << m->capTimer & sCapFlickerFrames)
+ {
flags &= ~MARIO_SPECIAL_CAPS;
- if (!(flags & MARIO_CAPS)) {
+ if (!(flags & MARIO_CAPS))
+ {
flags &= ~MARIO_CAP_ON_HEAD;
}
}
@@ -1619,55 +1902,72 @@ u32 update_and_return_cap_flags(struct MarioState *m) {
/**
* Updates the Mario's cap, rendering, and hitbox.
*/
-void mario_update_hitbox_and_cap_model(struct MarioState *m) {
+void mario_update_hitbox_and_cap_model(struct MarioState *m)
+{
struct MarioBodyState *bodyState = m->marioBodyState;
s32 flags = update_and_return_cap_flags(m);
- if (flags & MARIO_VANISH_CAP) {
+ if (flags & MARIO_VANISH_CAP)
+ {
bodyState->modelState = MODEL_STATE_NOISE_ALPHA;
}
- if (flags & MARIO_METAL_CAP) {
+ if (flags & MARIO_METAL_CAP)
+ {
bodyState->modelState |= MODEL_STATE_METAL;
}
- if (flags & MARIO_METAL_SHOCK) {
+ if (flags & MARIO_METAL_SHOCK)
+ {
bodyState->modelState |= MODEL_STATE_METAL;
}
//! (Pause buffered hitstun) Since the global timer increments while paused,
// this can be paused through to give continual invisibility. This leads to
// no interaction with objects.
- if ((m->invincTimer >= 3) && (gGlobalTimer & 1)) {
+ if (m->invincTimer >= 3 && gGlobalTimer & 1)
+ {
gMarioState->marioObj->header.gfx.node.flags |= GRAPH_RENDER_INVISIBLE;
}
- if (flags & MARIO_CAP_IN_HAND) {
- if (flags & MARIO_WING_CAP) {
+ if (flags & MARIO_CAP_IN_HAND)
+ {
+ if (flags & MARIO_WING_CAP)
+ {
bodyState->handState = MARIO_HAND_HOLDING_WING_CAP;
- } else {
+ }
+ else
+ {
bodyState->handState = MARIO_HAND_HOLDING_CAP;
}
}
- if (flags & MARIO_CAP_ON_HEAD) {
- if (flags & MARIO_WING_CAP) {
+ if (flags & MARIO_CAP_ON_HEAD)
+ {
+ if (flags & MARIO_WING_CAP)
+ {
bodyState->capState = MARIO_HAS_WING_CAP_ON;
- } else {
+ }
+ else
+ {
bodyState->capState = MARIO_HAS_DEFAULT_CAP_ON;
}
}
// Short hitbox for crouching/crawling/etc.
- if (m->action & ACT_FLAG_SHORT_HITBOX) {
+ if (m->action & ACT_FLAG_SHORT_HITBOX)
+ {
m->marioObj->hitboxHeight = 100.0f;
- } else {
+ }
+ else
+ {
m->marioObj->hitboxHeight = 160.0f;
}
- if ((m->flags & MARIO_TELEPORTING) && (m->fadeWarpOpacity != 0xFF)) {
+ if (m->flags & MARIO_TELEPORTING && m->fadeWarpOpacity != 0xFF)
+ {
bodyState->modelState &= ~0xFF;
- bodyState->modelState |= (0x100 | m->fadeWarpOpacity);
+ bodyState->modelState |= 0x100 | m->fadeWarpOpacity;
}
}
@@ -1692,15 +1992,22 @@ void mario_update_hitbox_and_cap_model(struct MarioState *m) {
//}
#ifdef VERSION_SH
-void func_sh_8025574C(void) {
- if (gMarioState->particleFlags & PARTICLE_HORIZONTAL_STAR) {
- queue_rumble_data(5, 80);
- } else if (gMarioState->particleFlags & PARTICLE_VERTICAL_STAR) {
- queue_rumble_data(5, 80);
- } else if (gMarioState->particleFlags & PARTICLE_TRIANGLE) {
+void func_sh_8025574C(void)
+{
+ if (gMarioState->particleFlags & PARTICLE_HORIZONTAL_STAR)
+ {
queue_rumble_data(5, 80);
}
- if(gMarioState->heldObj && gMarioState->heldObj->behavior == segmented_to_virtual(bhvBobomb)) {
+ else if (gMarioState->particleFlags & PARTICLE_VERTICAL_STAR)
+ {
+ queue_rumble_data(5, 80);
+ }
+ else if (gMarioState->particleFlags & PARTICLE_TRIANGLE)
+ {
+ queue_rumble_data(5, 80);
+ }
+ if (gMarioState->heldObj && gMarioState->heldObj->behavior == segmented_to_virtual(bhvBobomb))
+ {
reset_rumble_timers();
}
}
@@ -1709,10 +2016,11 @@ void func_sh_8025574C(void) {
/**
* Main function for executing Mario's behavior.
*/
-s32 execute_mario_action(UNUSED struct Object *o) {
- s32 inLoop = TRUE;
-
- if (gMarioState->action) {
+s32 execute_mario_action(UNUSED struct Object * o)
+{
+ if (gMarioState->action)
+ {
+ s32 inLoop = TRUE;
gMarioState->marioObj->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE;
mario_reset_bodystate(gMarioState);
update_mario_inputs(gMarioState);
@@ -1720,15 +2028,18 @@ s32 execute_mario_action(UNUSED struct Object *o) {
mario_process_interactions(gMarioState);
// If Mario is OOB, stop executing actions.
- if (gMarioState->floor == NULL) {
+ if (gMarioState->floor == NULL)
+ {
return 0;
}
// The function can loop through many action shifts in one frame,
// which can lead to unexpected sub-frame behavior. Could potentially hang
// if a loop of actions were found, but there has not been a situation found.
- while (inLoop) {
- switch (gMarioState->action & ACT_GROUP_MASK) {
+ while (inLoop)
+ {
+ switch (gMarioState->action & ACT_GROUP_MASK)
+ {
case ACT_GROUP_STATIONARY:
inLoop = mario_execute_stationary_action(gMarioState);
break;
@@ -1768,25 +2079,27 @@ s32 execute_mario_action(UNUSED struct Object *o) {
// Both of the wind handling portions play wind audio only in
// non-Japanese releases.
- if (gMarioState->floor->type == SURFACE_HORIZONTAL_WIND) {
- spawn_wind_particles(0, (gMarioState->floor->force << 8));
-#ifndef VERSION_JP
+ if (gMarioState->floor->type == SURFACE_HORIZONTAL_WIND)
+ {
+ spawn_wind_particles(0, gMarioState->floor->force << 8);
+ #ifndef VERSION_JP
play_sound(SOUND_ENV_WIND2, gMarioState->marioObj->header.gfx.cameraToObject);
-#endif
+ #endif
}
- if (gMarioState->floor->type == SURFACE_VERTICAL_WIND) {
+ if (gMarioState->floor->type == SURFACE_VERTICAL_WIND)
+ {
spawn_wind_particles(1, 0);
-#ifndef VERSION_JP
+ #ifndef VERSION_JP
play_sound(SOUND_ENV_WIND2, gMarioState->marioObj->header.gfx.cameraToObject);
-#endif
+ #endif
}
play_infinite_stairs_music();
gMarioState->marioObj->oInteractStatus = 0;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
func_sh_8025574C();
-#endif
+ #endif
return gMarioState->particleFlags;
}
@@ -1798,7 +2111,8 @@ s32 execute_mario_action(UNUSED struct Object *o) {
* INITIALIZATION *
**************************************************/
-int init_mario(void) {
+int init_mario(void)
+{
//Vec3s capPos;
//struct Object *capObject;
@@ -1810,10 +2124,13 @@ int init_mario(void) {
if (save_file_get_flags()
& (SAVE_FLAG_CAP_ON_GROUND | SAVE_FLAG_CAP_ON_KLEPTO | SAVE_FLAG_CAP_ON_UKIKI
- | SAVE_FLAG_CAP_ON_MR_BLIZZARD)) {
+ | SAVE_FLAG_CAP_ON_MR_BLIZZARD))
+ {
gMarioState->flags = 0;
- } else {
- gMarioState->flags = (MARIO_NORMAL_CAP | MARIO_CAP_ON_HEAD);
+ }
+ else
+ {
+ gMarioState->flags = MARIO_NORMAL_CAP | MARIO_CAP_ON_HEAD;
}
gMarioState->forwardVel = 0.0f;
@@ -1830,9 +2147,9 @@ int init_mario(void) {
gMarioState->usedObj = NULL;
gMarioState->waterLevel =
- find_water_level(gMarioSpawnInfo->startPos[0], gMarioSpawnInfo->startPos[2]);
+ find_water_level(gMarioSpawnInfo->startPos[0], gMarioSpawnInfo->startPos[2]);
gMarioState->gasLevel =
- find_poison_gas_level(gMarioSpawnInfo->startPos[0], gMarioSpawnInfo->startPos[2]);
+ find_poison_gas_level(gMarioSpawnInfo->startPos[0], gMarioSpawnInfo->startPos[2]);
gMarioState->area = gCurrentArea;
gMarioState->marioObj = gMarioObject;
@@ -1844,20 +2161,22 @@ int init_mario(void) {
vec3f_set(gMarioState->vel, 0, 0, 0);
gMarioState->floorHeight =
- find_floor(gMarioState->pos[0], gMarioState->pos[1], gMarioState->pos[2], &gMarioState->floor);
+ find_floor(gMarioState->pos[0], gMarioState->pos[1], gMarioState->pos[2], &gMarioState->floor);
- if (gMarioState->floor != NULL) {
+ if (gMarioState->floor != NULL)
+ {
gMarioState->curTerrain = gMarioState->floor->terrain;
}
- if (gMarioState->pos[1] < gMarioState->floorHeight) {
+ if (gMarioState->pos[1] < gMarioState->floorHeight)
+ {
gMarioState->pos[1] = gMarioState->floorHeight;
}
gMarioState->marioObj->header.gfx.pos[1] = gMarioState->pos[1];
gMarioState->action =
- (gMarioState->pos[1] <= (gMarioState->waterLevel - 100)) ? ACT_WATER_IDLE : ACT_IDLE;
+ gMarioState->pos[1] <= gMarioState->waterLevel - 100 ? ACT_WATER_IDLE : ACT_IDLE;
mario_reset_bodystate(gMarioState);
update_mario_info_for_cam(gMarioState);
@@ -1874,8 +2193,9 @@ int init_mario(void) {
vec3f_copy(gMarioState->marioObj->header.gfx.pos, gMarioState->pos);
vec3s_set(gMarioState->marioObj->header.gfx.angle, 0, gMarioState->faceAngle[1], 0);
-#ifdef TODO_LATER
- if (save_file_get_cap_pos(capPos)) {
+ #ifdef TODO_LATER
+ if (save_file_get_cap_pos(capPos))
+ {
capObject = spawn_object(gMarioState->marioObj, MODEL_MARIOS_CAP, bhvNormalCap);
capObject->oPosX = capPos[0];
@@ -1886,24 +2206,25 @@ int init_mario(void) {
capObject->oMoveAngleYaw = 0;
}
-#endif
+ #endif
return gMarioState->floor != NULL ? 0 : -1;
}
-void init_mario_from_save_file(void) {
+void init_mario_from_save_file(void)
+{
gMarioState->unk00 = 0;
gMarioState->flags = 0;
gMarioState->action = 0;
gMarioState->spawnInfo = gMarioSpawnInfo;
-// gMarioState->statusForCamera = &gPlayerCameraState;
+ // gMarioState->statusForCamera = &gPlayerCameraState;
gMarioState->marioBodyState = &g_state->mgBodyStates[0];
gMarioState->controller = &gController;
gMarioState->animation = &D_80339D10;
gMarioState->numCoins = 0;
gMarioState->numStars =
- save_file_get_total_star_count(gCurrSaveFileNum - 1, COURSE_MIN - 1, COURSE_MAX - 1);
+ save_file_get_total_star_count(gCurrSaveFileNum - 1, COURSE_MIN - 1, COURSE_MAX - 1);
gMarioState->numKeys = 0;
gMarioState->numLives = 4;
@@ -1912,6 +2233,6 @@ void init_mario_from_save_file(void) {
gMarioState->prevNumStarsForDialog = gMarioState->numStars;
gMarioState->unkB0 = 0xBD;
-// gHudDisplay.coins = 0;
-// gHudDisplay.wedges = 8;
+ // gHudDisplay.coins = 0;
+ // gHudDisplay.wedges = 8;
}
diff --git a/src/decomp/game/mario.h b/src/decomp/game/mario.h
index b8dbf5c..198af44 100644
--- a/src/decomp/game/mario.h
+++ b/src/decomp/game/mario.h
@@ -7,48 +7,91 @@
#include "../include/types.h"
s32 is_anim_at_end(struct MarioState *m);
+
s32 is_anim_past_end(struct MarioState *m);
+
s16 set_mario_animation(struct MarioState *m, s32 targetAnimID);
+
s16 set_mario_anim_with_accel(struct MarioState *m, s32 targetAnimID, s32 accel);
+
void set_anim_to_frame(struct MarioState *m, s16 animFrame);
+
s32 is_anim_past_frame(struct MarioState *m, s16 animFrame);
+
s16 find_mario_anim_flags_and_translation(struct Object *o, s32 yaw, Vec3s translation);
+
void update_mario_pos_for_anim(struct MarioState *m);
+
s16 return_mario_anim_y_translation(struct MarioState *m);
+
void play_sound_if_no_flag(struct MarioState *m, u32 soundBits, u32 flags);
+
void play_mario_jump_sound(struct MarioState *m);
+
void adjust_sound_for_speed(struct MarioState *m);
+
void play_sound_and_spawn_particles(struct MarioState *m, u32 soundBits, u32 waveParticleType);
+
void play_mario_action_sound(struct MarioState *m, u32 soundBits, u32 waveParticleType);
+
void play_mario_landing_sound(struct MarioState *m, u32 soundBits);
+
void play_mario_landing_sound_once(struct MarioState *m, u32 soundBits);
+
void play_mario_heavy_landing_sound(struct MarioState *m, u32 soundBits);
+
void play_mario_heavy_landing_sound_once(struct MarioState *m, u32 soundBits);
+
void play_mario_sound(struct MarioState *m, s32 primarySoundBits, s32 scondarySoundBits);
+
void mario_set_forward_vel(struct MarioState *m, f32 speed);
+
s32 mario_get_floor_class(struct MarioState *m);
+
u32 mario_get_terrain_sound_addend(struct MarioState *m);
+
struct SM64SurfaceCollisionData *resolve_and_return_wall_collisions(Vec3f pos, f32 offset, f32 radius);
+
f32 vec3f_find_ceil(Vec3f pos, f32 height, struct SM64SurfaceCollisionData **ceil);
+
s32 mario_facing_downhill(struct MarioState *m, s32 turnYaw);
+
u32 mario_floor_is_slippery(struct MarioState *m);
+
s32 mario_floor_is_slope(struct MarioState *m);
+
s32 mario_floor_is_steep(struct MarioState *m);
+
f32 find_floor_height_relative_polar(struct MarioState *m, s16 angleFromMario, f32 distFromMario);
+
s16 find_floor_slope(struct MarioState *m, s16 yawOffset);
+
void update_mario_sound_and_camera(struct MarioState *m);
+
void set_steep_jump_action(struct MarioState *m);
+
u32 set_mario_action(struct MarioState *, u32 action, u32 actionArg);
+
s32 set_jump_from_landing(struct MarioState *m);
+
s32 set_jumping_action(struct MarioState *m, u32 action, u32 actionArg);
+
s32 drop_and_set_mario_action(struct MarioState *m, u32 action, u32 actionArg);
+
s32 hurt_and_set_mario_action(struct MarioState *m, u32 action, u32 actionArg, s16 hurtCounter);
+
s32 check_common_action_exits(struct MarioState *m);
+
s32 check_common_hold_action_exits(struct MarioState *m);
+
s32 transition_submerged_to_walking(struct MarioState *m);
+
s32 set_water_plunge_action(struct MarioState *m);
+
s32 execute_mario_action(UNUSED struct Object *o);
+
int init_mario(void);
+
void init_mario_from_save_file(void);
#endif // MARIO_H
diff --git a/src/decomp/game/mario_actions_airborne.c b/src/decomp/game/mario_actions_airborne.c
index 804ac5a..fb2040e 100644
--- a/src/decomp/game/mario_actions_airborne.c
+++ b/src/decomp/game/mario_actions_airborne.c
@@ -20,18 +20,23 @@
#include "../include/object_fields.h"
#include "../include/mario_geo_switch_case_ids.h"
-void play_flip_sounds(struct MarioState *m, s16 frame1, s16 frame2, s16 frame3) {
+void play_flip_sounds(struct MarioState *m, s16 frame1, s16 frame2, s16 frame3)
+{
s32 animFrame = m->marioObj->header.gfx.animInfo.animFrame;
- if (animFrame == frame1 || animFrame == frame2 || animFrame == frame3) {
+ if (animFrame == frame1 || animFrame == frame2 || animFrame == frame3)
+ {
play_sound(SOUND_ACTION_SPIN, m->marioObj->header.gfx.cameraToObject);
}
}
-void play_far_fall_sound(struct MarioState *m) {
+void play_far_fall_sound(struct MarioState *m)
+{
u32 action = m->action;
if (!(action & ACT_FLAG_INVULNERABLE) && action != ACT_TWIRLING && action != ACT_FLYING
- && !(m->flags & MARIO_UNKNOWN_18)) {
- if (m->peakHeight - m->pos[1] > 1150.0f) {
+ && !(m->flags & MARIO_UNKNOWN_18))
+ {
+ if (m->peakHeight - m->pos[1] > 1150.0f)
+ {
play_sound(SOUND_MARIO_WAAAOOOW, m->marioObj->header.gfx.cameraToObject);
m->flags |= MARIO_UNKNOWN_18;
}
@@ -39,24 +44,31 @@ void play_far_fall_sound(struct MarioState *m) {
}
#ifndef VERSION_JP
-void play_knockback_sound(struct MarioState *m) {
- if (m->actionArg == 0 && (m->forwardVel <= -28.0f || m->forwardVel >= 28.0f)) {
+void play_knockback_sound(struct MarioState *m)
+{
+ if (m->actionArg == 0 && (m->forwardVel <= -28.0f || m->forwardVel >= 28.0f))
+ {
play_sound_if_no_flag(m, SOUND_MARIO_DOH, MARIO_MARIO_SOUND_PLAYED);
- } else {
+ }
+ else
+ {
play_sound_if_no_flag(m, SOUND_MARIO_UH, MARIO_MARIO_SOUND_PLAYED);
}
}
#endif
-s32 lava_boost_on_wall(struct MarioState *m) {
+s32 lava_boost_on_wall(struct MarioState *m)
+{
m->faceAngle[1] = atan2s(m->wall->normal.z, m->wall->normal.x);
- if (m->forwardVel < 24.0f) {
+ if (m->forwardVel < 24.0f)
+ {
m->forwardVel = 24.0f;
}
- if (!(m->flags & MARIO_METAL_CAP)) {
- m->hurtCounter += (m->flags & MARIO_CAP_ON_HEAD) ? 12 : 18;
+ if (!(m->flags & MARIO_METAL_CAP))
+ {
+ m->hurtCounter += m->flags & MARIO_CAP_ON_HEAD ? 12 : 18;
}
play_sound(SOUND_MARIO_ON_FIRE, m->marioObj->header.gfx.cameraToObject);
@@ -64,40 +76,49 @@ s32 lava_boost_on_wall(struct MarioState *m) {
return drop_and_set_mario_action(m, ACT_LAVA_BOOST, 1);
}
-s32 check_fall_damage(struct MarioState *m, u32 hardFallAction) {
+s32 check_fall_damage(struct MarioState *m, u32 hardFallAction)
+{
f32 fallHeight;
f32 damageHeight;
fallHeight = m->peakHeight - m->pos[1];
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wtype-limits"
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wtype-limits"
//! Never true
- if (m->actionState == ACT_GROUND_POUND) {
+ if (m->actionState == ACT_GROUND_POUND)
+ {
damageHeight = 600.0f;
- } else {
+ }
+ else
+ {
damageHeight = 1150.0f;
}
-#pragma GCC diagnostic pop
+ #pragma GCC diagnostic pop
- if (m->action != ACT_TWIRLING && m->floor->type != SURFACE_BURNING) {
- if (m->vel[1] < -55.0f) {
- if (fallHeight > 3000.0f) {
- m->hurtCounter += (m->flags & MARIO_CAP_ON_HEAD) ? 16 : 24;
-#ifdef VERSION_SH
+ if (m->action != ACT_TWIRLING && m->floor->type != SURFACE_BURNING)
+ {
+ if (m->vel[1] < -55.0f)
+ {
+ if (fallHeight > 3000.0f)
+ {
+ m->hurtCounter += m->flags & MARIO_CAP_ON_HEAD ? 16 : 24;
+ #ifdef VERSION_SH
queue_rumble_data(5, 80);
-#endif
+ #endif
set_camera_shake_from_hit(SHAKE_FALL_DAMAGE);
play_sound(SOUND_MARIO_ATTACKED, m->marioObj->header.gfx.cameraToObject);
return drop_and_set_mario_action(m, hardFallAction, 4);
- } else if (fallHeight > damageHeight && !mario_floor_is_slippery(m)) {
- m->hurtCounter += (m->flags & MARIO_CAP_ON_HEAD) ? 8 : 12;
+ }
+ else if (fallHeight > damageHeight && !mario_floor_is_slippery(m))
+ {
+ m->hurtCounter += m->flags & MARIO_CAP_ON_HEAD ? 8 : 12;
m->squishTimer = 30;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
queue_rumble_data(5, 80);
-#endif
+ #endif
set_camera_shake_from_hit(SHAKE_FALL_DAMAGE);
play_sound(SOUND_MARIO_ATTACKED, m->marioObj->header.gfx.cameraToObject);
}
@@ -107,21 +128,26 @@ s32 check_fall_damage(struct MarioState *m, u32 hardFallAction) {
return FALSE;
}
-s32 check_kick_or_dive_in_air(struct MarioState *m) {
- if (m->input & INPUT_B_PRESSED) {
+s32 check_kick_or_dive_in_air(struct MarioState *m)
+{
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, m->forwardVel > 28.0f ? ACT_DIVE : ACT_JUMP_KICK, 0);
}
return FALSE;
}
-s32 should_get_stuck_in_ground(struct MarioState *m) {
+s32 should_get_stuck_in_ground(struct MarioState *m)
+{
struct SM64SurfaceCollisionData *floor = m->floor;
s32 flags = floor->flags;
s32 type = floor->type;
if (floor != NULL && (m->curTerrain == TERRAIN_SNOW || m->curTerrain == TERRAIN_SAND)
- && type != SURFACE_BURNING && SURFACE_IS_NOT_HARD(type)) {
- if (!(flags & 0x01) && m->peakHeight - m->pos[1] > 1000.0f && floor->normal.y >= 0.8660254f) {
+ && type != SURFACE_BURNING && SURFACE_IS_NOT_HARD(type))
+ {
+ if (!(flags & 0x01) && m->peakHeight - m->pos[1] > 1000.0f && floor->normal.y >= 0.8660254f)
+ {
return TRUE;
}
}
@@ -129,32 +155,36 @@ s32 should_get_stuck_in_ground(struct MarioState *m) {
return FALSE;
}
-s32 check_fall_damage_or_get_stuck(struct MarioState *m, u32 hardFallAction) {
- if (should_get_stuck_in_ground(m)) {
-#ifdef VERSION_JP
+s32 check_fall_damage_or_get_stuck(struct MarioState *m, u32 hardFallAction)
+{
+ if (should_get_stuck_in_ground(m))
+ {
+ #ifdef VERSION_JP
play_sound(SOUND_MARIO_OOOF, m->marioObj->header.gfx.cameraToObject);
-#else
+ #else
play_sound(SOUND_MARIO_OOOF2, m->marioObj->header.gfx.cameraToObject);
-#endif
+ #endif
m->particleFlags |= PARTICLE_MIST_CIRCLE;
drop_and_set_mario_action(m, ACT_FEET_STUCK_IN_GROUND, 0);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
queue_rumble_data(5, 80);
-#endif
+ #endif
return TRUE;
}
return check_fall_damage(m, hardFallAction);
}
-s32 check_horizontal_wind(struct MarioState *m) {
+s32 check_horizontal_wind(struct MarioState *m)
+{
struct SM64SurfaceCollisionData *floor;
f32 speed;
s16 pushAngle;
floor = m->floor;
- if (floor->type == SURFACE_HORIZONTAL_WIND) {
+ if (floor->type == SURFACE_HORIZONTAL_WIND)
+ {
pushAngle = floor->force << 8;
m->slideVelX += 1.2f * sins(pushAngle);
@@ -162,11 +192,14 @@ s32 check_horizontal_wind(struct MarioState *m) {
speed = sqrtf(m->slideVelX * m->slideVelX + m->slideVelZ * m->slideVelZ);
- if (speed > 48.0f) {
+ if (speed > 48.0f)
+ {
m->slideVelX = m->slideVelX * 48.0f / speed;
m->slideVelZ = m->slideVelZ * 48.0f / speed;
speed = 32.0f; //! This was meant to be 48?
- } else if (speed > 32.0f) {
+ }
+ else if (speed > 32.0f)
+ {
speed = 32.0f;
}
@@ -175,37 +208,38 @@ s32 check_horizontal_wind(struct MarioState *m) {
m->slideYaw = atan2s(m->slideVelZ, m->slideVelX);
m->forwardVel = speed * coss(m->faceAngle[1] - m->slideYaw);
-#ifdef VERSION_JP
+ #ifdef VERSION_JP
play_sound(SOUND_ENV_WIND2, m->marioObj->header.gfx.cameraToObject);
-#endif
+ #endif
return TRUE;
}
return FALSE;
}
-void update_air_with_turn(struct MarioState *m) {
- f32 dragThreshold;
- s16 intendedDYaw;
- f32 intendedMag;
-
- if (!check_horizontal_wind(m)) {
- dragThreshold = m->action == ACT_LONG_JUMP ? 48.0f : 32.0f;
+void update_air_with_turn(struct MarioState *m)
+{
+ if (!check_horizontal_wind(m))
+ {
+ f32 dragThreshold = m->action == ACT_LONG_JUMP ? 48.0f : 32.0f;
m->forwardVel = approach_f32(m->forwardVel, 0.0f, 0.35f, 0.35f);
- if (m->input & INPUT_NONZERO_ANALOG) {
- intendedDYaw = m->intendedYaw - m->faceAngle[1];
- intendedMag = m->intendedMag / 32.0f;
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
+ s16 intendedDYaw = m->intendedYaw - m->faceAngle[1];
+ f32 intendedMag = m->intendedMag / 32.0f;
m->forwardVel += 1.5f * coss(intendedDYaw) * intendedMag;
m->faceAngle[1] += 512.0f * sins(intendedDYaw) * intendedMag;
}
//! Uncapped air speed. Net positive when moving forward.
- if (m->forwardVel > dragThreshold) {
+ if (m->forwardVel > dragThreshold)
+ {
m->forwardVel -= 1.0f;
}
- if (m->forwardVel < -16.0f) {
+ if (m->forwardVel < -16.0f)
+ {
m->forwardVel += 2.0f;
}
@@ -214,17 +248,20 @@ void update_air_with_turn(struct MarioState *m) {
}
}
-void update_air_without_turn(struct MarioState *m) {
+void update_air_without_turn(struct MarioState *m)
+{
f32 sidewaysSpeed = 0.0f;
f32 dragThreshold;
s16 intendedDYaw;
f32 intendedMag;
- if (!check_horizontal_wind(m)) {
+ if (!check_horizontal_wind(m))
+ {
dragThreshold = m->action == ACT_LONG_JUMP ? 48.0f : 32.0f;
m->forwardVel = approach_f32(m->forwardVel, 0.0f, 0.35f, 0.35f);
- if (m->input & INPUT_NONZERO_ANALOG) {
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
intendedDYaw = m->intendedYaw - m->faceAngle[1];
intendedMag = m->intendedMag / 32.0f;
@@ -233,10 +270,12 @@ void update_air_without_turn(struct MarioState *m) {
}
//! Uncapped air speed. Net positive when moving forward.
- if (m->forwardVel > dragThreshold) {
+ if (m->forwardVel > dragThreshold)
+ {
m->forwardVel -= 1.0f;
}
- if (m->forwardVel < -16.0f) {
+ if (m->forwardVel < -16.0f)
+ {
m->forwardVel += 2.0f;
}
@@ -251,23 +290,27 @@ void update_air_without_turn(struct MarioState *m) {
}
}
-void update_lava_boost_or_twirling(struct MarioState *m) {
+void update_lava_boost_or_twirling(struct MarioState *m)
+{
s16 intendedDYaw;
f32 intendedMag;
- if (m->input & INPUT_NONZERO_ANALOG) {
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
intendedDYaw = m->intendedYaw - m->faceAngle[1];
intendedMag = m->intendedMag / 32.0f;
m->forwardVel += coss(intendedDYaw) * intendedMag;
m->faceAngle[1] += sins(intendedDYaw) * intendedMag * 1024.0f;
- if (m->forwardVel < 0.0f) {
+ if (m->forwardVel < 0.0f)
+ {
m->faceAngle[1] += 0x8000;
m->forwardVel *= -1.0f;
}
- if (m->forwardVel > 32.0f) {
+ if (m->forwardVel > 32.0f)
+ {
m->forwardVel -= 2.0f;
}
}
@@ -276,28 +319,42 @@ void update_lava_boost_or_twirling(struct MarioState *m) {
m->vel[2] = m->slideVelZ = m->forwardVel * coss(m->faceAngle[1]);
}
-void update_flying_yaw(struct MarioState *m) {
+void update_flying_yaw(struct MarioState *m)
+{
s16 targetYawVel = (s16)(m->controller->stickX * (m->forwardVel / 4.0f));
- if (targetYawVel > 0) {
- if (m->angleVel[1] < 0) {
+ if (targetYawVel > 0)
+ {
+ if (m->angleVel[1] < 0)
+ {
m->angleVel[1] += 0x40;
- if (m->angleVel[1] > 0x10) {
+ if (m->angleVel[1] > 0x10)
+ {
m->angleVel[1] = 0x10;
}
- } else {
+ }
+ else
+ {
m->angleVel[1] = approach_s32(m->angleVel[1], targetYawVel, 0x10, 0x20);
}
- } else if (targetYawVel < 0) {
- if (m->angleVel[1] > 0) {
+ }
+ else if (targetYawVel < 0)
+ {
+ if (m->angleVel[1] > 0)
+ {
m->angleVel[1] -= 0x40;
- if (m->angleVel[1] < -0x10) {
+ if (m->angleVel[1] < -0x10)
+ {
m->angleVel[1] = -0x10;
}
- } else {
+ }
+ else
+ {
m->angleVel[1] = approach_s32(m->angleVel[1], targetYawVel, 0x20, 0x10);
}
- } else {
+ }
+ else
+ {
m->angleVel[1] = approach_s32(m->angleVel[1], 0, 0x40, 0x40);
}
@@ -305,59 +362,82 @@ void update_flying_yaw(struct MarioState *m) {
m->faceAngle[2] = 20 * -m->angleVel[1];
}
-void update_flying_pitch(struct MarioState *m) {
+void update_flying_pitch(struct MarioState *m)
+{
s16 targetPitchVel = (s16)(m->controller->stickY * (m->forwardVel / 5.0f));
- if (targetPitchVel > 0) {
- if (m->angleVel[0] < 0) {
+ if (targetPitchVel > 0)
+ {
+ if (m->angleVel[0] < 0)
+ {
m->angleVel[0] += 0x40;
- if (m->angleVel[0] > 0x20) {
+ if (m->angleVel[0] > 0x20)
+ {
m->angleVel[0] = 0x20;
}
- } else {
+ }
+ else
+ {
m->angleVel[0] = approach_s32(m->angleVel[0], targetPitchVel, 0x20, 0x40);
}
- } else if (targetPitchVel < 0) {
- if (m->angleVel[0] > 0) {
+ }
+ else if (targetPitchVel < 0)
+ {
+ if (m->angleVel[0] > 0)
+ {
m->angleVel[0] -= 0x40;
- if (m->angleVel[0] < -0x20) {
+ if (m->angleVel[0] < -0x20)
+ {
m->angleVel[0] = -0x20;
}
- } else {
+ }
+ else
+ {
m->angleVel[0] = approach_s32(m->angleVel[0], targetPitchVel, 0x40, 0x20);
}
- } else {
+ }
+ else
+ {
m->angleVel[0] = approach_s32(m->angleVel[0], 0, 0x40, 0x40);
}
}
-void update_flying(struct MarioState *m) {
+void update_flying(struct MarioState *m)
+{
UNUSED u32 unused;
update_flying_pitch(m);
update_flying_yaw(m);
- m->forwardVel -= 2.0f * ((f32) m->faceAngle[0] / 0x4000) + 0.1f;
+ m->forwardVel -= 2.0f * ((f32)m->faceAngle[0] / 0x4000) + 0.1f;
m->forwardVel -= 0.5f * (1.0f - coss(m->angleVel[1]));
- if (m->forwardVel < 0.0f) {
+ if (m->forwardVel < 0.0f)
+ {
m->forwardVel = 0.0f;
}
- if (m->forwardVel > 16.0f) {
+ if (m->forwardVel > 16.0f)
+ {
m->faceAngle[0] += (m->forwardVel - 32.0f) * 6.0f;
- } else if (m->forwardVel > 4.0f) {
+ }
+ else if (m->forwardVel > 4.0f)
+ {
m->faceAngle[0] += (m->forwardVel - 32.0f) * 10.0f;
- } else {
+ }
+ else
+ {
m->faceAngle[0] -= 0x400;
}
m->faceAngle[0] += m->angleVel[0];
- if (m->faceAngle[0] > 0x2AAA) {
+ if (m->faceAngle[0] > 0x2AAA)
+ {
m->faceAngle[0] = 0x2AAA;
}
- if (m->faceAngle[0] < -0x2AAA) {
+ if (m->faceAngle[0] < -0x2AAA)
+ {
m->faceAngle[0] = -0x2AAA;
}
@@ -369,19 +449,22 @@ void update_flying(struct MarioState *m) {
m->slideVelZ = m->vel[2];
}
-u32 common_air_action_step(struct MarioState *m, u32 landAction, s32 animation, u32 stepArg) {
+u32 common_air_action_step(struct MarioState *m, u32 landAction, s32 animation, u32 stepArg)
+{
u32 stepResult;
update_air_without_turn(m);
stepResult = perform_air_step(m, stepArg);
- switch (stepResult) {
+ switch (stepResult)
+ {
case AIR_STEP_NONE:
set_mario_animation(m, animation);
break;
case AIR_STEP_LANDED:
- if (!check_fall_damage_or_get_stuck(m, ACT_HARD_BACKWARD_GROUND_KB)) {
+ if (!check_fall_damage_or_get_stuck(m, ACT_HARD_BACKWARD_GROUND_KB))
+ {
set_mario_action(m, landAction, 0);
}
break;
@@ -389,17 +472,22 @@ u32 common_air_action_step(struct MarioState *m, u32 landAction, s32 animation,
case AIR_STEP_HIT_WALL:
set_mario_animation(m, animation);
- if (m->forwardVel > 16.0f) {
-#ifdef VERSION_SH
+ if (m->forwardVel > 16.0f)
+ {
+ #ifdef VERSION_SH
queue_rumble_data(5, 40);
-#endif
+ #endif
mario_bonk_reflection(m, FALSE);
m->faceAngle[1] += 0x8000;
- if (m->wall != NULL) {
+ if (m->wall != NULL)
+ {
set_mario_action(m, ACT_AIR_HIT_WALL, 0);
- } else {
- if (m->vel[1] > 0.0f) {
+ }
+ else
+ {
+ if (m->vel[1] > 0.0f)
+ {
m->vel[1] = 0.0f;
}
@@ -412,17 +500,23 @@ u32 common_air_action_step(struct MarioState *m, u32 landAction, s32 animation,
// wall collision, or by rising into the top of a wall such
// that the final quarter step detects a ledge, but you are
// not able to ledge grab it.
- if (m->forwardVel >= 38.0f) {
+ if (m->forwardVel >= 38.0f)
+ {
m->particleFlags |= PARTICLE_VERTICAL_STAR;
set_mario_action(m, ACT_BACKWARD_AIR_KB, 0);
- } else {
- if (m->forwardVel > 8.0f) {
+ }
+ else
+ {
+ if (m->forwardVel > 8.0f)
+ {
mario_set_forward_vel(m, -8.0f);
}
return set_mario_action(m, ACT_SOFT_BONK, 0);
}
}
- } else {
+ }
+ else
+ {
mario_set_forward_vel(m, 0.0f);
}
break;
@@ -444,12 +538,15 @@ u32 common_air_action_step(struct MarioState *m, u32 landAction, s32 animation,
return stepResult;
}
-s32 act_jump(struct MarioState *m) {
- if (check_kick_or_dive_in_air(m)) {
+s32 act_jump(struct MarioState *m)
+{
+ if (check_kick_or_dive_in_air(m))
+ {
return TRUE;
}
- if (m->input & INPUT_Z_PRESSED) {
+ if (m->input & INPUT_Z_PRESSED)
+ {
return set_mario_action(m, ACT_GROUND_POUND, 0);
}
@@ -459,16 +556,19 @@ s32 act_jump(struct MarioState *m) {
return FALSE;
}
-s32 act_double_jump(struct MarioState *m) {
- s32 animation = (m->vel[1] >= 0.0f)
- ? MARIO_ANIM_DOUBLE_JUMP_RISE
- : MARIO_ANIM_DOUBLE_JUMP_FALL;
+s32 act_double_jump(struct MarioState *m)
+{
+ s32 animation = m->vel[1] >= 0.0f
+ ? MARIO_ANIM_DOUBLE_JUMP_RISE
+ : MARIO_ANIM_DOUBLE_JUMP_FALL;
- if (check_kick_or_dive_in_air(m)) {
+ if (check_kick_or_dive_in_air(m))
+ {
return TRUE;
}
- if (m->input & INPUT_Z_PRESSED) {
+ if (m->input & INPUT_Z_PRESSED)
+ {
return set_mario_action(m, ACT_GROUND_POUND, 0);
}
@@ -478,63 +578,75 @@ s32 act_double_jump(struct MarioState *m) {
return FALSE;
}
-s32 act_triple_jump(struct MarioState *m) {
- if (gSpecialTripleJump) {
+s32 act_triple_jump(struct MarioState *m)
+{
+ if (gSpecialTripleJump)
+ {
return set_mario_action(m, ACT_SPECIAL_TRIPLE_JUMP, 0);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_DIVE, 0);
}
- if (m->input & INPUT_Z_PRESSED) {
+ if (m->input & INPUT_Z_PRESSED)
+ {
return set_mario_action(m, ACT_GROUND_POUND, 0);
}
-#ifndef VERSION_JP
+ #ifndef VERSION_JP
play_mario_sound(m, SOUND_ACTION_TERRAIN_JUMP, 0);
-#else
+ #else
play_mario_sound(m, SOUND_ACTION_TERRAIN_JUMP, SOUND_MARIO_YAHOO);
-#endif
+ #endif
common_air_action_step(m, ACT_TRIPLE_JUMP_LAND, MARIO_ANIM_TRIPLE_JUMP, 0);
-#ifdef VERSION_SH
- if (m->action == ACT_TRIPLE_JUMP_LAND) {
+ #ifdef VERSION_SH
+ if (m->action == ACT_TRIPLE_JUMP_LAND)
+ {
queue_rumble_data(5, 40);
}
-#endif
+ #endif
play_flip_sounds(m, 2, 8, 20);
return FALSE;
}
-s32 act_backflip(struct MarioState *m) {
- if (m->input & INPUT_Z_PRESSED) {
+s32 act_backflip(struct MarioState *m)
+{
+ if (m->input & INPUT_Z_PRESSED)
+ {
return set_mario_action(m, ACT_GROUND_POUND, 0);
}
play_mario_sound(m, SOUND_ACTION_TERRAIN_JUMP, SOUND_MARIO_YAH_WAH_HOO);
common_air_action_step(m, ACT_BACKFLIP_LAND, MARIO_ANIM_BACKFLIP, 0);
-#ifdef VERSION_SH
- if (m->action == ACT_BACKFLIP_LAND) {
+ #ifdef VERSION_SH
+ if (m->action == ACT_BACKFLIP_LAND)
+ {
queue_rumble_data(5, 40);
}
-#endif
+ #endif
play_flip_sounds(m, 2, 3, 17);
return FALSE;
}
-s32 act_freefall(struct MarioState *m) {
+s32 act_freefall(struct MarioState *m)
+{
s32 animation;
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_DIVE, 0);
}
- if (m->input & INPUT_Z_PRESSED) {
+ if (m->input & INPUT_Z_PRESSED)
+ {
return set_mario_action(m, ACT_GROUND_POUND, 0);
}
- switch (m->actionArg) {
+ switch (m->actionArg)
+ {
case 0:
animation = MARIO_ANIM_GENERAL_FALL;
break;
@@ -550,16 +662,20 @@ s32 act_freefall(struct MarioState *m) {
return FALSE;
}
-s32 act_hold_jump(struct MarioState *m) {
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+s32 act_hold_jump(struct MarioState *m)
+{
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_FREEFALL, 0);
}
- if ((m->input & INPUT_B_PRESSED) && !(m->heldObj->oInteractionSubtype & INT_SUBTYPE_HOLDABLE_NPC)) {
+ if (m->input & INPUT_B_PRESSED && !(m->heldObj->oInteractionSubtype & INT_SUBTYPE_HOLDABLE_NPC))
+ {
return set_mario_action(m, ACT_AIR_THROW, 0);
}
- if (m->input & INPUT_Z_PRESSED) {
+ if (m->input & INPUT_Z_PRESSED)
+ {
return drop_and_set_mario_action(m, ACT_GROUND_POUND, 0);
}
@@ -569,23 +685,30 @@ s32 act_hold_jump(struct MarioState *m) {
return FALSE;
}
-s32 act_hold_freefall(struct MarioState *m) {
+s32 act_hold_freefall(struct MarioState *m)
+{
s32 animation;
- if (m->actionArg == 0) {
+ if (m->actionArg == 0)
+ {
animation = MARIO_ANIM_FALL_WITH_LIGHT_OBJ;
- } else {
+ }
+ else
+ {
animation = MARIO_ANIM_FALL_FROM_SLIDING_WITH_LIGHT_OBJ;
}
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_FREEFALL, 0);
}
- if ((m->input & INPUT_B_PRESSED) && !(m->heldObj->oInteractionSubtype & INT_SUBTYPE_HOLDABLE_NPC)) {
+ if (m->input & INPUT_B_PRESSED && !(m->heldObj->oInteractionSubtype & INT_SUBTYPE_HOLDABLE_NPC))
+ {
return set_mario_action(m, ACT_AIR_THROW, 0);
}
- if (m->input & INPUT_Z_PRESSED) {
+ if (m->input & INPUT_Z_PRESSED)
+ {
return drop_and_set_mario_action(m, ACT_GROUND_POUND, 0);
}
@@ -593,19 +716,23 @@ s32 act_hold_freefall(struct MarioState *m) {
return FALSE;
}
-s32 act_side_flip(struct MarioState *m) {
- if (m->input & INPUT_B_PRESSED) {
+s32 act_side_flip(struct MarioState *m)
+{
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_DIVE, 0);
}
- if (m->input & INPUT_Z_PRESSED) {
+ if (m->input & INPUT_Z_PRESSED)
+ {
return set_mario_action(m, ACT_GROUND_POUND, 0);
}
play_mario_sound(m, SOUND_ACTION_TERRAIN_JUMP, 0);
if (common_air_action_step(m, ACT_SIDE_FLIP_LAND, MARIO_ANIM_SLIDEFLIP, AIR_STEP_CHECK_LEDGE_GRAB)
- != AIR_STEP_GRABBED_LEDGE) {
+ != AIR_STEP_GRABBED_LEDGE)
+ {
m->marioObj->header.gfx.angle[1] += 0x8000;
}
@@ -616,12 +743,15 @@ s32 act_side_flip(struct MarioState *m) {
return FALSE;
}
-s32 act_wall_kick_air(struct MarioState *m) {
- if (m->input & INPUT_B_PRESSED) {
+s32 act_wall_kick_air(struct MarioState *m)
+{
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_DIVE, 0);
}
- if (m->input & INPUT_Z_PRESSED) {
+ if (m->input & INPUT_Z_PRESSED)
+ {
return set_mario_action(m, ACT_GROUND_POUND, 0);
}
@@ -630,37 +760,45 @@ s32 act_wall_kick_air(struct MarioState *m) {
return FALSE;
}
-s32 act_long_jump(struct MarioState *m) {
+s32 act_long_jump(struct MarioState *m)
+{
s32 animation;
- if (!m->marioObj->oMarioLongJumpIsSlow) {
+ if (!m->marioObj->oMarioLongJumpIsSlow)
+ {
animation = MARIO_ANIM_FAST_LONGJUMP;
- } else {
+ }
+ else
+ {
animation = MARIO_ANIM_SLOW_LONGJUMP;
}
play_mario_sound(m, SOUND_ACTION_TERRAIN_JUMP, SOUND_MARIO_YAHOO);
- if (m->floor->type == SURFACE_VERTICAL_WIND && m->actionState == 0) {
+ if (m->floor->type == SURFACE_VERTICAL_WIND && m->actionState == 0)
+ {
play_sound(SOUND_MARIO_HERE_WE_GO, m->marioObj->header.gfx.cameraToObject);
m->actionState = 1;
}
common_air_action_step(m, ACT_LONG_JUMP_LAND, animation, AIR_STEP_CHECK_LEDGE_GRAB);
-#ifdef VERSION_SH
- if (m->action == ACT_LONG_JUMP_LAND) {
+ #ifdef VERSION_SH
+ if (m->action == ACT_LONG_JUMP_LAND)
+ {
queue_rumble_data(5, 40);
}
-#endif
+ #endif
return FALSE;
}
-s32 act_riding_shell_air(struct MarioState *m) {
+s32 act_riding_shell_air(struct MarioState *m)
+{
play_mario_sound(m, SOUND_ACTION_TERRAIN_JUMP, 0);
set_mario_animation(m, MARIO_ANIM_JUMP_RIDING_SHELL);
update_air_without_turn(m);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_LANDED:
set_mario_action(m, ACT_RIDING_SHELL_GROUND, 1);
break;
@@ -678,13 +816,17 @@ s32 act_riding_shell_air(struct MarioState *m) {
return FALSE;
}
-s32 act_twirling(struct MarioState *m) {
+s32 act_twirling(struct MarioState *m)
+{
s16 startTwirlYaw = m->twirlYaw;
s16 yawVelTarget;
- if (m->input & INPUT_A_DOWN) {
+ if (m->input & INPUT_A_DOWN)
+ {
yawVelTarget = 0x2000;
- } else {
+ }
+ else
+ {
yawVelTarget = 0x1800;
}
@@ -692,17 +834,20 @@ s32 act_twirling(struct MarioState *m) {
m->twirlYaw += m->angleVel[1];
set_mario_animation(m, m->actionArg == 0 ? MARIO_ANIM_START_TWIRL : MARIO_ANIM_TWIRL);
- if (is_anim_past_end(m)) {
+ if (is_anim_past_end(m))
+ {
m->actionArg = 1;
}
- if (startTwirlYaw > m->twirlYaw) {
+ if (startTwirlYaw > m->twirlYaw)
+ {
play_sound(SOUND_ACTION_TWIRL, m->marioObj->header.gfx.cameraToObject);
}
update_lava_boost_or_twirling(m);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_LANDED:
set_mario_action(m, ACT_TWIRL_LAND, 0);
break;
@@ -720,29 +865,38 @@ s32 act_twirling(struct MarioState *m) {
return FALSE;
}
-s32 act_dive(struct MarioState *m) {
- if (m->actionArg == 0) {
+s32 act_dive(struct MarioState *m)
+{
+ if (m->actionArg == 0)
+ {
play_mario_sound(m, SOUND_ACTION_THROW, SOUND_MARIO_HOOHOO);
- } else {
+ }
+ else
+ {
play_mario_sound(m, SOUND_ACTION_TERRAIN_JUMP, 0);
}
set_mario_animation(m, MARIO_ANIM_DIVE);
- if (mario_check_object_grab(m)) {
+ if (mario_check_object_grab(m))
+ {
mario_grab_used_object(m);
m->marioBodyState->grabPos = GRAB_POS_LIGHT_OBJ;
- if (m->action != ACT_DIVE) {
+ if (m->action != ACT_DIVE)
+ {
return TRUE;
}
}
update_air_without_turn(m);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_NONE:
- if (m->vel[1] < 0.0f && m->faceAngle[0] > -0x2AAA) {
+ if (m->vel[1] < 0.0f && m->faceAngle[0] > -0x2AAA)
+ {
m->faceAngle[0] -= 0x200;
- if (m->faceAngle[0] < -0x2AAA) {
+ if (m->faceAngle[0] < -0x2AAA)
+ {
m->faceAngle[0] = -0x2AAA;
}
}
@@ -750,21 +904,27 @@ s32 act_dive(struct MarioState *m) {
break;
case AIR_STEP_LANDED:
- if (should_get_stuck_in_ground(m) && m->faceAngle[0] == -0x2AAA) {
-#ifdef VERSION_SH
+ if (should_get_stuck_in_ground(m) && m->faceAngle[0] == -0x2AAA)
+ {
+ #ifdef VERSION_SH
queue_rumble_data(5, 80);
-#endif
-#ifdef VERSION_JP
+ #endif
+ #ifdef VERSION_JP
play_sound(SOUND_MARIO_OOOF, m->marioObj->header.gfx.cameraToObject);
-#else
+ #else
play_sound(SOUND_MARIO_OOOF2, m->marioObj->header.gfx.cameraToObject);
-#endif
+ #endif
m->particleFlags |= PARTICLE_MIST_CIRCLE;
drop_and_set_mario_action(m, ACT_HEAD_STUCK_IN_GROUND, 0);
- } else if (!check_fall_damage(m, ACT_HARD_FORWARD_GROUND_KB)) {
- if (m->heldObj == NULL) {
+ }
+ else if (!check_fall_damage(m, ACT_HARD_FORWARD_GROUND_KB))
+ {
+ if (m->heldObj == NULL)
+ {
set_mario_action(m, ACT_DIVE_SLIDE, 0);
- } else {
+ }
+ else
+ {
set_mario_action(m, ACT_DIVE_PICKING_UP, 0);
}
}
@@ -775,7 +935,8 @@ s32 act_dive(struct MarioState *m) {
mario_bonk_reflection(m, TRUE);
m->faceAngle[0] = 0;
- if (m->vel[1] > 0.0f) {
+ if (m->vel[1] > 0.0f)
+ {
m->vel[1] = 0.0f;
}
@@ -791,8 +952,10 @@ s32 act_dive(struct MarioState *m) {
return FALSE;
}
-s32 act_air_throw(struct MarioState *m) {
- if (++(m->actionTimer) == 4) {
+s32 act_air_throw(struct MarioState *m)
+{
+ if (++m->actionTimer == 4)
+ {
mario_throw_held_object(m);
}
@@ -800,9 +963,11 @@ s32 act_air_throw(struct MarioState *m) {
set_mario_animation(m, MARIO_ANIM_THROW_LIGHT_OBJECT);
update_air_without_turn(m);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_LANDED:
- if (!check_fall_damage_or_get_stuck(m, ACT_HARD_BACKWARD_GROUND_KB)) {
+ if (!check_fall_damage_or_get_stuck(m, ACT_HARD_BACKWARD_GROUND_KB))
+ {
m->action = ACT_AIR_THROW_LAND;
}
break;
@@ -819,15 +984,18 @@ s32 act_air_throw(struct MarioState *m) {
return FALSE;
}
-s32 act_water_jump(struct MarioState *m) {
- if (m->forwardVel < 15.0f) {
+s32 act_water_jump(struct MarioState *m)
+{
+ if (m->forwardVel < 15.0f)
+ {
mario_set_forward_vel(m, 15.0f);
}
play_mario_sound(m, SOUND_ACTION_UNKNOWN432, 0);
set_mario_animation(m, MARIO_ANIM_SINGLE_JUMP);
- switch (perform_air_step(m, AIR_STEP_CHECK_LEDGE_GRAB)) {
+ switch (perform_air_step(m, AIR_STEP_CHECK_LEDGE_GRAB))
+ {
case AIR_STEP_LANDED:
set_mario_action(m, ACT_JUMP_LAND, 0);
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
@@ -838,9 +1006,9 @@ s32 act_water_jump(struct MarioState *m) {
break;
case AIR_STEP_GRABBED_LEDGE:
-#ifndef VERSION_JP
+ #ifndef VERSION_JP
set_mario_animation(m, MARIO_ANIM_IDLE_ON_LEDGE);
-#endif
+ #endif
set_mario_action(m, ACT_LEDGE_GRAB, 0);
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
break;
@@ -853,19 +1021,23 @@ s32 act_water_jump(struct MarioState *m) {
return FALSE;
}
-s32 act_hold_water_jump(struct MarioState *m) {
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+s32 act_hold_water_jump(struct MarioState *m)
+{
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->forwardVel < 15.0f) {
+ if (m->forwardVel < 15.0f)
+ {
mario_set_forward_vel(m, 15.0f);
}
play_mario_sound(m, SOUND_ACTION_UNKNOWN432, 0);
set_mario_animation(m, MARIO_ANIM_JUMP_WITH_LIGHT_OBJ);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_LANDED:
set_mario_action(m, ACT_HOLD_JUMP_LAND, 0);
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
@@ -883,17 +1055,21 @@ s32 act_hold_water_jump(struct MarioState *m) {
return FALSE;
}
-s32 act_steep_jump(struct MarioState *m) {
- if (m->input & INPUT_B_PRESSED) {
+s32 act_steep_jump(struct MarioState *m)
+{
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_DIVE, 0);
}
play_mario_sound(m, SOUND_ACTION_TERRAIN_JUMP, 0);
mario_set_forward_vel(m, 0.98f * m->forwardVel);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_LANDED:
- if (!check_fall_damage_or_get_stuck(m, ACT_HARD_BACKWARD_GROUND_KB)) {
+ if (!check_fall_damage_or_get_stuck(m, ACT_HARD_BACKWARD_GROUND_KB))
+ {
m->faceAngle[0] = 0;
set_mario_action(m, m->forwardVel < 0.0f ? ACT_BEGIN_SLIDING : ACT_JUMP_LAND, 0);
}
@@ -913,16 +1089,20 @@ s32 act_steep_jump(struct MarioState *m) {
return FALSE;
}
-s32 act_ground_pound(struct MarioState *m) {
+s32 act_ground_pound(struct MarioState *m)
+{
u32 stepResult;
f32 yOffset;
play_sound_if_no_flag(m, SOUND_ACTION_THROW, MARIO_ACTION_SOUND_PLAYED);
- if (m->actionState == 0) {
- if (m->actionTimer < 10) {
+ if (m->actionState == 0)
+ {
+ if (m->actionTimer < 10)
+ {
yOffset = 20 - 2 * m->actionTimer;
- if (m->pos[1] + yOffset + 160.0f < m->ceilHeight) {
+ if (m->pos[1] + yOffset + 160.0f < m->ceilHeight)
+ {
m->pos[1] += yOffset;
m->peakHeight = m->pos[1];
vec3f_copy(m->marioObj->header.gfx.pos, m->pos);
@@ -932,44 +1112,57 @@ s32 act_ground_pound(struct MarioState *m) {
m->vel[1] = -50.0f;
mario_set_forward_vel(m, 0.0f);
- set_mario_animation(m, m->actionArg == 0 ? MARIO_ANIM_START_GROUND_POUND
- : MARIO_ANIM_TRIPLE_JUMP_GROUND_POUND);
- if (m->actionTimer == 0) {
+ set_mario_animation(m, m->actionArg == 0
+ ? MARIO_ANIM_START_GROUND_POUND
+ : MARIO_ANIM_TRIPLE_JUMP_GROUND_POUND);
+ if (m->actionTimer == 0)
+ {
play_sound(SOUND_ACTION_SPIN, m->marioObj->header.gfx.cameraToObject);
}
m->actionTimer++;
- if (m->actionTimer >= m->marioObj->header.gfx.animInfo.curAnim->loopEnd + 4) {
+ if (m->actionTimer >= m->marioObj->header.gfx.animInfo.curAnim->loopEnd + 4)
+ {
play_sound(SOUND_MARIO_GROUND_POUND_WAH, m->marioObj->header.gfx.cameraToObject);
m->actionState = 1;
}
- } else {
+ }
+ else
+ {
set_mario_animation(m, MARIO_ANIM_GROUND_POUND);
stepResult = perform_air_step(m, 0);
- if (stepResult == AIR_STEP_LANDED) {
- if (should_get_stuck_in_ground(m)) {
-#ifdef VERSION_SH
+ if (stepResult == AIR_STEP_LANDED)
+ {
+ if (should_get_stuck_in_ground(m))
+ {
+ #ifdef VERSION_SH
queue_rumble_data(5, 80);
-#endif
-#ifdef VERSION_JP
+ #endif
+ #ifdef VERSION_JP
play_sound(SOUND_MARIO_OOOF, m->marioObj->header.gfx.cameraToObject);
-#else
+ #else
play_sound(SOUND_MARIO_OOOF2, m->marioObj->header.gfx.cameraToObject);
-#endif
+ #endif
m->particleFlags |= PARTICLE_MIST_CIRCLE;
set_mario_action(m, ACT_BUTT_STUCK_IN_GROUND, 0);
- } else {
+ }
+ else
+ {
play_mario_heavy_landing_sound(m, SOUND_ACTION_TERRAIN_HEAVY_LANDING);
- if (!check_fall_damage(m, ACT_HARD_BACKWARD_GROUND_KB)) {
+ if (!check_fall_damage(m, ACT_HARD_BACKWARD_GROUND_KB))
+ {
m->particleFlags |= PARTICLE_MIST_CIRCLE | PARTICLE_HORIZONTAL_STAR;
set_mario_action(m, ACT_GROUND_POUND_LAND, 0);
}
}
set_camera_shake_from_hit(SHAKE_GROUND_POUND);
- } else if (stepResult == AIR_STEP_HIT_WALL) {
+ }
+ else if (stepResult == AIR_STEP_HIT_WALL)
+ {
mario_set_forward_vel(m, -16.0f);
- if (m->vel[1] > 0.0f) {
+ if (m->vel[1] > 0.0f)
+ {
m->vel[1] = 0.0f;
}
@@ -981,11 +1174,13 @@ s32 act_ground_pound(struct MarioState *m) {
return FALSE;
}
-s32 act_burning_jump(struct MarioState *m) {
+s32 act_burning_jump(struct MarioState *m)
+{
play_mario_sound(m, SOUND_ACTION_TERRAIN_JUMP, m->actionArg == 0 ? 0 : -1);
mario_set_forward_vel(m, m->forwardVel);
- if (perform_air_step(m, 0) == AIR_STEP_LANDED) {
+ if (perform_air_step(m, 0) == AIR_STEP_LANDED)
+ {
play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
set_mario_action(m, ACT_BURNING_GROUND, 0);
}
@@ -997,19 +1192,22 @@ s32 act_burning_jump(struct MarioState *m) {
m->marioObj->oMarioBurnTimer += 3;
m->health -= 10;
- if (m->health < 0x100) {
+ if (m->health < 0x100)
+ {
m->health = 0xFF;
}
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
reset_rumble_timers();
-#endif
+ #endif
return FALSE;
}
-s32 act_burning_fall(struct MarioState *m) {
+s32 act_burning_fall(struct MarioState *m)
+{
mario_set_forward_vel(m, m->forwardVel);
- if (perform_air_step(m, 0) == AIR_STEP_LANDED) {
+ if (perform_air_step(m, 0) == AIR_STEP_LANDED)
+ {
play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
set_mario_action(m, ACT_BURNING_GROUND, 0);
}
@@ -1019,20 +1217,24 @@ s32 act_burning_fall(struct MarioState *m) {
m->marioObj->oMarioBurnTimer += 3;
m->health -= 10;
- if (m->health < 0x100) {
+ if (m->health < 0x100)
+ {
m->health = 0xFF;
}
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
reset_rumble_timers();
-#endif
+ #endif
return FALSE;
}
-s32 act_crazy_box_bounce(struct MarioState *m) {
+s32 act_crazy_box_bounce(struct MarioState *m)
+{
f32 minSpeed;
- if (m->actionTimer == 0) {
- switch (m->actionArg) {
+ if (m->actionTimer == 0)
+ {
+ switch (m->actionArg)
+ {
case 0:
m->vel[1] = 45.0f;
minSpeed = 32.0f;
@@ -1052,7 +1254,8 @@ s32 act_crazy_box_bounce(struct MarioState *m) {
play_sound(minSpeed < 40.0f ? SOUND_GENERAL_BOING1 : SOUND_GENERAL_BOING2,
m->marioObj->header.gfx.cameraToObject);
- if (m->forwardVel < minSpeed) {
+ if (m->forwardVel < minSpeed)
+ {
mario_set_forward_vel(m, minSpeed);
}
@@ -1064,18 +1267,22 @@ s32 act_crazy_box_bounce(struct MarioState *m) {
update_air_without_turn(m);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_LANDED:
- if (m->actionArg < 2) {
+ if (m->actionArg < 2)
+ {
set_mario_action(m, ACT_CRAZY_BOX_BOUNCE, m->actionArg + 1);
- } else {
+ }
+ else
+ {
m->heldObj->oInteractStatus = INT_STATUS_STOP_RIDING;
m->heldObj = NULL;
set_mario_action(m, ACT_STOMACH_SLIDE, 0);
}
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
queue_rumble_data(5, 80);
-#endif
+ #endif
m->particleFlags |= PARTICLE_MIST_CIRCLE;
break;
@@ -1092,34 +1299,42 @@ s32 act_crazy_box_bounce(struct MarioState *m) {
return FALSE;
}
-u32 common_air_knockback_step(struct MarioState *m, u32 landAction, u32 hardFallAction, s32 animation,
- f32 speed) {
+u32 common_air_knockback_step(
+ struct MarioState *m, u32 landAction, u32 hardFallAction, s32 animation,
+ f32 speed)
+{
u32 stepResult;
mario_set_forward_vel(m, speed);
stepResult = perform_air_step(m, 0);
- switch (stepResult) {
+ switch (stepResult)
+ {
case AIR_STEP_NONE:
set_mario_animation(m, animation);
break;
case AIR_STEP_LANDED:
-#ifdef VERSION_SH
- if (m->action == ACT_SOFT_BONK) {
+ #ifdef VERSION_SH
+ if (m->action == ACT_SOFT_BONK)
+ {
queue_rumble_data(5, 80);
}
-#endif
- if (!check_fall_damage_or_get_stuck(m, hardFallAction)) {
-#ifndef VERSION_JP
- if (m->action == ACT_THROWN_FORWARD || m->action == ACT_THROWN_BACKWARD) {
+ #endif
+ if (!check_fall_damage_or_get_stuck(m, hardFallAction))
+ {
+ #ifndef VERSION_JP
+ if (m->action == ACT_THROWN_FORWARD || m->action == ACT_THROWN_BACKWARD)
+ {
set_mario_action(m, landAction, m->hurtCounter);
- } else {
+ }
+ else
+ {
set_mario_action(m, landAction, m->actionArg);
}
-#else
+ #else
set_mario_action(m, landAction, m->actionArg);
-#endif
+ #endif
}
break;
@@ -1127,7 +1342,8 @@ u32 common_air_knockback_step(struct MarioState *m, u32 landAction, u32 hardFall
set_mario_animation(m, MARIO_ANIM_BACKWARD_AIR_KB);
mario_bonk_reflection(m, FALSE);
- if (m->vel[1] > 0.0f) {
+ if (m->vel[1] > 0.0f)
+ {
m->vel[1] = 0.0f;
}
@@ -1142,8 +1358,10 @@ u32 common_air_knockback_step(struct MarioState *m, u32 landAction, u32 hardFall
return stepResult;
}
-s32 check_wall_kick(struct MarioState *m) {
- if ((m->input & INPUT_A_PRESSED) && m->wallKickTimer != 0 && m->prevAction == ACT_AIR_HIT_WALL) {
+s32 check_wall_kick(struct MarioState *m)
+{
+ if (m->input & INPUT_A_PRESSED && m->wallKickTimer != 0 && m->prevAction == ACT_AIR_HIT_WALL)
+ {
m->faceAngle[1] += 0x8000;
return set_mario_action(m, ACT_WALL_KICK_AIR, 0);
}
@@ -1151,60 +1369,70 @@ s32 check_wall_kick(struct MarioState *m) {
return FALSE;
}
-s32 act_backward_air_kb(struct MarioState *m) {
- if (check_wall_kick(m)) {
+s32 act_backward_air_kb(struct MarioState *m)
+{
+ if (check_wall_kick(m))
+ {
return TRUE;
}
-#ifndef VERSION_JP
+ #ifndef VERSION_JP
play_knockback_sound(m);
-#else
+ #else
play_sound_if_no_flag(m, SOUND_MARIO_UH, MARIO_MARIO_SOUND_PLAYED);
-#endif
+ #endif
common_air_knockback_step(m, ACT_BACKWARD_GROUND_KB, ACT_HARD_BACKWARD_GROUND_KB, 0x0002, -16.0f);
return FALSE;
}
-s32 act_forward_air_kb(struct MarioState *m) {
- if (check_wall_kick(m)) {
+s32 act_forward_air_kb(struct MarioState *m)
+{
+ if (check_wall_kick(m))
+ {
return TRUE;
}
-#ifndef VERSION_JP
+ #ifndef VERSION_JP
play_knockback_sound(m);
-#else
+ #else
play_sound_if_no_flag(m, SOUND_MARIO_UH, MARIO_MARIO_SOUND_PLAYED);
-#endif
+ #endif
common_air_knockback_step(m, ACT_FORWARD_GROUND_KB, ACT_HARD_FORWARD_GROUND_KB, 0x002D, 16.0f);
return FALSE;
}
-s32 act_hard_backward_air_kb(struct MarioState *m) {
-#ifndef VERSION_JP
+s32 act_hard_backward_air_kb(struct MarioState *m)
+{
+ #ifndef VERSION_JP
play_knockback_sound(m);
-#else
+ #else
play_sound_if_no_flag(m, SOUND_MARIO_UH, MARIO_MARIO_SOUND_PLAYED);
-#endif
+ #endif
common_air_knockback_step(m, ACT_HARD_BACKWARD_GROUND_KB, ACT_HARD_BACKWARD_GROUND_KB, 0x0002,
-16.0f);
return FALSE;
}
-s32 act_hard_forward_air_kb(struct MarioState *m) {
-#ifndef VERSION_JP
+s32 act_hard_forward_air_kb(struct MarioState *m)
+{
+ #ifndef VERSION_JP
play_knockback_sound(m);
-#else
+ #else
play_sound_if_no_flag(m, SOUND_MARIO_UH, MARIO_MARIO_SOUND_PLAYED);
-#endif
+ #endif
common_air_knockback_step(m, ACT_HARD_FORWARD_GROUND_KB, ACT_HARD_FORWARD_GROUND_KB, 0x002D, 16.0f);
return FALSE;
}
-s32 act_thrown_backward(struct MarioState *m) {
+s32 act_thrown_backward(struct MarioState *m)
+{
u32 landAction;
- if (m->actionArg != 0) {
+ if (m->actionArg != 0)
+ {
landAction = ACT_HARD_BACKWARD_GROUND_KB;
- } else {
+ }
+ else
+ {
landAction = ACT_BACKWARD_GROUND_KB;
}
@@ -1216,22 +1444,28 @@ s32 act_thrown_backward(struct MarioState *m) {
return FALSE;
}
-s32 act_thrown_forward(struct MarioState *m) {
+s32 act_thrown_forward(struct MarioState *m)
+{
s16 pitch;
u32 landAction;
- if (m->actionArg != 0) {
+ if (m->actionArg != 0)
+ {
landAction = ACT_HARD_FORWARD_GROUND_KB;
- } else {
+ }
+ else
+ {
landAction = ACT_FORWARD_GROUND_KB;
}
play_sound_if_no_flag(m, SOUND_MARIO_WAAAOOOW, MARIO_MARIO_SOUND_PLAYED);
if (common_air_knockback_step(m, landAction, ACT_HARD_FORWARD_GROUND_KB, 0x002D, m->forwardVel)
- == AIR_STEP_NONE) {
+ == AIR_STEP_NONE)
+ {
pitch = atan2s(m->forwardVel, -m->vel[1]);
- if (pitch > 0x1800) {
+ if (pitch > 0x1800)
+ {
pitch = 0x1800;
}
@@ -1242,49 +1476,62 @@ s32 act_thrown_forward(struct MarioState *m) {
return FALSE;
}
-s32 act_soft_bonk(struct MarioState *m) {
- if (check_wall_kick(m)) {
+s32 act_soft_bonk(struct MarioState *m)
+{
+ if (check_wall_kick(m))
+ {
return TRUE;
}
-#ifndef VERSION_JP
+ #ifndef VERSION_JP
play_knockback_sound(m);
-#else
+ #else
play_sound_if_no_flag(m, SOUND_MARIO_UH, MARIO_MARIO_SOUND_PLAYED);
-#endif
+ #endif
common_air_knockback_step(m, ACT_FREEFALL_LAND, ACT_HARD_BACKWARD_GROUND_KB, 0x0056, m->forwardVel);
return FALSE;
}
-s32 act_getting_blown(struct MarioState *m) {
- if (m->actionState == 0) {
- if (m->forwardVel > -60.0f) {
+s32 act_getting_blown(struct MarioState *m)
+{
+ if (m->actionState == 0)
+ {
+ if (m->forwardVel > -60.0f)
+ {
m->forwardVel -= 6.0f;
- } else {
+ }
+ else
+ {
m->actionState = 1;
}
- } else {
- if (m->forwardVel < -16.0f) {
+ }
+ else
+ {
+ if (m->forwardVel < -16.0f)
+ {
m->forwardVel += 0.8f;
}
- if (m->vel[1] < 0.0f && m->unkC4 < 4.0f) {
+ if (m->vel[1] < 0.0f && m->unkC4 < 4.0f)
+ {
m->unkC4 += 0.05f;
}
}
- if (++(m->actionTimer) == 20) {
+ if (++m->actionTimer == 20)
+ {
mario_blow_off_cap(m, 50.0f);
}
mario_set_forward_vel(m, m->forwardVel);
-#ifdef VERSION_JP
+ #ifdef VERSION_JP
play_sound_if_no_flag(m, SOUND_MARIO_UH, MARIO_MARIO_SOUND_PLAYED);
-#endif
+ #endif
set_mario_animation(m, MARIO_ANIM_BACKWARD_AIR_KB);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_LANDED:
set_mario_action(m, ACT_HARD_BACKWARD_AIR_KB, 0);
break;
@@ -1293,7 +1540,8 @@ s32 act_getting_blown(struct MarioState *m) {
set_mario_animation(m, MARIO_ANIM_AIR_FORWARD_KB);
mario_bonk_reflection(m, FALSE);
- if (m->vel[1] > 0.0f) {
+ if (m->vel[1] > 0.0f)
+ {
m->vel[1] = 0.0f;
}
@@ -1304,41 +1552,52 @@ s32 act_getting_blown(struct MarioState *m) {
return FALSE;
}
-s32 act_air_hit_wall(struct MarioState *m) {
- if (m->heldObj != NULL) {
+s32 act_air_hit_wall(struct MarioState *m)
+{
+ if (m->heldObj != NULL)
+ {
mario_drop_held_object(m);
}
- if (++(m->actionTimer) <= 2) {
- if (m->input & INPUT_A_PRESSED) {
+ if (++m->actionTimer <= 2)
+ {
+ if (m->input & INPUT_A_PRESSED)
+ {
m->vel[1] = 52.0f;
m->faceAngle[1] += 0x8000;
return set_mario_action(m, ACT_WALL_KICK_AIR, 0);
}
- } else if (m->forwardVel >= 38.0f) {
+ }
+ else if (m->forwardVel >= 38.0f)
+ {
m->wallKickTimer = 5;
- if (m->vel[1] > 0.0f) {
+ if (m->vel[1] > 0.0f)
+ {
m->vel[1] = 0.0f;
}
m->particleFlags |= PARTICLE_VERTICAL_STAR;
return set_mario_action(m, ACT_BACKWARD_AIR_KB, 0);
- } else {
+ }
+ else
+ {
m->wallKickTimer = 5;
- if (m->vel[1] > 0.0f) {
+ if (m->vel[1] > 0.0f)
+ {
m->vel[1] = 0.0f;
}
- if (m->forwardVel > 8.0f) {
+ if (m->forwardVel > 8.0f)
+ {
mario_set_forward_vel(m, -8.0f);
}
return set_mario_action(m, ACT_SOFT_BONK, 0);
}
-#ifdef AVOID_UB
+ #ifdef AVOID_UB
return
-#endif
- set_mario_animation(m, MARIO_ANIM_START_WALLKICK);
+ #endif
+ set_mario_animation(m, MARIO_ANIM_START_WALLKICK);
//! Missing return statement. The returned value is the result of the call
// to set_mario_animation. In practice, this value is nonzero.
@@ -1348,8 +1607,10 @@ s32 act_air_hit_wall(struct MarioState *m) {
// of two.
}
-s32 act_forward_rollout(struct MarioState *m) {
- if (m->actionState == 0) {
+s32 act_forward_rollout(struct MarioState *m)
+{
+ if (m->actionState == 0)
+ {
m->vel[1] = 30.0f;
m->actionState = 1;
}
@@ -1358,13 +1619,18 @@ s32 act_forward_rollout(struct MarioState *m) {
update_air_without_turn(m);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_NONE:
- if (m->actionState == 1) {
- if (set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING) == 4) {
+ if (m->actionState == 1)
+ {
+ if (set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING) == 4)
+ {
play_sound(SOUND_ACTION_SPIN, m->marioObj->header.gfx.cameraToObject);
}
- } else {
+ }
+ else
+ {
set_mario_animation(m, MARIO_ANIM_GENERAL_FALL);
}
break;
@@ -1383,14 +1649,17 @@ s32 act_forward_rollout(struct MarioState *m) {
break;
}
- if (m->actionState == 1 && is_anim_past_end(m)) {
+ if (m->actionState == 1 && is_anim_past_end(m))
+ {
m->actionState = 2;
}
return FALSE;
}
-s32 act_backward_rollout(struct MarioState *m) {
- if (m->actionState == 0) {
+s32 act_backward_rollout(struct MarioState *m)
+{
+ if (m->actionState == 0)
+ {
m->vel[1] = 30.0f;
m->actionState = 1;
}
@@ -1399,13 +1668,18 @@ s32 act_backward_rollout(struct MarioState *m) {
update_air_without_turn(m);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_NONE:
- if (m->actionState == 1) {
- if (set_mario_animation(m, MARIO_ANIM_BACKWARD_SPINNING) == 4) {
+ if (m->actionState == 1)
+ {
+ if (set_mario_animation(m, MARIO_ANIM_BACKWARD_SPINNING) == 4)
+ {
play_sound(SOUND_ACTION_SPIN, m->marioObj->header.gfx.cameraToObject);
}
- } else {
+ }
+ else
+ {
set_mario_animation(m, MARIO_ANIM_GENERAL_FALL);
}
break;
@@ -1424,32 +1698,40 @@ s32 act_backward_rollout(struct MarioState *m) {
break;
}
- if (m->actionState == 1 && m->marioObj->header.gfx.animInfo.animFrame == 2) {
+ if (m->actionState == 1 && m->marioObj->header.gfx.animInfo.animFrame == 2)
+ {
m->actionState = 2;
}
return FALSE;
}
-s32 act_butt_slide_air(struct MarioState *m) {
- if (++(m->actionTimer) > 30 && m->pos[1] - m->floorHeight > 500.0f) {
+s32 act_butt_slide_air(struct MarioState *m)
+{
+ if (++m->actionTimer > 30 && m->pos[1] - m->floorHeight > 500.0f)
+ {
return set_mario_action(m, ACT_FREEFALL, 1);
}
update_air_with_turn(m);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_LANDED:
- if (m->actionState == 0 && m->vel[1] < 0.0f && m->floor->normal.y >= 0.9848077f) {
+ if (m->actionState == 0 && m->vel[1] < 0.0f && m->floor->normal.y >= 0.9848077f)
+ {
m->vel[1] = -m->vel[1] / 2.0f;
m->actionState = 1;
- } else {
+ }
+ else
+ {
set_mario_action(m, ACT_BUTT_SLIDE, 0);
}
play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
break;
case AIR_STEP_HIT_WALL:
- if (m->vel[1] > 0.0f) {
+ if (m->vel[1] > 0.0f)
+ {
m->vel[1] = 0.0f;
}
m->particleFlags |= PARTICLE_VERTICAL_STAR;
@@ -1465,30 +1747,38 @@ s32 act_butt_slide_air(struct MarioState *m) {
return FALSE;
}
-s32 act_hold_butt_slide_air(struct MarioState *m) {
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+s32 act_hold_butt_slide_air(struct MarioState *m)
+{
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_HOLD_FREEFALL, 1);
}
- if (++m->actionTimer > 30 && m->pos[1] - m->floorHeight > 500.0f) {
+ if (++m->actionTimer > 30 && m->pos[1] - m->floorHeight > 500.0f)
+ {
return set_mario_action(m, ACT_HOLD_FREEFALL, 1);
}
update_air_with_turn(m);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_LANDED:
- if (m->actionState == 0 && m->vel[1] < 0.0f && m->floor->normal.y >= 0.9848077f) {
+ if (m->actionState == 0 && m->vel[1] < 0.0f && m->floor->normal.y >= 0.9848077f)
+ {
m->vel[1] = -m->vel[1] / 2.0f;
m->actionState = 1;
- } else {
+ }
+ else
+ {
set_mario_action(m, ACT_HOLD_BUTT_SLIDE, 0);
}
play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
break;
case AIR_STEP_HIT_WALL:
- if (m->vel[1] > 0.0f) {
+ if (m->vel[1] > 0.0f)
+ {
m->vel[1] = 0.0f;
}
@@ -1506,41 +1796,52 @@ s32 act_hold_butt_slide_air(struct MarioState *m) {
return FALSE;
}
-s32 act_lava_boost(struct MarioState *m) {
-#ifdef VERSION_SH
- if (!(m->flags & MARIO_MARIO_SOUND_PLAYED)) {
+s32 act_lava_boost(struct MarioState *m)
+{
+ #ifdef VERSION_SH
+ if (!(m->flags & MARIO_MARIO_SOUND_PLAYED))
+ {
play_sound_if_no_flag(m, SOUND_MARIO_ON_FIRE, MARIO_MARIO_SOUND_PLAYED);
queue_rumble_data(5, 80);
}
-#else
+ #else
play_sound_if_no_flag(m, SOUND_MARIO_ON_FIRE, MARIO_MARIO_SOUND_PLAYED);
-#endif
+ #endif
- if (!(m->input & INPUT_NONZERO_ANALOG)) {
+ if (!(m->input & INPUT_NONZERO_ANALOG))
+ {
m->forwardVel = approach_f32(m->forwardVel, 0.0f, 0.35f, 0.35f);
}
update_lava_boost_or_twirling(m);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_LANDED:
- if (m->floor->type == SURFACE_BURNING) {
+ if (m->floor->type == SURFACE_BURNING)
+ {
m->actionState = 0;
- if (!(m->flags & MARIO_METAL_CAP)) {
- m->hurtCounter += (m->flags & MARIO_CAP_ON_HEAD) ? 12 : 18;
+ if (!(m->flags & MARIO_METAL_CAP))
+ {
+ m->hurtCounter += m->flags & MARIO_CAP_ON_HEAD ? 12 : 18;
}
m->vel[1] = 84.0f;
play_sound(SOUND_MARIO_ON_FIRE, m->marioObj->header.gfx.cameraToObject);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
queue_rumble_data(5, 80);
-#endif
- } else {
+ #endif
+ }
+ else
+ {
play_mario_heavy_landing_sound(m, SOUND_ACTION_TERRAIN_BODY_HIT_GROUND);
- if (m->actionState < 2 && m->vel[1] < 0.0f) {
+ if (m->actionState < 2 && m->vel[1] < 0.0f)
+ {
m->vel[1] = -m->vel[1] * 0.4f;
mario_set_forward_vel(m, m->forwardVel * 0.5f);
m->actionState += 1;
- } else {
+ }
+ else
+ {
set_mario_action(m, ACT_LAVA_BOOST_LAND, 0);
}
}
@@ -1558,59 +1859,72 @@ s32 act_lava_boost(struct MarioState *m) {
set_mario_animation(m, MARIO_ANIM_FIRE_LAVA_BURN);
if (m->curTerrain != TERRAIN_SNOW && !(m->flags & MARIO_METAL_CAP)
- && m->vel[1] > 0.0f) {
+ && m->vel[1] > 0.0f)
+ {
m->particleFlags |= PARTICLE_FIRE;
- if (m->actionState == 0) {
+ if (m->actionState == 0)
+ {
play_sound(SOUND_MOVING_LAVA_BURN, m->marioObj->header.gfx.cameraToObject);
}
}
- if (m->health < 0x100) {
+ if (m->health < 0x100)
+ {
level_trigger_warp(m, WARP_OP_DEATH);
}
m->marioBodyState->eyeState = MARIO_EYES_DEAD;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
reset_rumble_timers();
-#endif
+ #endif
return FALSE;
}
-s32 act_slide_kick(struct MarioState *m) {
- if (m->actionState == 0 && m->actionTimer == 0) {
+s32 act_slide_kick(struct MarioState *m)
+{
+ if (m->actionState == 0 && m->actionTimer == 0)
+ {
play_mario_sound(m, SOUND_ACTION_TERRAIN_JUMP, SOUND_MARIO_HOOHOO);
set_mario_animation(m, MARIO_ANIM_SLIDE_KICK);
}
- if (++(m->actionTimer) > 30 && m->pos[1] - m->floorHeight > 500.0f) {
+ if (++m->actionTimer > 30 && m->pos[1] - m->floorHeight > 500.0f)
+ {
return set_mario_action(m, ACT_FREEFALL, 2);
}
update_air_without_turn(m);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_NONE:
- if (m->actionState == 0) {
+ if (m->actionState == 0)
+ {
m->marioObj->header.gfx.angle[0] = atan2s(m->forwardVel, -m->vel[1]);
- if (m->marioObj->header.gfx.angle[0] > 0x1800) {
+ if (m->marioObj->header.gfx.angle[0] > 0x1800)
+ {
m->marioObj->header.gfx.angle[0] = 0x1800;
}
}
break;
case AIR_STEP_LANDED:
- if (m->actionState == 0 && m->vel[1] < 0.0f) {
+ if (m->actionState == 0 && m->vel[1] < 0.0f)
+ {
m->vel[1] = -m->vel[1] / 2.0f;
m->actionState = 1;
m->actionTimer = 0;
- } else {
+ }
+ else
+ {
set_mario_action(m, ACT_SLIDE_KICK_SLIDE, 0);
}
play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
break;
case AIR_STEP_HIT_WALL:
- if (m->vel[1] > 0.0f) {
+ if (m->vel[1] > 0.0f)
+ {
m->vel[1] = 0.0f;
}
@@ -1627,10 +1941,12 @@ s32 act_slide_kick(struct MarioState *m) {
return FALSE;
}
-s32 act_jump_kick(struct MarioState *m) {
+s32 act_jump_kick(struct MarioState *m)
+{
s32 animFrame;
- if (m->actionState == 0) {
+ if (m->actionState == 0)
+ {
play_sound_if_no_flag(m, SOUND_MARIO_PUNCH_HOO, MARIO_ACTION_SOUND_PLAYED);
m->marioObj->header.gfx.animInfo.animID = -1;
set_mario_animation(m, MARIO_ANIM_AIR_KICK);
@@ -1638,18 +1954,22 @@ s32 act_jump_kick(struct MarioState *m) {
}
animFrame = m->marioObj->header.gfx.animInfo.animFrame;
- if (animFrame == 0) {
- m->marioBodyState->punchState = (2 << 6) | 6;
+ if (animFrame == 0)
+ {
+ m->marioBodyState->punchState = 2 << 6 | 6;
}
- if (animFrame >= 0 && animFrame < 8) {
+ if (animFrame >= 0 && animFrame < 8)
+ {
m->flags |= MARIO_KICKING;
}
update_air_without_turn(m);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_LANDED:
- if (!check_fall_damage_or_get_stuck(m, ACT_HARD_BACKWARD_GROUND_KB)) {
+ if (!check_fall_damage_or_get_stuck(m, ACT_HARD_BACKWARD_GROUND_KB))
+ {
set_mario_action(m, ACT_FREEFALL_LAND, 0);
}
break;
@@ -1662,16 +1982,18 @@ s32 act_jump_kick(struct MarioState *m) {
return FALSE;
}
-s32 act_shot_from_cannon(struct MarioState *m) {
-// if (m->area->camera->mode != CAMERA_MODE_BEHIND_MARIO) {
-// m->statusForCamera->cameraEvent = CAM_EVENT_SHOT_FROM_CANNON;
-// }
+s32 act_shot_from_cannon(struct MarioState *m)
+{
+ // if (m->area->camera->mode != CAMERA_MODE_BEHIND_MARIO) {
+ // m->statusForCamera->cameraEvent = CAM_EVENT_SHOT_FROM_CANNON;
+ // }
mario_set_forward_vel(m, m->forwardVel);
play_sound_if_no_flag(m, SOUND_MARIO_YAHOO, MARIO_MARIO_SOUND_PLAYED);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_NONE:
set_mario_animation(m, MARIO_ANIM_AIRBORNE_ON_STOMACH);
m->faceAngle[0] = atan2s(m->forwardVel, m->vel[1]);
@@ -1682,16 +2004,17 @@ s32 act_shot_from_cannon(struct MarioState *m) {
set_mario_action(m, ACT_DIVE_SLIDE, 0);
m->faceAngle[0] = 0;
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
queue_rumble_data(5, 80);
-#endif
+ #endif
break;
case AIR_STEP_HIT_WALL:
mario_set_forward_vel(m, -16.0f);
m->faceAngle[0] = 0;
- if (m->vel[1] > 0.0f) {
+ if (m->vel[1] > 0.0f)
+ {
m->vel[1] = 0.0f;
}
@@ -1705,56 +2028,72 @@ s32 act_shot_from_cannon(struct MarioState *m) {
break;
}
- if ((m->flags & MARIO_WING_CAP) && m->vel[1] < 0.0f) {
+ if (m->flags & MARIO_WING_CAP && m->vel[1] < 0.0f)
+ {
set_mario_action(m, ACT_FLYING, 0);
}
- if ((m->forwardVel -= 0.05) < 10.0f) {
+ if ((m->forwardVel -= 0.05) < 10.0f)
+ {
mario_set_forward_vel(m, 10.0f);
}
- if (m->vel[1] > 0.0f) {
+ if (m->vel[1] > 0.0f)
+ {
m->particleFlags |= PARTICLE_DUST;
}
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
reset_rumble_timers();
-#endif
+ #endif
return FALSE;
}
-s32 act_flying(struct MarioState *m) {
+s32 act_flying(struct MarioState *m)
+{
s16 startPitch = m->faceAngle[0];
- if (m->input & INPUT_Z_PRESSED) {
- if (m->area->camera->mode == CAMERA_MODE_BEHIND_MARIO) {
+ if (m->input & INPUT_Z_PRESSED)
+ {
+ if (m->area->camera->mode == CAMERA_MODE_BEHIND_MARIO)
+ {
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
}
return set_mario_action(m, ACT_GROUND_POUND, 1);
}
- if (!(m->flags & MARIO_WING_CAP)) {
- if (m->area->camera->mode == CAMERA_MODE_BEHIND_MARIO) {
+ if (!(m->flags & MARIO_WING_CAP))
+ {
+ if (m->area->camera->mode == CAMERA_MODE_BEHIND_MARIO)
+ {
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
}
return set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->area->camera->mode != CAMERA_MODE_BEHIND_MARIO) {
+ if (m->area->camera->mode != CAMERA_MODE_BEHIND_MARIO)
+ {
set_camera_mode(m->area->camera, CAMERA_MODE_BEHIND_MARIO, 1);
}
- if (m->actionState == 0) {
- if (m->actionArg == 0) {
+ if (m->actionState == 0)
+ {
+ if (m->actionArg == 0)
+ {
set_mario_animation(m, MARIO_ANIM_FLY_FROM_CANNON);
- } else {
+ }
+ else
+ {
set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING_FLIP);
- if (m->marioObj->header.gfx.animInfo.animFrame == 1) {
+ if (m->marioObj->header.gfx.animInfo.animFrame == 1)
+ {
play_sound(SOUND_ACTION_SPIN, m->marioObj->header.gfx.cameraToObject);
}
}
- if (is_anim_at_end(m)) {
- if (m->actionArg == 2) {
+ if (is_anim_at_end(m))
+ {
+ if (m->actionArg == 2)
+ {
load_level_init_text(0);
m->actionArg = 1;
}
@@ -1766,7 +2105,8 @@ s32 act_flying(struct MarioState *m) {
update_flying(m);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_NONE:
m->marioObj->header.gfx.angle[0] = -m->faceAngle[0];
m->marioObj->header.gfx.angle[2] = m->faceAngle[2];
@@ -1781,38 +2121,46 @@ s32 act_flying(struct MarioState *m) {
m->faceAngle[0] = 0;
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
queue_rumble_data(5, 80);
-#endif
+ #endif
break;
case AIR_STEP_HIT_WALL:
- if (m->wall != NULL) {
+ if (m->wall != NULL)
+ {
mario_set_forward_vel(m, -16.0f);
m->faceAngle[0] = 0;
- if (m->vel[1] > 0.0f) {
+ if (m->vel[1] > 0.0f)
+ {
m->vel[1] = 0.0f;
}
- play_sound((m->flags & MARIO_METAL_CAP) ? SOUND_ACTION_METAL_BONK
- : SOUND_ACTION_BONK,
+ play_sound(m->flags & MARIO_METAL_CAP
+ ? SOUND_ACTION_METAL_BONK
+ : SOUND_ACTION_BONK,
m->marioObj->header.gfx.cameraToObject);
m->particleFlags |= PARTICLE_VERTICAL_STAR;
set_mario_action(m, ACT_BACKWARD_AIR_KB, 0);
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
- } else {
- if (m->actionTimer++ == 0) {
+ }
+ else
+ {
+ if (m->actionTimer++ == 0)
+ {
play_sound(SOUND_ACTION_HIT, m->marioObj->header.gfx.cameraToObject);
}
- if (m->actionTimer == 30) {
+ if (m->actionTimer == 30)
+ {
m->actionTimer = 0;
}
m->faceAngle[0] -= 0x200;
- if (m->faceAngle[0] < -0x2AAA) {
+ if (m->faceAngle[0] < -0x2AAA)
+ {
m->faceAngle[0] = -0x2AAA;
}
@@ -1826,19 +2174,21 @@ s32 act_flying(struct MarioState *m) {
break;
}
- if (m->faceAngle[0] > 0x800 && m->forwardVel >= 48.0f) {
+ if (m->faceAngle[0] > 0x800 && m->forwardVel >= 48.0f)
+ {
m->particleFlags |= PARTICLE_DUST;
}
- if (startPitch <= 0 && m->faceAngle[0] > 0 && m->forwardVel >= 48.0f) {
+ if (startPitch <= 0 && m->faceAngle[0] > 0 && m->forwardVel >= 48.0f)
+ {
play_sound(SOUND_ACTION_FLYING_FAST, m->marioObj->header.gfx.cameraToObject);
-#ifndef VERSION_JP
+ #ifndef VERSION_JP
play_sound(SOUND_MARIO_YAHOO_WAHA_YIPPEE + ((gAudioRandom % 5) << 16),
m->marioObj->header.gfx.cameraToObject);
-#endif
-#ifdef VERSION_SH
+ #endif
+ #ifdef VERSION_SH
queue_rumble_data(50, 40);
-#endif
+ #endif
}
play_sound(SOUND_MOVING_FLYING, m->marioObj->header.gfx.cameraToObject);
@@ -1846,15 +2196,17 @@ s32 act_flying(struct MarioState *m) {
return FALSE;
}
-s32 act_riding_hoot(struct MarioState *m) {
- if (!(m->input & INPUT_A_DOWN) || (m->marioObj->oInteractStatus & INT_STATUS_MARIO_UNK7)) {
+s32 act_riding_hoot(struct MarioState *m)
+{
+ if (!(m->input & INPUT_A_DOWN) || m->marioObj->oInteractStatus & INT_STATUS_MARIO_UNK7)
+ {
m->usedObj->oInteractStatus = 0;
m->usedObj->oHootMarioReleaseTime = gGlobalTimer;
play_sound_if_no_flag(m, SOUND_MARIO_UH, MARIO_MARIO_SOUND_PLAYED);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
queue_rumble_data(4, 40);
-#endif
+ #endif
return set_mario_action(m, ACT_FREEFALL, 0);
}
@@ -1864,9 +2216,11 @@ s32 act_riding_hoot(struct MarioState *m) {
m->faceAngle[1] = 0x4000 - m->usedObj->oMoveAngleYaw;
- if (m->actionState == 0) {
+ if (m->actionState == 0)
+ {
set_mario_animation(m, MARIO_ANIM_HANG_ON_CEILING);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_animation(m, MARIO_ANIM_HANG_ON_OWL);
m->actionState = 1;
}
@@ -1878,70 +2232,88 @@ s32 act_riding_hoot(struct MarioState *m) {
return FALSE;
}
-s32 act_flying_triple_jump(struct MarioState *m) {
-#ifndef VERSION_JP
- if (m->input & (INPUT_B_PRESSED | INPUT_Z_PRESSED)) {
- if (m->area->camera->mode == CAMERA_MODE_BEHIND_MARIO) {
+s32 act_flying_triple_jump(struct MarioState *m)
+{
+ #ifndef VERSION_JP
+ if (m->input & (INPUT_B_PRESSED | INPUT_Z_PRESSED))
+ {
+ if (m->area->camera->mode == CAMERA_MODE_BEHIND_MARIO)
+ {
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_DIVE, 0);
- } else {
+ }
+ else
+ {
return set_mario_action(m, ACT_GROUND_POUND, 0);
}
}
-#else
- if (m->input & INPUT_B_PRESSED) {
+ #else
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_DIVE, 0);
}
- if (m->input & INPUT_Z_PRESSED) {
+ if (m->input & INPUT_Z_PRESSED)
+ {
return set_mario_action(m, ACT_GROUND_POUND, 0);
}
-#endif
+ #endif
play_mario_sound(m, SOUND_ACTION_TERRAIN_JUMP, SOUND_MARIO_YAHOO);
- if (m->actionState == 0) {
+ if (m->actionState == 0)
+ {
set_mario_animation(m, MARIO_ANIM_TRIPLE_JUMP_FLY);
- if (m->marioObj->header.gfx.animInfo.animFrame == 7) {
+ if (m->marioObj->header.gfx.animInfo.animFrame == 7)
+ {
play_sound(SOUND_ACTION_SPIN, m->marioObj->header.gfx.cameraToObject);
}
- if (is_anim_past_end(m)) {
+ if (is_anim_past_end(m))
+ {
set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
queue_rumble_data(8, 80);
-#endif
+ #endif
m->actionState = 1;
}
}
- if (m->actionState == 1 && m->marioObj->header.gfx.animInfo.animFrame == 1) {
+ if (m->actionState == 1 && m->marioObj->header.gfx.animInfo.animFrame == 1)
+ {
play_sound(SOUND_ACTION_SPIN, m->marioObj->header.gfx.cameraToObject);
}
- if (m->vel[1] < 4.0f) {
- if (m->area->camera->mode != CAMERA_MODE_BEHIND_MARIO) {
+ if (m->vel[1] < 4.0f)
+ {
+ if (m->area->camera->mode != CAMERA_MODE_BEHIND_MARIO)
+ {
set_camera_mode(m->area->camera, CAMERA_MODE_BEHIND_MARIO, 1);
}
- if (m->forwardVel < 32.0f) {
+ if (m->forwardVel < 32.0f)
+ {
mario_set_forward_vel(m, 32.0f);
}
set_mario_action(m, ACT_FLYING, 1);
}
- if (m->actionTimer++ == 10 && m->area->camera->mode != CAMERA_MODE_BEHIND_MARIO) {
+ if (m->actionTimer++ == 10 && m->area->camera->mode != CAMERA_MODE_BEHIND_MARIO)
+ {
set_camera_mode(m->area->camera, CAMERA_MODE_BEHIND_MARIO, 1);
}
update_air_without_turn(m);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_LANDED:
- if (!check_fall_damage_or_get_stuck(m, ACT_HARD_BACKWARD_GROUND_KB)) {
+ if (!check_fall_damage_or_get_stuck(m, ACT_HARD_BACKWARD_GROUND_KB))
+ {
set_mario_action(m, ACT_DOUBLE_JUMP_LAND, 0);
}
break;
@@ -1958,36 +2330,44 @@ s32 act_flying_triple_jump(struct MarioState *m) {
return FALSE;
}
-s32 act_top_of_pole_jump(struct MarioState *m) {
+s32 act_top_of_pole_jump(struct MarioState *m)
+{
play_mario_jump_sound(m);
common_air_action_step(m, ACT_FREEFALL_LAND, MARIO_ANIM_HANDSTAND_JUMP, AIR_STEP_CHECK_LEDGE_GRAB);
return FALSE;
}
-s32 act_vertical_wind(struct MarioState *m) {
+s32 act_vertical_wind(struct MarioState *m)
+{
s16 intendedDYaw = m->intendedYaw - m->faceAngle[1];
f32 intendedMag = m->intendedMag / 32.0f;
play_sound_if_no_flag(m, SOUND_MARIO_HERE_WE_GO, MARIO_MARIO_SOUND_PLAYED);
- if (m->actionState == 0) {
+ if (m->actionState == 0)
+ {
set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING_FLIP);
- if (m->marioObj->header.gfx.animInfo.animFrame == 1) {
+ if (m->marioObj->header.gfx.animInfo.animFrame == 1)
+ {
play_sound(SOUND_ACTION_SPIN, m->marioObj->header.gfx.cameraToObject);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
queue_rumble_data(8, 80);
-#endif
+ #endif
}
- if (is_anim_past_end(m)) {
+ if (is_anim_past_end(m))
+ {
m->actionState = 1;
}
- } else {
+ }
+ else
+ {
set_mario_animation(m, MARIO_ANIM_AIRBORNE_ON_STOMACH);
}
update_air_without_turn(m);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_LANDED:
set_mario_action(m, ACT_DIVE_SLIDE, 0);
break;
@@ -2002,12 +2382,15 @@ s32 act_vertical_wind(struct MarioState *m) {
return FALSE;
}
-s32 act_special_triple_jump(struct MarioState *m) {
- if (m->input & INPUT_B_PRESSED) {
+s32 act_special_triple_jump(struct MarioState *m)
+{
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_DIVE, 0);
}
- if (m->input & INPUT_Z_PRESSED) {
+ if (m->input & INPUT_Z_PRESSED)
+ {
return set_mario_action(m, ACT_GROUND_POUND, 0);
}
@@ -2015,11 +2398,15 @@ s32 act_special_triple_jump(struct MarioState *m) {
update_air_without_turn(m);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_LANDED:
- if (m->actionState++ == 0) {
+ if (m->actionState++ == 0)
+ {
m->vel[1] = 42.0f;
- } else {
+ }
+ else
+ {
set_mario_action(m, ACT_FREEFALL_LAND_STOP, 0);
}
play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
@@ -2030,11 +2417,15 @@ s32 act_special_triple_jump(struct MarioState *m) {
break;
}
- if (m->actionState == 0 || m->vel[1] > 0.0f) {
- if (set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING) == 0) {
+ if (m->actionState == 0 || m->vel[1] > 0.0f)
+ {
+ if (set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING) == 0)
+ {
play_sound(SOUND_ACTION_SPIN, m->marioObj->header.gfx.cameraToObject);
}
- } else {
+ }
+ else
+ {
set_mario_animation(m, MARIO_ANIM_GENERAL_FALL);
}
@@ -2042,16 +2433,20 @@ s32 act_special_triple_jump(struct MarioState *m) {
return FALSE;
}
-s32 check_common_airborne_cancels(struct MarioState *m) {
- if (m->pos[1] < m->waterLevel - 100) {
+s32 check_common_airborne_cancels(struct MarioState *m)
+{
+ if (m->pos[1] < m->waterLevel - 100)
+ {
return set_water_plunge_action(m);
}
- if (m->input & INPUT_SQUISHED) {
+ if (m->input & INPUT_SQUISHED)
+ {
return drop_and_set_mario_action(m, ACT_SQUISHED, 0);
}
- if (m->floor->type == SURFACE_VERTICAL_WIND && (m->action & ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION)) {
+ if (m->floor->type == SURFACE_VERTICAL_WIND && m->action & ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION)
+ {
return drop_and_set_mario_action(m, ACT_VERTICAL_WIND, 0);
}
@@ -2059,10 +2454,12 @@ s32 check_common_airborne_cancels(struct MarioState *m) {
return FALSE;
}
-s32 mario_execute_airborne_action(struct MarioState *m) {
+s32 mario_execute_airborne_action(struct MarioState *m)
+{
u32 cancel;
- if (check_common_airborne_cancels(m)) {
+ if (check_common_airborne_cancels(m))
+ {
return TRUE;
}
diff --git a/src/decomp/game/mario_actions_automatic.c b/src/decomp/game/mario_actions_automatic.c
index b635d29..3a52024 100644
--- a/src/decomp/game/mario_actions_automatic.c
+++ b/src/decomp/game/mario_actions_automatic.c
@@ -21,7 +21,7 @@
#include "../include/object_fields.h"
#include "../include/mario_geo_switch_case_ids.h"
-static Vec3f gVec3fZero = { 0.0f, 0.0f, 0.0f };
+static Vec3f gVec3fZero = {0.0f, 0.0f, 0.0f};
#define POLE_NONE 0
#define POLE_TOUCHED_FLOOR 1
@@ -31,37 +31,40 @@ static Vec3f gVec3fZero = { 0.0f, 0.0f, 0.0f };
#define HANG_HIT_CEIL_OR_OOB 1
#define HANG_LEFT_CEIL 2
-void add_tree_leaf_particles(struct MarioState *m) {
-// f32 leafHeight;
+void add_tree_leaf_particles(struct MarioState *m)
+{
+ // f32 leafHeight;
-// if (m->usedObj->behavior == segmented_to_virtual(bhvTree)) {
-// // make leaf effect spawn higher on the Shifting Sand Land palm tree
-// if (gCurrLevelNum == LEVEL_SSL) {
-// leafHeight = 250.0f;
-// } else {
-// leafHeight = 100.0f;
-// }
-// if (m->pos[1] - m->floorHeight > leafHeight) {
-// m->particleFlags |= PARTICLE_LEAF;
-// }
-// }
+ // if (m->usedObj->behavior == segmented_to_virtual(bhvTree)) {
+ // // make leaf effect spawn higher on the Shifting Sand Land palm tree
+ // if (gCurrLevelNum == LEVEL_SSL) {
+ // leafHeight = 250.0f;
+ // } else {
+ // leafHeight = 100.0f;
+ // }
+ // if (m->pos[1] - m->floorHeight > leafHeight) {
+ // m->particleFlags |= PARTICLE_LEAF;
+ // }
+ // }
}
-void play_climbing_sounds(struct MarioState *m, s32 b) {
-// s32 isOnTree = (m->usedObj->behavior == segmented_to_virtual(bhvTree));
+void play_climbing_sounds(struct MarioState *m, s32 b)
+{
+ // s32 isOnTree = (m->usedObj->behavior == segmented_to_virtual(bhvTree));
-// if (b == 1) {
-// if (is_anim_past_frame(m, 1)) {
-// play_sound(isOnTree ? SOUND_ACTION_CLIMB_UP_TREE : SOUND_ACTION_CLIMB_UP_POLE,
-// m->marioObj->header.gfx.cameraToObject);
-// }
-// } else {
-// play_sound(isOnTree ? SOUND_MOVING_SLIDE_DOWN_TREE : SOUND_MOVING_SLIDE_DOWN_POLE,
-// m->marioObj->header.gfx.cameraToObject);
-// }
+ // if (b == 1) {
+ // if (is_anim_past_frame(m, 1)) {
+ // play_sound(isOnTree ? SOUND_ACTION_CLIMB_UP_TREE : SOUND_ACTION_CLIMB_UP_POLE,
+ // m->marioObj->header.gfx.cameraToObject);
+ // }
+ // } else {
+ // play_sound(isOnTree ? SOUND_MOVING_SLIDE_DOWN_TREE : SOUND_MOVING_SLIDE_DOWN_POLE,
+ // m->marioObj->header.gfx.cameraToObject);
+ // }
}
-s32 set_pole_position(struct MarioState *m, f32 offsetY) {
+s32 set_pole_position(struct MarioState *m, f32 offsetY)
+{
UNUSED s32 unused1;
UNUSED s32 unused2;
UNUSED s32 unused3;
@@ -74,7 +77,8 @@ s32 set_pole_position(struct MarioState *m, f32 offsetY) {
f32 poleTop = m->usedObj->hitboxHeight - 100.0f;
struct Object *marioObj = m->marioObj;
- if (marioObj->oMarioPolePos > poleTop) {
+ if (marioObj->oMarioPolePos > poleTop)
+ {
marioObj->oMarioPolePos = poleTop;
}
@@ -86,26 +90,35 @@ s32 set_pole_position(struct MarioState *m, f32 offsetY) {
collided |= f32_find_wall_collision(&m->pos[0], &m->pos[1], &m->pos[2], 30.0f, 24.0f);
ceilHeight = vec3f_find_ceil(m->pos, m->pos[1], &ceil);
- if (m->pos[1] > ceilHeight - 160.0f) {
+ if (m->pos[1] > ceilHeight - 160.0f)
+ {
m->pos[1] = ceilHeight - 160.0f;
marioObj->oMarioPolePos = m->pos[1] - m->usedObj->oPosY;
}
floorHeight = find_floor(m->pos[0], m->pos[1], m->pos[2], &floor);
- if (m->pos[1] < floorHeight) {
+ if (m->pos[1] < floorHeight)
+ {
m->pos[1] = floorHeight;
set_mario_action(m, ACT_IDLE, 0);
result = POLE_TOUCHED_FLOOR;
- } else if (marioObj->oMarioPolePos < -m->usedObj->hitboxDownOffset) {
+ }
+ else if (marioObj->oMarioPolePos < -m->usedObj->hitboxDownOffset)
+ {
m->pos[1] = m->usedObj->oPosY - m->usedObj->hitboxDownOffset;
set_mario_action(m, ACT_FREEFALL, 0);
result = POLE_FELL_OFF;
- } else if (collided) {
- if (m->pos[1] > floorHeight + 20.0f) {
+ }
+ else if (collided)
+ {
+ if (m->pos[1] > floorHeight + 20.0f)
+ {
m->forwardVel = -2.0f;
set_mario_action(m, ACT_SOFT_BONK, 0);
result = POLE_FELL_OFF;
- } else {
+ }
+ else
+ {
set_mario_action(m, ACT_IDLE, 0);
result = POLE_TOUCHED_FLOOR;
}
@@ -118,102 +131,119 @@ s32 set_pole_position(struct MarioState *m, f32 offsetY) {
return result;
}
-s32 act_holding_pole(struct MarioState *m) {
+s32 act_holding_pole(struct MarioState *m)
+{
struct Object *marioObj = m->marioObj;
-#ifdef VERSION_JP
- if (m->input & INPUT_A_PRESSED) {
+ #ifdef VERSION_JP
+ if (m->input & INPUT_A_PRESSED)
+ {
add_tree_leaf_particles(m);
m->faceAngle[1] += 0x8000;
return set_mario_action(m, ACT_WALL_KICK_AIR, 0);
}
- if (m->input & INPUT_Z_PRESSED) {
+ if (m->input & INPUT_Z_PRESSED)
+ {
add_tree_leaf_particles(m);
m->forwardVel = -2.0f;
return set_mario_action(m, ACT_SOFT_BONK, 0);
}
-#else
- if ((m->input & INPUT_Z_PRESSED) || m->health < 0x100) {
+ #else
+ if (m->input & INPUT_Z_PRESSED || m->health < 0x100)
+ {
add_tree_leaf_particles(m);
m->forwardVel = -2.0f;
return set_mario_action(m, ACT_SOFT_BONK, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
add_tree_leaf_particles(m);
m->faceAngle[1] += 0x8000;
return set_mario_action(m, ACT_WALL_KICK_AIR, 0);
}
-#endif
+ #endif
- if (m->controller->stickY > 16.0f) {
+ if (m->controller->stickY > 16.0f)
+ {
f32 poleTop = m->usedObj->hitboxHeight - 100.0f;
-// const BehaviorScript *poleBehavior = virtual_to_segmented(0x13, m->usedObj->behavior);
+ // const BehaviorScript *poleBehavior = virtual_to_segmented(0x13, m->usedObj->behavior);
- if (marioObj->oMarioPolePos < poleTop - 0.4f) {
+ if (marioObj->oMarioPolePos < poleTop - 0.4f)
+ {
return set_mario_action(m, ACT_CLIMBING_POLE, 0);
}
-// if (poleBehavior != bhvGiantPole && m->controller->stickY > 50.0f) {
- if (m->controller->stickY > 50.0f) {
+ // if (poleBehavior != bhvGiantPole && m->controller->stickY > 50.0f) {
+ if (m->controller->stickY > 50.0f)
+ {
return set_mario_action(m, ACT_TOP_OF_POLE_TRANSITION, 0);
}
}
- if (m->controller->stickY < -16.0f) {
+ if (m->controller->stickY < -16.0f)
+ {
marioObj->oMarioPoleYawVel -= m->controller->stickY * 2;
- if (marioObj->oMarioPoleYawVel > 0x1000) {
+ if (marioObj->oMarioPoleYawVel > 0x1000)
+ {
marioObj->oMarioPoleYawVel = 0x1000;
}
m->faceAngle[1] += marioObj->oMarioPoleYawVel;
marioObj->oMarioPolePos -= marioObj->oMarioPoleYawVel / 0x100;
-// if (m->usedObj->behavior == segmented_to_virtual(bhvTree)) {
-// //! The Shifting Sand Land palm tree check is done climbing up in
-// // add_tree_leaf_particles, but not here, when climbing down.
-// if (m->pos[1] - m->floorHeight > 100.0f) {
-// m->particleFlags |= PARTICLE_LEAF;
-// }
-// }
+ // if (m->usedObj->behavior == segmented_to_virtual(bhvTree)) {
+ // //! The Shifting Sand Land palm tree check is done climbing up in
+ // // add_tree_leaf_particles, but not here, when climbing down.
+ // if (m->pos[1] - m->floorHeight > 100.0f) {
+ // m->particleFlags |= PARTICLE_LEAF;
+ // }
+ // }
play_climbing_sounds(m, 2);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
reset_rumble_timers();
-#endif
+ #endif
func_80320A4C(1, marioObj->oMarioPoleYawVel / 0x100 * 2);
- } else {
+ }
+ else
+ {
marioObj->oMarioPoleYawVel = 0;
m->faceAngle[1] -= m->controller->stickX * 16.0f;
}
- if (set_pole_position(m, 0.0f) == POLE_NONE) {
+ if (set_pole_position(m, 0.0f) == POLE_NONE)
+ {
set_mario_animation(m, MARIO_ANIM_IDLE_ON_POLE);
}
return FALSE;
}
-s32 act_climbing_pole(struct MarioState *m) {
+s32 act_climbing_pole(struct MarioState *m)
+{
s32 sp24;
struct Object *marioObj = m->marioObj;
s16 cameraAngle = m->area->camera->yaw;
-#ifndef VERSION_JP
- if (m->health < 0x100) {
+ #ifndef VERSION_JP
+ if (m->health < 0x100)
+ {
add_tree_leaf_particles(m);
m->forwardVel = -2.0f;
return set_mario_action(m, ACT_SOFT_BONK, 0);
}
-#endif
+ #endif
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
add_tree_leaf_particles(m);
m->faceAngle[1] += 0x8000;
return set_mario_action(m, ACT_WALL_KICK_AIR, 0);
}
- if (m->controller->stickY < 8.0f) {
+ if (m->controller->stickY < 8.0f)
+ {
return set_mario_action(m, ACT_HOLDING_POLE, 0);
}
@@ -221,7 +251,8 @@ s32 act_climbing_pole(struct MarioState *m) {
marioObj->oMarioPoleYawVel = 0;
m->faceAngle[1] = cameraAngle - approach_s32((s16)(cameraAngle - m->faceAngle[1]), 0, 0x400, 0x400);
- if (set_pole_position(m, 0.0f) == POLE_NONE) {
+ if (set_pole_position(m, 0.0f) == POLE_NONE)
+ {
sp24 = m->controller->stickY / 4.0f * 0x10000;
set_mario_anim_with_accel(m, MARIO_ANIM_CLIMB_UP_POLE, sp24);
add_tree_leaf_particles(m);
@@ -231,12 +262,15 @@ s32 act_climbing_pole(struct MarioState *m) {
return FALSE;
}
-s32 act_grab_pole_slow(struct MarioState *m) {
+s32 act_grab_pole_slow(struct MarioState *m)
+{
play_sound_if_no_flag(m, SOUND_MARIO_WHOA, MARIO_MARIO_SOUND_PLAYED);
- if (set_pole_position(m, 0.0f) == POLE_NONE) {
+ if (set_pole_position(m, 0.0f) == POLE_NONE)
+ {
set_mario_animation(m, MARIO_ANIM_GRAB_POLE_SHORT);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_action(m, ACT_HOLDING_POLE, 0);
}
add_tree_leaf_particles(m);
@@ -245,19 +279,25 @@ s32 act_grab_pole_slow(struct MarioState *m) {
return FALSE;
}
-s32 act_grab_pole_fast(struct MarioState *m) {
+s32 act_grab_pole_fast(struct MarioState *m)
+{
struct Object *marioObj = m->marioObj;
play_sound_if_no_flag(m, SOUND_MARIO_WHOA, MARIO_MARIO_SOUND_PLAYED);
m->faceAngle[1] += marioObj->oMarioPoleYawVel;
marioObj->oMarioPoleYawVel = marioObj->oMarioPoleYawVel * 8 / 10;
- if (set_pole_position(m, 0.0f) == POLE_NONE) {
- if (marioObj->oMarioPoleYawVel > 0x800) {
+ if (set_pole_position(m, 0.0f) == POLE_NONE)
+ {
+ if (marioObj->oMarioPoleYawVel > 0x800)
+ {
set_mario_animation(m, MARIO_ANIM_GRAB_POLE_SWING_PART1);
- } else {
+ }
+ else
+ {
set_mario_animation(m, MARIO_ANIM_GRAB_POLE_SWING_PART2);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
marioObj->oMarioPoleYawVel = 0;
set_mario_action(m, ACT_HOLDING_POLE, 0);
}
@@ -268,18 +308,24 @@ s32 act_grab_pole_fast(struct MarioState *m) {
return FALSE;
}
-s32 act_top_of_pole_transition(struct MarioState *m) {
+s32 act_top_of_pole_transition(struct MarioState *m)
+{
struct Object *marioObj = m->marioObj;
marioObj->oMarioPoleYawVel = 0;
- if (m->actionArg == 0) {
+ if (m->actionArg == 0)
+ {
set_mario_animation(m, MARIO_ANIM_START_HANDSTAND);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
return set_mario_action(m, ACT_TOP_OF_POLE, 0);
}
- } else {
+ }
+ else
+ {
set_mario_animation(m, MARIO_ANIM_RETURN_FROM_HANDSTAND);
- if (m->marioObj->header.gfx.animInfo.animFrame == 0) {
+ if (m->marioObj->header.gfx.animInfo.animFrame == 0)
+ {
return set_mario_action(m, ACT_HOLDING_POLE, 0);
}
}
@@ -288,13 +334,17 @@ s32 act_top_of_pole_transition(struct MarioState *m) {
return FALSE;
}
-s32 act_top_of_pole(struct MarioState *m) {
- UNUSED struct Object *marioObj = m->marioObj;
+s32 act_top_of_pole(struct MarioState *m)
+{
+ UNUSED
+ struct Object *marioObj = m->marioObj;
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_mario_action(m, ACT_TOP_OF_POLE_JUMP, 0);
}
- if (m->controller->stickY < -16.0f) {
+ if (m->controller->stickY < -16.0f)
+ {
return set_mario_action(m, ACT_TOP_OF_POLE_TRANSITION, 1);
}
@@ -305,7 +355,8 @@ s32 act_top_of_pole(struct MarioState *m) {
return FALSE;
}
-s32 perform_hanging_step(struct MarioState *m, Vec3f nextPos) {
+s32 perform_hanging_step(struct MarioState *m, Vec3f nextPos)
+{
UNUSED s32 unused;
struct SM64SurfaceCollisionData *ceil;
struct SM64SurfaceCollisionData *floor;
@@ -317,24 +368,30 @@ s32 perform_hanging_step(struct MarioState *m, Vec3f nextPos) {
floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor);
ceilHeight = vec3f_find_ceil(nextPos, floorHeight, &ceil);
- if (floor == NULL) {
+ if (floor == NULL)
+ {
return HANG_HIT_CEIL_OR_OOB;
}
- if (ceil == NULL) {
+ if (ceil == NULL)
+ {
return HANG_LEFT_CEIL;
}
- if (ceilHeight - floorHeight <= 160.0f) {
+ if (ceilHeight - floorHeight <= 160.0f)
+ {
return HANG_HIT_CEIL_OR_OOB;
}
- if (ceil->type != SURFACE_HANGABLE) {
+ if (ceil->type != SURFACE_HANGABLE)
+ {
return HANG_LEFT_CEIL;
}
ceilOffset = ceilHeight - (nextPos[1] + 160.0f);
- if (ceilOffset < -30.0f) {
+ if (ceilOffset < -30.0f)
+ {
return HANG_HIT_CEIL_OR_OOB;
}
- if (ceilOffset > 30.0f) {
+ if (ceilOffset > 30.0f)
+ {
return HANG_LEFT_CEIL;
}
@@ -349,18 +406,20 @@ s32 perform_hanging_step(struct MarioState *m, Vec3f nextPos) {
return HANG_NONE;
}
-s32 update_hang_moving(struct MarioState *m) {
+s32 update_hang_moving(struct MarioState *m)
+{
s32 stepResult;
Vec3f nextPos;
f32 maxSpeed = 4.0f;
m->forwardVel += 1.0f;
- if (m->forwardVel > maxSpeed) {
+ if (m->forwardVel > maxSpeed)
+ {
m->forwardVel = maxSpeed;
}
m->faceAngle[1] =
- m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x800, 0x800);
+ m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x800, 0x800);
m->slideYaw = m->faceAngle[1];
m->slideVelX = m->forwardVel * sins(m->faceAngle[1]);
@@ -381,7 +440,8 @@ s32 update_hang_moving(struct MarioState *m) {
return stepResult;
}
-void update_hang_stationary(struct MarioState *m) {
+void update_hang_stationary(struct MarioState *m)
+{
m->forwardVel = 0.0f;
m->slideVelX = 0.0f;
m->slideVelZ = 0.0f;
@@ -391,28 +451,34 @@ void update_hang_stationary(struct MarioState *m) {
vec3f_copy(m->marioObj->header.gfx.pos, m->pos);
}
-s32 act_start_hanging(struct MarioState *m) {
-#ifdef VERSION_SH
- if (m->actionTimer++ == 0) {
+s32 act_start_hanging(struct MarioState *m)
+{
+ #ifdef VERSION_SH
+ if (m->actionTimer++ == 0)
+ {
queue_rumble_data(5, 80);
}
-#else
+ #else
m->actionTimer++;
-#endif
+ #endif
- if ((m->input & INPUT_NONZERO_ANALOG) && m->actionTimer >= 31) {
+ if (m->input & INPUT_NONZERO_ANALOG && m->actionTimer >= 31)
+ {
return set_mario_action(m, ACT_HANGING, 0);
}
- if (!(m->input & INPUT_A_DOWN)) {
+ if (!(m->input & INPUT_A_DOWN))
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->input & INPUT_Z_PRESSED) {
+ if (m->input & INPUT_Z_PRESSED)
+ {
return set_mario_action(m, ACT_GROUND_POUND, 0);
}
- if (m->ceil == NULL || m->ceil->type != SURFACE_HANGABLE) {
+ if (m->ceil == NULL || m->ceil->type != SURFACE_HANGABLE)
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
@@ -420,33 +486,42 @@ s32 act_start_hanging(struct MarioState *m) {
play_sound_if_no_flag(m, SOUND_ACTION_HANGING_STEP, MARIO_ACTION_SOUND_PLAYED);
update_hang_stationary(m);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_action(m, ACT_HANGING, 0);
}
return FALSE;
}
-s32 act_hanging(struct MarioState *m) {
- if (m->input & INPUT_NONZERO_ANALOG) {
+s32 act_hanging(struct MarioState *m)
+{
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
return set_mario_action(m, ACT_HANG_MOVING, m->actionArg);
}
- if (!(m->input & INPUT_A_DOWN)) {
+ if (!(m->input & INPUT_A_DOWN))
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->input & INPUT_Z_PRESSED) {
+ if (m->input & INPUT_Z_PRESSED)
+ {
return set_mario_action(m, ACT_GROUND_POUND, 0);
}
- if (m->ceil == NULL || m->ceil->type != SURFACE_HANGABLE) {
+ if (m->ceil == NULL || m->ceil->type != SURFACE_HANGABLE)
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->actionArg & 1) {
+ if (m->actionArg & 1)
+ {
set_mario_animation(m, MARIO_ANIM_HANDSTAND_LEFT);
- } else {
+ }
+ else
+ {
set_mario_animation(m, MARIO_ANIM_HANDSTAND_RIGHT);
}
@@ -455,47 +530,59 @@ s32 act_hanging(struct MarioState *m) {
return FALSE;
}
-s32 act_hang_moving(struct MarioState *m) {
- if (!(m->input & INPUT_A_DOWN)) {
+s32 act_hang_moving(struct MarioState *m)
+{
+ if (!(m->input & INPUT_A_DOWN))
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->input & INPUT_Z_PRESSED) {
+ if (m->input & INPUT_Z_PRESSED)
+ {
return set_mario_action(m, ACT_GROUND_POUND, 0);
}
- if (m->ceil == NULL || m->ceil->type != SURFACE_HANGABLE) {
+ if (m->ceil == NULL || m->ceil->type != SURFACE_HANGABLE)
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->actionArg & 1) {
+ if (m->actionArg & 1)
+ {
set_mario_animation(m, MARIO_ANIM_MOVE_ON_WIRE_NET_RIGHT);
- } else {
+ }
+ else
+ {
set_mario_animation(m, MARIO_ANIM_MOVE_ON_WIRE_NET_LEFT);
}
- if (m->marioObj->header.gfx.animInfo.animFrame == 12) {
+ if (m->marioObj->header.gfx.animInfo.animFrame == 12)
+ {
play_sound(SOUND_ACTION_HANGING_STEP, m->marioObj->header.gfx.cameraToObject);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
queue_rumble_data(5, 30);
-#endif
+ #endif
}
- if (is_anim_past_end(m)) {
+ if (is_anim_past_end(m))
+ {
m->actionArg ^= 1;
- if (m->input & INPUT_UNKNOWN_5) {
+ if (m->input & INPUT_UNKNOWN_5)
+ {
return set_mario_action(m, ACT_HANGING, m->actionArg);
}
}
- if (update_hang_moving(m) == HANG_LEFT_CEIL) {
+ if (update_hang_moving(m) == HANG_LEFT_CEIL)
+ {
set_mario_action(m, ACT_FREEFALL, 0);
}
return FALSE;
}
-s32 let_go_of_ledge(struct MarioState *m) {
+s32 let_go_of_ledge(struct MarioState *m)
+{
f32 floorHeight;
struct SM64SurfaceCollisionData *floor;
@@ -505,98 +592,119 @@ s32 let_go_of_ledge(struct MarioState *m) {
m->pos[2] -= 60.0f * coss(m->faceAngle[1]);
floorHeight = find_floor(m->pos[0], m->pos[1], m->pos[2], &floor);
- if (floorHeight < m->pos[1] - 100.0f) {
+ if (floorHeight < m->pos[1] - 100.0f)
+ {
m->pos[1] -= 100.0f;
- } else {
+ }
+ else
+ {
m->pos[1] = floorHeight;
}
return set_mario_action(m, ACT_SOFT_BONK, 0);
}
-void climb_up_ledge(struct MarioState *m) {
+void climb_up_ledge(struct MarioState *m)
+{
set_mario_animation(m, MARIO_ANIM_IDLE_HEAD_LEFT);
m->pos[0] += 14.0f * sins(m->faceAngle[1]);
m->pos[2] += 14.0f * coss(m->faceAngle[1]);
vec3f_copy(m->marioObj->header.gfx.pos, m->pos);
}
-void update_ledge_climb_camera(struct MarioState *m) {
-// f32 sp4;
+void update_ledge_climb_camera(struct MarioState *m)
+{
+ // f32 sp4;
-// if (m->actionTimer < 14) {
-// sp4 = m->actionTimer;
-// } else {
-// sp4 = 14.0f;
-// }
-// m->statusForCamera->pos[0] = m->pos[0] + sp4 * sins(m->faceAngle[1]);
-// m->statusForCamera->pos[2] = m->pos[2] + sp4 * coss(m->faceAngle[1]);
-// m->statusForCamera->pos[1] = m->pos[1];
-// m->actionTimer++;
-// m->flags |= MARIO_UNKNOWN_25;
+ // if (m->actionTimer < 14) {
+ // sp4 = m->actionTimer;
+ // } else {
+ // sp4 = 14.0f;
+ // }
+ // m->statusForCamera->pos[0] = m->pos[0] + sp4 * sins(m->faceAngle[1]);
+ // m->statusForCamera->pos[2] = m->pos[2] + sp4 * coss(m->faceAngle[1]);
+ // m->statusForCamera->pos[1] = m->pos[1];
+ // m->actionTimer++;
+ // m->flags |= MARIO_UNKNOWN_25;
}
-void update_ledge_climb(struct MarioState *m, s32 animation, u32 endAction) {
+void update_ledge_climb(struct MarioState *m, s32 animation, u32 endAction)
+{
stop_and_set_height_to_floor(m);
set_mario_animation(m, animation);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_action(m, endAction, 0);
- if (endAction == ACT_IDLE) {
+ if (endAction == ACT_IDLE)
+ {
climb_up_ledge(m);
}
}
}
-s32 act_ledge_grab(struct MarioState *m) {
+s32 act_ledge_grab(struct MarioState *m)
+{
f32 heightAboveFloor;
s16 intendedDYaw = m->intendedYaw - m->faceAngle[1];
- s32 hasSpaceForMario = (m->ceilHeight - m->floorHeight >= 160.0f);
+ s32 hasSpaceForMario = m->ceilHeight - m->floorHeight >= 160.0f;
- if (m->actionTimer < 10) {
+ if (m->actionTimer < 10)
+ {
m->actionTimer++;
}
- if (m->floor->normal.y < 0.9063078f) {
+ if (m->floor->normal.y < 0.9063078f)
+ {
return let_go_of_ledge(m);
}
- if (m->input & (INPUT_Z_PRESSED | INPUT_OFF_FLOOR)) {
+ if (m->input & (INPUT_Z_PRESSED | INPUT_OFF_FLOOR))
+ {
return let_go_of_ledge(m);
}
- if ((m->input & INPUT_A_PRESSED) && hasSpaceForMario) {
+ if (m->input & INPUT_A_PRESSED && hasSpaceForMario)
+ {
return set_mario_action(m, ACT_LEDGE_CLIMB_FAST, 0);
}
- if (m->input & INPUT_UNKNOWN_10) {
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_UNK1) {
- m->hurtCounter += (m->flags & MARIO_CAP_ON_HEAD) ? 12 : 18;
+ if (m->input & INPUT_UNKNOWN_10)
+ {
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_UNK1)
+ {
+ m->hurtCounter += m->flags & MARIO_CAP_ON_HEAD ? 12 : 18;
}
return let_go_of_ledge(m);
}
-#ifdef VERSION_EU
+ #ifdef VERSION_EU
// On EU, you can't slow climb up ledges while holding A.
if (m->actionTimer == 10 && (m->input & INPUT_NONZERO_ANALOG) && !(m->input & INPUT_A_DOWN))
-#else
- if (m->actionTimer == 10 && (m->input & INPUT_NONZERO_ANALOG))
-#endif
+ #else
+ if (m->actionTimer == 10 && m->input & INPUT_NONZERO_ANALOG)
+ #endif
{
- if (intendedDYaw >= -0x4000 && intendedDYaw <= 0x4000) {
- if (hasSpaceForMario) {
+ if (intendedDYaw >= -0x4000 && intendedDYaw <= 0x4000)
+ {
+ if (hasSpaceForMario)
+ {
return set_mario_action(m, ACT_LEDGE_CLIMB_SLOW_1, 0);
}
- } else {
+ }
+ else
+ {
return let_go_of_ledge(m);
}
}
heightAboveFloor = m->pos[1] - find_floor_height_relative_polar(m, -0x8000, 30.0f);
- if (hasSpaceForMario && heightAboveFloor < 100.0f) {
+ if (hasSpaceForMario && heightAboveFloor < 100.0f)
+ {
return set_mario_action(m, ACT_LEDGE_CLIMB_FAST, 0);
}
- if (m->actionArg == 0) {
+ if (m->actionArg == 0)
+ {
play_sound_if_no_flag(m, SOUND_MARIO_WHOA, MARIO_MARIO_SOUND_PLAYED);
}
@@ -606,36 +714,43 @@ s32 act_ledge_grab(struct MarioState *m) {
return FALSE;
}
-s32 act_ledge_climb_slow(struct MarioState *m) {
- if (m->input & INPUT_OFF_FLOOR) {
+s32 act_ledge_climb_slow(struct MarioState *m)
+{
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return let_go_of_ledge(m);
}
m->actionTimer++;
if (m->actionTimer >= 28
- && (m->input
- & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE))) {
+ && m->input
+ & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE))
+ {
climb_up_ledge(m);
return check_common_action_exits(m);
}
- if (m->actionTimer == 10) {
+ if (m->actionTimer == 10)
+ {
play_sound_if_no_flag(m, SOUND_MARIO_EEUH, MARIO_MARIO_SOUND_PLAYED);
}
update_ledge_climb(m, MARIO_ANIM_SLOW_LEDGE_GRAB, ACT_IDLE);
update_ledge_climb_camera(m);
- if (m->marioObj->header.gfx.animInfo.animFrame == 17) {
+ if (m->marioObj->header.gfx.animInfo.animFrame == 17)
+ {
m->action = ACT_LEDGE_CLIMB_SLOW_2;
}
return FALSE;
}
-s32 act_ledge_climb_down(struct MarioState *m) {
- if (m->input & INPUT_OFF_FLOOR) {
+s32 act_ledge_climb_down(struct MarioState *m)
+{
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return let_go_of_ledge(m);
}
@@ -647,8 +762,10 @@ s32 act_ledge_climb_down(struct MarioState *m) {
return FALSE;
}
-s32 act_ledge_climb_fast(struct MarioState *m) {
- if (m->input & INPUT_OFF_FLOOR) {
+s32 act_ledge_climb_fast(struct MarioState *m)
+{
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return let_go_of_ledge(m);
}
@@ -656,7 +773,8 @@ s32 act_ledge_climb_fast(struct MarioState *m) {
update_ledge_climb(m, MARIO_ANIM_FAST_LEDGE_GRAB, ACT_IDLE);
- if (m->marioObj->header.gfx.animInfo.animFrame == 8) {
+ if (m->marioObj->header.gfx.animInfo.animFrame == 8)
+ {
play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
}
update_ledge_climb_camera(m);
@@ -664,17 +782,19 @@ s32 act_ledge_climb_fast(struct MarioState *m) {
return FALSE;
}
-s32 act_grabbed(struct MarioState *m) {
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_UNK2) {
+s32 act_grabbed(struct MarioState *m)
+{
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_UNK2)
+ {
s32 thrown = (m->marioObj->oInteractStatus & INT_STATUS_MARIO_UNK6) == 0;
m->faceAngle[1] = m->usedObj->oMoveAngleYaw;
vec3f_copy(m->pos, m->marioObj->header.gfx.pos);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
queue_rumble_data(5, 60);
-#endif
+ #endif
- return set_mario_action(m, (m->forwardVel >= 0.0f) ? ACT_THROWN_FORWARD : ACT_THROWN_BACKWARD,
+ return set_mario_action(m, m->forwardVel >= 0.0f ? ACT_THROWN_FORWARD : ACT_THROWN_BACKWARD,
thrown);
}
@@ -682,18 +802,20 @@ s32 act_grabbed(struct MarioState *m) {
return FALSE;
}
-s32 act_in_cannon(struct MarioState *m) {
+s32 act_in_cannon(struct MarioState *m)
+{
struct Object *marioObj = m->marioObj;
s16 startFacePitch = m->faceAngle[0];
s16 startFaceYaw = m->faceAngle[1];
- switch (m->actionState) {
+ switch (m->actionState)
+ {
case 0:
m->marioObj->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE;
m->usedObj->oInteractStatus = INT_STATUS_INTERACTED;
-// m->statusForCamera->cameraEvent = CAM_EVENT_CANNON;
-// m->statusForCamera->usedObj = m->usedObj;
+ // m->statusForCamera->cameraEvent = CAM_EVENT_CANNON;
+ // m->statusForCamera->usedObj = m->usedObj;
vec3f_set(m->vel, 0.0f, 0.0f, 0.0f);
@@ -707,7 +829,8 @@ s32 act_in_cannon(struct MarioState *m) {
break;
case 1:
- if (m->usedObj->oAction == 1) {
+ if (m->usedObj->oAction == 1)
+ {
m->faceAngle[0] = m->usedObj->oMoveAnglePitch;
m->faceAngle[1] = m->usedObj->oMoveAngleYaw;
@@ -722,22 +845,27 @@ s32 act_in_cannon(struct MarioState *m) {
m->faceAngle[0] -= (s16)(m->controller->stickY * 10.0f);
marioObj->oMarioCannonInputYaw -= (s16)(m->controller->stickX * 10.0f);
- if (m->faceAngle[0] > 0x38E3) {
+ if (m->faceAngle[0] > 0x38E3)
+ {
m->faceAngle[0] = 0x38E3;
}
- if (m->faceAngle[0] < 0) {
+ if (m->faceAngle[0] < 0)
+ {
m->faceAngle[0] = 0;
}
- if (marioObj->oMarioCannonInputYaw > 0x4000) {
+ if (marioObj->oMarioCannonInputYaw > 0x4000)
+ {
marioObj->oMarioCannonInputYaw = 0x4000;
}
- if (marioObj->oMarioCannonInputYaw < -0x4000) {
+ if (marioObj->oMarioCannonInputYaw < -0x4000)
+ {
marioObj->oMarioCannonInputYaw = -0x4000;
}
m->faceAngle[1] = marioObj->oMarioCannonObjectYaw + marioObj->oMarioCannonInputYaw;
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
m->forwardVel = 100.0f * coss(m->faceAngle[0]);
m->vel[1] = 100.0f * sins(m->faceAngle[0]);
@@ -752,16 +880,18 @@ s32 act_in_cannon(struct MarioState *m) {
m->marioObj->header.gfx.node.flags |= GRAPH_RENDER_ACTIVE;
set_mario_action(m, ACT_SHOT_FROM_CANNON, 0);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
queue_rumble_data(60, 70);
-#endif
+ #endif
m->usedObj->oAction = 2;
return FALSE;
- } else if (m->faceAngle[0] != startFacePitch || m->faceAngle[1] != startFaceYaw) {
+ }
+ else if (m->faceAngle[0] != startFacePitch || m->faceAngle[1] != startFaceYaw)
+ {
play_sound(SOUND_MOVING_AIM_CANNON, m->marioObj->header.gfx.cameraToObject);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
reset_rumble_timers_2(0);
-#endif
+ #endif
}
}
@@ -772,7 +902,8 @@ s32 act_in_cannon(struct MarioState *m) {
return FALSE;
}
-s32 act_tornado_twirling(struct MarioState *m) {
+s32 act_tornado_twirling(struct MarioState *m)
+{
struct SM64SurfaceCollisionData *floor;
Vec3f nextPos;
f32 sinAngleVel;
@@ -785,25 +916,31 @@ s32 act_tornado_twirling(struct MarioState *m) {
f32 dx = (m->pos[0] - usedObj->oPosX) * 0.95f;
f32 dz = (m->pos[2] - usedObj->oPosZ) * 0.95f;
- if (m->vel[1] < 60.0f) {
+ if (m->vel[1] < 60.0f)
+ {
m->vel[1] += 1.0f;
}
- if ((marioObj->oMarioTornadoPosY += m->vel[1]) < 0.0f) {
+ if ((marioObj->oMarioTornadoPosY += m->vel[1]) < 0.0f)
+ {
marioObj->oMarioTornadoPosY = 0.0f;
}
- if (marioObj->oMarioTornadoPosY > usedObj->hitboxHeight) {
- if (m->vel[1] < 20.0f) {
+ if (marioObj->oMarioTornadoPosY > usedObj->hitboxHeight)
+ {
+ if (m->vel[1] < 20.0f)
+ {
m->vel[1] = 20.0f;
}
return set_mario_action(m, ACT_TWIRLING, 1);
}
- if (m->angleVel[1] < 0x3000) {
+ if (m->angleVel[1] < 0x3000)
+ {
m->angleVel[1] += 0x100;
}
- if (marioObj->oMarioTornadoYawVel < 0x1000) {
+ if (marioObj->oMarioTornadoYawVel < 0x1000)
+ {
marioObj->oMarioTornadoYawVel += 0x100;
}
@@ -819,52 +956,64 @@ s32 act_tornado_twirling(struct MarioState *m) {
f32_find_wall_collision(&nextPos[0], &nextPos[1], &nextPos[2], 60.0f, 50.0f);
floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor);
- if (floor != NULL) {
+ if (floor != NULL)
+ {
m->floor = floor;
m->floorHeight = floorHeight;
vec3f_copy(m->pos, nextPos);
- } else {
- if (nextPos[1] >= m->floorHeight) {
+ }
+ else
+ {
+ if (nextPos[1] >= m->floorHeight)
+ {
m->pos[1] = nextPos[1];
- } else {
+ }
+ else
+ {
m->pos[1] = m->floorHeight;
}
}
m->actionTimer++;
- set_mario_animation(m, (m->actionArg == 0) ? MARIO_ANIM_START_TWIRL : MARIO_ANIM_TWIRL);
+ set_mario_animation(m, m->actionArg == 0 ? MARIO_ANIM_START_TWIRL : MARIO_ANIM_TWIRL);
- if (is_anim_past_end(m)) {
+ if (is_anim_past_end(m))
+ {
m->actionArg = 1;
}
// Play sound on angle overflow
- if (prevTwirlYaw > m->twirlYaw) {
+ if (prevTwirlYaw > m->twirlYaw)
+ {
play_sound(SOUND_ACTION_TWIRL, m->marioObj->header.gfx.cameraToObject);
}
vec3f_copy(m->marioObj->header.gfx.pos, m->pos);
vec3s_set(m->marioObj->header.gfx.angle, 0, m->faceAngle[1] + m->twirlYaw, 0);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
reset_rumble_timers();
-#endif
+ #endif
return FALSE;
}
-s32 check_common_automatic_cancels(struct MarioState *m) {
- if (m->pos[1] < m->waterLevel - 100) {
+s32 check_common_automatic_cancels(struct MarioState *m)
+{
+ if (m->pos[1] < m->waterLevel - 100)
+ {
return set_water_plunge_action(m);
}
return FALSE;
}
-s32 mario_execute_automatic_action(struct MarioState *m) {
+s32 mario_execute_automatic_action(struct MarioState *m)
+{
s32 cancel;
- if (check_common_automatic_cancels(m)) {
+ if (check_common_automatic_cancels(m))
+ {
return TRUE;
}
diff --git a/src/decomp/game/mario_actions_cutscene.c b/src/decomp/game/mario_actions_cutscene.c
index 1eecf0b..53dccc8 100644
--- a/src/decomp/game/mario_actions_cutscene.c
+++ b/src/decomp/game/mario_actions_cutscene.c
@@ -37,7 +37,6 @@
#include "../include/mario_geo_switch_case_ids.h"
-
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
@@ -51,12 +50,11 @@
#define GFX_DIMENSIONS_FULL_RADIUS (SCREEN_HEIGHT * (GFX_DIMENSIONS_ASPECT_RATIO > 1 ? GFX_DIMENSIONS_ASPECT_RATIO : 1))
-
-
-
-
// TODO: put this elsewhere
-enum SaveOption { SAVE_OPT_SAVE_AND_CONTINUE = 1, SAVE_OPT_SAVE_AND_QUIT, SAVE_OPT_CONTINUE_DONT_SAVE };
+enum SaveOption
+{
+ SAVE_OPT_SAVE_AND_CONTINUE = 1, SAVE_OPT_SAVE_AND_QUIT, SAVE_OPT_CONTINUE_DONT_SAVE
+};
static struct Object *sIntroWarpPipeObj;
static struct Object *sEndPeachObj;
@@ -67,7 +65,7 @@ static UNUSED s32 sUnused;
static s16 sEndPeachAnimation;
//static s16 sEndToadAnims[2];
-static Vp sEndCutsceneVp = { { { 640, 480, 511, 0 }, { 640, 480, 511, 0 } } };
+static Vp sEndCutsceneVp = {{{640, 480, 511, 0}, {640, 480, 511, 0}}};
//static struct CreditsEntry *sDispCreditsEntry = NULL;
// related to peach gfx?
@@ -88,15 +86,15 @@ static Vp sEndCutsceneVp = { { { 640, 480, 511, 0 }, { 640, 480, 511, 0 } } };
* that define the curve.
*/
static Vec4s sJumboStarKeyframes[27] = {
- { 20, 0, 678, -2916 }, { 30, 0, 680, -3500 }, { 40, 1000, 700, -4000 },
- { 50, 2500, 750, -3500 }, { 50, 3500, 800, -2000 }, { 50, 4000, 850, 0 },
- { 50, 3500, 900, 2000 }, { 50, 2000, 950, 3500 }, { 50, 0, 1000, 4000 },
- { 50, -2000, 1050, 3500 }, { 50, -3500, 1100, 2000 }, { 50, -4000, 1150, 0 },
- { 50, -3500, 1200, -2000 }, { 50, -2000, 1250, -3500 }, { 50, 0, 1300, -4000 },
- { 50, 2000, 1350, -3500 }, { 50, 3500, 1400, -2000 }, { 50, 4000, 1450, 0 },
- { 50, 3500, 1500, 2000 }, { 50, 2000, 1600, 3500 }, { 50, 0, 1700, 4000 },
- { 50, -2000, 1800, 3500 }, { 50, -3500, 1900, 2000 }, { 30, -4000, 2000, 0 },
- { 0, -3500, 2100, -2000 }, { 0, -2000, 2200, -3500 }, { 0, 0, 2300, -4000 },
+ {20, 0, 678, -2916}, {30, 0, 680, -3500}, {40, 1000, 700, -4000},
+ {50, 2500, 750, -3500}, {50, 3500, 800, -2000}, {50, 4000, 850, 0},
+ {50, 3500, 900, 2000}, {50, 2000, 950, 3500}, {50, 0, 1000, 4000},
+ {50, -2000, 1050, 3500}, {50, -3500, 1100, 2000}, {50, -4000, 1150, 0},
+ {50, -3500, 1200, -2000}, {50, -2000, 1250, -3500}, {50, 0, 1300, -4000},
+ {50, 2000, 1350, -3500}, {50, 3500, 1400, -2000}, {50, 4000, 1450, 0},
+ {50, 3500, 1500, 2000}, {50, 2000, 1600, 3500}, {50, 0, 1700, 4000},
+ {50, -2000, 1800, 3500}, {50, -3500, 1900, 2000}, {30, -4000, 2000, 0},
+ {0, -3500, 2100, -2000}, {0, -2000, 2200, -3500}, {0, 0, 2300, -4000},
};
/**
@@ -106,12 +104,14 @@ static Vec4s sJumboStarKeyframes[27] = {
* character is a null character (equal to 0), stop counting the length since
* that's the end of the string.
*/
-s32 get_credits_str_width(char *str) {
+s32 get_credits_str_width(char *str)
+{
u32 c;
s32 length = 0;
- while ((c = *str++) != 0) {
- length += (c == ' ' ? 4 : 7);
+ while ((c = *str++) != 0)
+ {
+ length += c == ' ' ? 4 : 7;
}
return length;
@@ -135,109 +135,113 @@ s32 get_credits_str_width(char *str) {
* as a counter, and increase the Y value by either the constant 16 (JP only) or
* by the value of lineHeight.
*/
-void print_displaying_credits_entry(void) {
-// char **currStrPtr;
-// char *titleStr;
-// s16 numLines;
-// s16 strY;
-//#ifndef VERSION_JP
-// s16 lineHeight;
-//#endif
-//
-// if (sDispCreditsEntry != NULL) {
-// currStrPtr = (char **) sDispCreditsEntry->unk0C;
-// titleStr = *currStrPtr++;
-// numLines = *titleStr++ - '0';
-//
-// strY = (sDispCreditsEntry->unk02 & 0x20 ? 28 : 172) + (numLines == 1) * 16;
-//#ifndef VERSION_JP
-// lineHeight = 16;
-//#endif
-//
-// dl_rgba16_begin_cutscene_msg_fade();
-// print_credits_str_ascii(CREDIT_TEXT_X_LEFT, strY, titleStr);
-//
-//#ifndef VERSION_JP
-// switch (numLines) {
-// case 4:
-// print_credits_str_ascii(CREDIT_TEXT_X_LEFT, strY + 24, *currStrPtr++);
-// numLines = 2;
-// lineHeight = 24;
-// break;
-// case 5:
-// print_credits_str_ascii(CREDIT_TEXT_X_LEFT, strY + 16, *currStrPtr++);
-// numLines = 3;
-// break;
-//#ifdef VERSION_EU
-// case 6:
-// print_credits_str_ascii(CREDIT_TEXT_X_LEFT, strY + 32, *currStrPtr++);
-// numLines = 3;
-// break;
-// case 7:
-// print_credits_str_ascii(CREDIT_TEXT_X_LEFT, strY + 16, *currStrPtr++);
-// print_credits_str_ascii(CREDIT_TEXT_X_LEFT, strY + 32, *currStrPtr++);
-// numLines = 3;
-// break;
-//#endif
-// }
-//#endif
-//
-// while (numLines-- > 0) {
-// print_credits_str_ascii(CREDIT_TEXT_X_RIGHT - get_credits_str_width(*currStrPtr), strY, *currStrPtr);
-//
-//#ifdef VERSION_JP
-// strY += 16;
-//#else
-// strY += lineHeight;
-//#endif
-//
-// currStrPtr++;
-// }
-//
-//// dl_rgba16_stop_cutscene_msg_fade();
-// sDispCreditsEntry = NULL;
-// }
+void print_displaying_credits_entry(void)
+{
+ // char **currStrPtr;
+ // char *titleStr;
+ // s16 numLines;
+ // s16 strY;
+ //#ifndef VERSION_JP
+ // s16 lineHeight;
+ //#endif
+ //
+ // if (sDispCreditsEntry != NULL) {
+ // currStrPtr = (char **) sDispCreditsEntry->unk0C;
+ // titleStr = *currStrPtr++;
+ // numLines = *titleStr++ - '0';
+ //
+ // strY = (sDispCreditsEntry->unk02 & 0x20 ? 28 : 172) + (numLines == 1) * 16;
+ //#ifndef VERSION_JP
+ // lineHeight = 16;
+ //#endif
+ //
+ // dl_rgba16_begin_cutscene_msg_fade();
+ // print_credits_str_ascii(CREDIT_TEXT_X_LEFT, strY, titleStr);
+ //
+ //#ifndef VERSION_JP
+ // switch (numLines) {
+ // case 4:
+ // print_credits_str_ascii(CREDIT_TEXT_X_LEFT, strY + 24, *currStrPtr++);
+ // numLines = 2;
+ // lineHeight = 24;
+ // break;
+ // case 5:
+ // print_credits_str_ascii(CREDIT_TEXT_X_LEFT, strY + 16, *currStrPtr++);
+ // numLines = 3;
+ // break;
+ //#ifdef VERSION_EU
+ // case 6:
+ // print_credits_str_ascii(CREDIT_TEXT_X_LEFT, strY + 32, *currStrPtr++);
+ // numLines = 3;
+ // break;
+ // case 7:
+ // print_credits_str_ascii(CREDIT_TEXT_X_LEFT, strY + 16, *currStrPtr++);
+ // print_credits_str_ascii(CREDIT_TEXT_X_LEFT, strY + 32, *currStrPtr++);
+ // numLines = 3;
+ // break;
+ //#endif
+ // }
+ //#endif
+ //
+ // while (numLines-- > 0) {
+ // print_credits_str_ascii(CREDIT_TEXT_X_RIGHT - get_credits_str_width(*currStrPtr), strY, *currStrPtr);
+ //
+ //#ifdef VERSION_JP
+ // strY += 16;
+ //#else
+ // strY += lineHeight;
+ //#endif
+ //
+ // currStrPtr++;
+ // }
+ //
+ //// dl_rgba16_stop_cutscene_msg_fade();
+ // sDispCreditsEntry = NULL;
+ // }
}
-void bhv_end_peach_loop(void) {
-// cur_obj_init_animation_with_sound(sEndPeachAnimation);
-// if (cur_obj_check_if_near_animation_end()) {
-// // anims: 0-3, 4, 5, 6-8, 9, 10, 11
-// if (sEndPeachAnimation < 3 || sEndPeachAnimation == 6 || sEndPeachAnimation == 7) {
-// sEndPeachAnimation++;
-// }
-// }
+void bhv_end_peach_loop(void)
+{
+ // cur_obj_init_animation_with_sound(sEndPeachAnimation);
+ // if (cur_obj_check_if_near_animation_end()) {
+ // // anims: 0-3, 4, 5, 6-8, 9, 10, 11
+ // if (sEndPeachAnimation < 3 || sEndPeachAnimation == 6 || sEndPeachAnimation == 7) {
+ // sEndPeachAnimation++;
+ // }
+ // }
}
-void bhv_end_toad_loop(void) {
-// s32 toadAnimIndex = (gCurrentObject->oPosX >= 0.0f);
+void bhv_end_toad_loop(void)
+{
+ // s32 toadAnimIndex = (gCurrentObject->oPosX >= 0.0f);
-// cur_obj_init_animation_with_sound(sEndToadAnims[toadAnimIndex]);
-// if (cur_obj_check_if_near_animation_end()) {
-// // 0-1, 2-3, 4, 5, 6, 7
-// if (sEndToadAnims[toadAnimIndex] == 0 || sEndToadAnims[toadAnimIndex] == 2) {
-// sEndToadAnims[toadAnimIndex]++;
-// }
-// }
+ // cur_obj_init_animation_with_sound(sEndToadAnims[toadAnimIndex]);
+ // if (cur_obj_check_if_near_animation_end()) {
+ // // 0-1, 2-3, 4, 5, 6, 7
+ // if (sEndToadAnims[toadAnimIndex] == 0 || sEndToadAnims[toadAnimIndex] == 2) {
+ // sEndToadAnims[toadAnimIndex]++;
+ // }
+ // }
}
// Geo switch case function for controlling Peach's eye state.
-s32 geo_switch_peach_eyes(s32 run, struct GraphNode *node, UNUSED s32 a2) {
-// struct GraphNodeSwitchCase *switchCase = (struct GraphNodeSwitchCase *) node;
-// s16 timer;
+s32 geo_switch_peach_eyes(s32 run, struct GraphNode *node, UNUSED s32 a2)
+{
+ // struct GraphNodeSwitchCase *switchCase = (struct GraphNodeSwitchCase *) node;
+ // s16 timer;
-// if (run == TRUE) {
-// if (D_8032CBE4 == 0) {
-// timer = (gAreaUpdateCounter + 0x20) >> 1 & 0x1F;
-// if (timer < 7) {
-// switchCase->selectedCase = D_8032CBE8 * 4 + D_8032CBEC[timer];
-// } else {
-// switchCase->selectedCase = D_8032CBE8 * 4 + 1;
-// }
-// } else {
-// switchCase->selectedCase = D_8032CBE8 * 4 + D_8032CBE4 - 1;
-// }
-// }
+ // if (run == TRUE) {
+ // if (D_8032CBE4 == 0) {
+ // timer = (gAreaUpdateCounter + 0x20) >> 1 & 0x1F;
+ // if (timer < 7) {
+ // switchCase->selectedCase = D_8032CBE8 * 4 + D_8032CBEC[timer];
+ // } else {
+ // switchCase->selectedCase = D_8032CBE8 * 4 + 1;
+ // }
+ // } else {
+ // switchCase->selectedCase = D_8032CBE8 * 4 + D_8032CBE4 - 1;
+ // }
+ // }
return 0;
}
@@ -256,53 +260,55 @@ s32 geo_switch_peach_eyes(s32 run, struct GraphNode *node, UNUSED s32 a2) {
* if so, return the dialog ID. Otherwise, return 0. A dialog is returned if
* numStars has reached a milestone and prevNumStarsForDialog has not reached it.
*/
-s32 get_star_collection_dialog(struct MarioState *m) {
-// s32 i;
-// s32 dialogID = 0;
-// s32 numStarsRequired;
+s32 get_star_collection_dialog(struct MarioState *m)
+{
+ // s32 i;
+ // s32 dialogID = 0;
+ // s32 numStarsRequired;
-// for (i = 0; i < ARRAY_COUNT(sStarsNeededForDialog); i++) {
-// numStarsRequired = sStarsNeededForDialog[i];
-// if (m->prevNumStarsForDialog < numStarsRequired && m->numStars >= numStarsRequired) {
-// dialogID = i + DIALOG_141;
-// break;
-// }
-// }
+ // for (i = 0; i < ARRAY_COUNT(sStarsNeededForDialog); i++) {
+ // numStarsRequired = sStarsNeededForDialog[i];
+ // if (m->prevNumStarsForDialog < numStarsRequired && m->numStars >= numStarsRequired) {
+ // dialogID = i + DIALOG_141;
+ // break;
+ // }
+ // }
-// m->prevNumStarsForDialog = m->numStars;
-// return dialogID;
+ // m->prevNumStarsForDialog = m->numStars;
+ // return dialogID;
return 0;
}
// save menu handler
-void handle_save_menu(struct MarioState *m) {
-// s32 dialogID;
-// // wait for the menu to show up
-// if (is_anim_past_end(m) && gSaveOptSelectIndex != 0) {
-// // save and continue / save and quit
-// if (gSaveOptSelectIndex == SAVE_OPT_SAVE_AND_CONTINUE || gSaveOptSelectIndex == SAVE_OPT_SAVE_AND_QUIT) {
-// save_file_do_save(gCurrSaveFileNum - 1);
+void handle_save_menu(struct MarioState *m)
+{
+ // s32 dialogID;
+ // // wait for the menu to show up
+ // if (is_anim_past_end(m) && gSaveOptSelectIndex != 0) {
+ // // save and continue / save and quit
+ // if (gSaveOptSelectIndex == SAVE_OPT_SAVE_AND_CONTINUE || gSaveOptSelectIndex == SAVE_OPT_SAVE_AND_QUIT) {
+ // save_file_do_save(gCurrSaveFileNum - 1);
-// if (gSaveOptSelectIndex == SAVE_OPT_SAVE_AND_QUIT) {
-// fade_into_special_warp(-2, 0); // reset game
-// }
-// }
+ // if (gSaveOptSelectIndex == SAVE_OPT_SAVE_AND_QUIT) {
+ // fade_into_special_warp(-2, 0); // reset game
+ // }
+ // }
-// // not quitting
-// if (gSaveOptSelectIndex != SAVE_OPT_SAVE_AND_QUIT) {
-// disable_time_stop();
-// m->faceAngle[1] += 0x8000;
-// // figure out what dialog to show, if we should
-// dialogID = get_star_collection_dialog(m);
-// if (dialogID != 0) {
-// play_peachs_jingle();
-// // look up for dialog
-// set_mario_action(m, ACT_READING_AUTOMATIC_DIALOG, dialogID);
-// } else {
-// set_mario_action(m, ACT_IDLE, 0);
-// }
-// }
-// }
+ // // not quitting
+ // if (gSaveOptSelectIndex != SAVE_OPT_SAVE_AND_QUIT) {
+ // disable_time_stop();
+ // m->faceAngle[1] += 0x8000;
+ // // figure out what dialog to show, if we should
+ // dialogID = get_star_collection_dialog(m);
+ // if (dialogID != 0) {
+ // play_peachs_jingle();
+ // // look up for dialog
+ // set_mario_action(m, ACT_READING_AUTOMATIC_DIALOG, dialogID);
+ // } else {
+ // set_mario_action(m, ACT_IDLE, 0);
+ // }
+ // }
+ // }
}
/**
@@ -310,15 +316,16 @@ void handle_save_menu(struct MarioState *m) {
* Spawns object with given behavior and model and copies over Mario's position
* and yaw plus relative yaw.
*/
-struct Object *spawn_obj_at_mario_rel_yaw(struct MarioState *m, s32 model, const BehaviorScript *behavior, s16 relYaw) {
-// struct Object *o = spawn_object(m->marioObj, model, behavior);
+struct Object *spawn_obj_at_mario_rel_yaw(struct MarioState *m, s32 model, const BehaviorScript *behavior, s16 relYaw)
+{
+ // struct Object *o = spawn_object(m->marioObj, model, behavior);
-// o->oFaceAngleYaw = m->faceAngle[1] + relYaw;
-// o->oPosX = m->pos[0];
-// o->oPosY = m->pos[1];
-// o->oPosZ = m->pos[2];
+ // o->oFaceAngleYaw = m->faceAngle[1] + relYaw;
+ // o->oPosX = m->pos[0];
+ // o->oPosY = m->pos[1];
+ // o->oPosZ = m->pos[2];
-// return o;
+ // return o;
return NULL;
}
@@ -327,7 +334,8 @@ struct Object *spawn_obj_at_mario_rel_yaw(struct MarioState *m, s32 model, const
* Clears "cap on head" flag, sets "cap in hand" flag, plays sound
* SOUND_ACTION_UNKNOWN43D.
*/
-void cutscene_take_cap_off(struct MarioState *m) {
+void cutscene_take_cap_off(struct MarioState *m)
+{
m->flags &= ~MARIO_CAP_ON_HEAD;
m->flags |= MARIO_CAP_IN_HAND;
play_sound(SOUND_ACTION_UNKNOWN43D, m->marioObj->header.gfx.cameraToObject);
@@ -338,7 +346,8 @@ void cutscene_take_cap_off(struct MarioState *m) {
* Clears "cap in hand" flag, sets "cap on head" flag, plays sound
* SOUND_ACTION_UNKNOWN43E.
*/
-void cutscene_put_cap_on(struct MarioState *m) {
+void cutscene_put_cap_on(struct MarioState *m)
+{
m->flags &= ~MARIO_CAP_IN_HAND;
m->flags |= MARIO_CAP_ON_HEAD;
play_sound(SOUND_ACTION_UNKNOWN43E, m->marioObj->header.gfx.cameraToObject);
@@ -353,14 +362,16 @@ void cutscene_put_cap_on(struct MarioState *m) {
* 2: Mario mat not be riding a shell or be invulnerable.
* 3: Mario must not be in first person mode.
*/
-s32 mario_ready_to_speak(void) {
+s32 mario_ready_to_speak(void)
+{
u32 actionGroup = gMarioState->action & ACT_GROUP_MASK;
s32 isReadyToSpeak = FALSE;
if ((gMarioState->action == ACT_WAITING_FOR_DIALOG || actionGroup == ACT_GROUP_STATIONARY
|| actionGroup == ACT_GROUP_MOVING)
- && (!(gMarioState->action & (ACT_FLAG_RIDING_SHELL | ACT_FLAG_INVULNERABLE))
- && gMarioState->action != ACT_FIRST_PERSON)) {
+ && !(gMarioState->action & (ACT_FLAG_RIDING_SHELL | ACT_FLAG_INVULNERABLE))
+ && gMarioState->action != ACT_FIRST_PERSON)
+ {
isReadyToSpeak = TRUE;
}
@@ -373,22 +384,31 @@ s32 mario_ready_to_speak(void) {
// 0 = not in dialog
// 1 = starting dialog
// 2 = speaking
-s32 set_mario_npc_dialog(s32 actionArg) {
+s32 set_mario_npc_dialog(s32 actionArg)
+{
s32 dialogState = 0;
// in dialog
- if (gMarioState->action == ACT_READING_NPC_DIALOG) {
- if (gMarioState->actionState < 8) {
+ if (gMarioState->action == ACT_READING_NPC_DIALOG)
+ {
+ if (gMarioState->actionState < 8)
+ {
dialogState = 1; // starting dialog
}
- if (gMarioState->actionState == 8) {
- if (actionArg == 0) {
+ if (gMarioState->actionState == 8)
+ {
+ if (actionArg == 0)
+ {
gMarioState->actionState++; // exit dialog
- } else {
+ }
+ else
+ {
dialogState = 2;
}
}
- } else if (actionArg != 0 && mario_ready_to_speak()) {
+ }
+ else if (actionArg != 0 && mario_ready_to_speak())
+ {
gMarioState->usedObj = gCurrentObject;
set_mario_action(gMarioState, ACT_READING_NPC_DIALOG, actionArg);
dialogState = 1; // starting dialog
@@ -406,34 +426,46 @@ s32 set_mario_npc_dialog(s32 actionArg) {
// 8: in dialog
// 9 - 22: looking away from npc
// 23: end
-s32 act_reading_npc_dialog(struct MarioState *m) {
+s32 act_reading_npc_dialog(struct MarioState *m)
+{
s32 headTurnAmount = 0;
s16 angleToNPC;
- if (m->actionArg == 2) {
+ if (m->actionArg == 2)
+ {
headTurnAmount = -1024;
}
- if (m->actionArg == 3) {
+ if (m->actionArg == 3)
+ {
headTurnAmount = 384;
}
- if (m->actionState < 8) {
+ if (m->actionState < 8)
+ {
// turn to NPC
angleToNPC = mario_obj_angle_to_object(m, m->usedObj);
m->faceAngle[1] =
- angleToNPC - approach_s32((angleToNPC - m->faceAngle[1]) << 16 >> 16, 0, 2048, 2048);
+ angleToNPC - approach_s32((angleToNPC - m->faceAngle[1]) << 16 >> 16, 0, 2048, 2048);
// turn head to npc
m->actionTimer += headTurnAmount;
// set animation
- set_mario_animation(m, m->heldObj == NULL ? MARIO_ANIM_FIRST_PERSON
- : MARIO_ANIM_IDLE_WITH_LIGHT_OBJ);
- } else if (m->actionState >= 9 && m->actionState < 17) {
+ set_mario_animation(m, m->heldObj == NULL
+ ? MARIO_ANIM_FIRST_PERSON
+ : MARIO_ANIM_IDLE_WITH_LIGHT_OBJ);
+ }
+ else if (m->actionState >= 9 && m->actionState < 17)
+ {
// look back from facing NPC
m->actionTimer -= headTurnAmount;
- } else if (m->actionState == 23) {
- if (m->flags & MARIO_CAP_IN_HAND) {
+ }
+ else if (m->actionState == 23)
+ {
+ if (m->flags & MARIO_CAP_IN_HAND)
+ {
set_mario_action(m, ACT_PUTTING_ON_CAP, 0);
- } else {
+ }
+ else
+ {
set_mario_action(m, m->heldObj == NULL ? ACT_IDLE : ACT_HOLD_IDLE, 0);
}
}
@@ -441,7 +473,8 @@ s32 act_reading_npc_dialog(struct MarioState *m) {
vec3s_set(m->marioObj->header.gfx.angle, 0, m->faceAngle[1], 0);
vec3s_set(m->marioBodyState->headAngle, m->actionTimer, 0, 0);
- if (m->actionState != 8) {
+ if (m->actionState != 8)
+ {
m->actionState++;
}
@@ -449,122 +482,130 @@ s32 act_reading_npc_dialog(struct MarioState *m) {
}
// puts Mario in a state where he's waiting for (npc) dialog; doesn't do much
-s32 act_waiting_for_dialog(struct MarioState *m) {
- set_mario_animation(m, m->heldObj == NULL ? MARIO_ANIM_FIRST_PERSON
- : MARIO_ANIM_IDLE_WITH_LIGHT_OBJ);
+s32 act_waiting_for_dialog(struct MarioState *m)
+{
+ set_mario_animation(m, m->heldObj == NULL
+ ? MARIO_ANIM_FIRST_PERSON
+ : MARIO_ANIM_IDLE_WITH_LIGHT_OBJ);
vec3f_copy(m->marioObj->header.gfx.pos, m->pos);
vec3s_set(m->marioObj->header.gfx.angle, 0, m->faceAngle[1], 0);
return FALSE;
}
// makes Mario disappear and triggers warp
-s32 act_disappeared(struct MarioState *m) {
+s32 act_disappeared(struct MarioState *m)
+{
set_mario_animation(m, MARIO_ANIM_A_POSE);
stop_and_set_height_to_floor(m);
m->marioObj->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE;
- if (m->actionArg) {
+ if (m->actionArg)
+ {
m->actionArg--;
- if ((m->actionArg & 0xFFFF) == 0) {
+ if ((m->actionArg & 0xFFFF) == 0)
+ {
level_trigger_warp(m, m->actionArg >> 16);
}
}
return FALSE;
}
-s32 act_reading_automatic_dialog(struct MarioState *m) {
-// u32 actionArg;
-//
-// m->actionState++;
-// if (m->actionState == 2) {
-// enable_time_stop();
-// }
-// if (m->actionState < 9) {
-// set_mario_animation(m, m->prevAction == ACT_STAR_DANCE_WATER ? MARIO_ANIM_WATER_IDLE
-// : MARIO_ANIM_FIRST_PERSON);
-// // always look up for automatic dialogs
-// m->actionTimer -= 1024;
-// } else {
-// // set Mario dialog
-// if (m->actionState == 9) {
-// actionArg = m->actionArg;
-// if (GET_HIGH_U16_OF_32(actionArg) == 0) {
-// create_dialog_box(GET_LOW_U16_OF_32(actionArg));
-// } else {
-// create_dialog_box_with_var(GET_HIGH_U16_OF_32(actionArg), GET_LOW_U16_OF_32(actionArg));
-// }
-// }
-// // wait until dialog is done
-// else if (m->actionState == 10) {
-// if (get_dialog_id() >= 0) {
-// m->actionState--;
-// }
-// }
-// // look back down
-// else if (m->actionState < 19) {
-// m->actionTimer += 1024;
-// }
-// // finished action
-// else if (m->actionState == 25) {
-// disable_time_stop();
-// if (gNeverEnteredCastle) {
-// gNeverEnteredCastle = FALSE;
-// play_cutscene_music(SEQUENCE_ARGS(0, SEQ_LEVEL_INSIDE_CASTLE));
-// }
-// if (m->prevAction == ACT_STAR_DANCE_WATER) {
-// set_mario_action(m, ACT_WATER_IDLE, 0); // 100c star?
-// } else {
-// // make Mario walk into door after star dialog
-// set_mario_action(m, m->prevAction == ACT_UNLOCKING_STAR_DOOR ? ACT_WALKING : ACT_IDLE,
-// 0);
-// }
-// }
-// }
-// // apply head turn
-// vec3s_set(m->marioBodyState->headAngle, m->actionTimer, 0, 0);
- return FALSE;
+s32 act_reading_automatic_dialog(struct MarioState *m)
+{
+ // u32 actionArg;
+ //
+ // m->actionState++;
+ // if (m->actionState == 2) {
+ // enable_time_stop();
+ // }
+ // if (m->actionState < 9) {
+ // set_mario_animation(m, m->prevAction == ACT_STAR_DANCE_WATER ? MARIO_ANIM_WATER_IDLE
+ // : MARIO_ANIM_FIRST_PERSON);
+ // // always look up for automatic dialogs
+ // m->actionTimer -= 1024;
+ // } else {
+ // // set Mario dialog
+ // if (m->actionState == 9) {
+ // actionArg = m->actionArg;
+ // if (GET_HIGH_U16_OF_32(actionArg) == 0) {
+ // create_dialog_box(GET_LOW_U16_OF_32(actionArg));
+ // } else {
+ // create_dialog_box_with_var(GET_HIGH_U16_OF_32(actionArg), GET_LOW_U16_OF_32(actionArg));
+ // }
+ // }
+ // // wait until dialog is done
+ // else if (m->actionState == 10) {
+ // if (get_dialog_id() >= 0) {
+ // m->actionState--;
+ // }
+ // }
+ // // look back down
+ // else if (m->actionState < 19) {
+ // m->actionTimer += 1024;
+ // }
+ // // finished action
+ // else if (m->actionState == 25) {
+ // disable_time_stop();
+ // if (gNeverEnteredCastle) {
+ // gNeverEnteredCastle = FALSE;
+ // play_cutscene_music(SEQUENCE_ARGS(0, SEQ_LEVEL_INSIDE_CASTLE));
+ // }
+ // if (m->prevAction == ACT_STAR_DANCE_WATER) {
+ // set_mario_action(m, ACT_WATER_IDLE, 0); // 100c star?
+ // } else {
+ // // make Mario walk into door after star dialog
+ // set_mario_action(m, m->prevAction == ACT_UNLOCKING_STAR_DOOR ? ACT_WALKING : ACT_IDLE,
+ // 0);
+ // }
+ // }
+ // }
+ // // apply head turn
+ // vec3s_set(m->marioBodyState->headAngle, m->actionTimer, 0, 0);
+ return FALSE;
}
-s32 act_reading_sign(struct MarioState *m) {
-// struct Object *marioObj = m->marioObj;
-//
-// play_sound_if_no_flag(m, SOUND_ACTION_READ_SIGN, MARIO_ACTION_SOUND_PLAYED);
-//
-// switch (m->actionState) {
-// // start dialog
-// case 0:
-// trigger_cutscene_dialog(1);
-// enable_time_stop();
-// // reading sign
-// set_mario_animation(m, MARIO_ANIM_FIRST_PERSON);
-// m->actionState = 1;
-// // intentional fall through
-// // turn toward sign
-// case 1:
-// m->faceAngle[1] += marioObj->oMarioPoleUnk108 / 11;
-// m->pos[0] += marioObj->oMarioReadingSignDPosX / 11.0f;
-// m->pos[2] += marioObj->oMarioReadingSignDPosZ / 11.0f;
-// // create the text box
-// if (m->actionTimer++ == 10) {
-// create_dialog_inverted_box(m->usedObj->oBehParams2ndByte);
-// m->actionState = 2;
-// }
-// break;
-// // in dialog
-// case 2:
-// // dialog finished
-//// if (gCamera->cutscene == 0) {
-// disable_time_stop();
-// set_mario_action(m, ACT_IDLE, 0);
-//// }
-// break;
-// }
-//
-// vec3f_copy(marioObj->header.gfx.pos, m->pos);
-// vec3s_set(marioObj->header.gfx.angle, 0, m->faceAngle[1], 0);
- return FALSE;
+s32 act_reading_sign(struct MarioState *m)
+{
+ // struct Object *marioObj = m->marioObj;
+ //
+ // play_sound_if_no_flag(m, SOUND_ACTION_READ_SIGN, MARIO_ACTION_SOUND_PLAYED);
+ //
+ // switch (m->actionState) {
+ // // start dialog
+ // case 0:
+ // trigger_cutscene_dialog(1);
+ // enable_time_stop();
+ // // reading sign
+ // set_mario_animation(m, MARIO_ANIM_FIRST_PERSON);
+ // m->actionState = 1;
+ // // intentional fall through
+ // // turn toward sign
+ // case 1:
+ // m->faceAngle[1] += marioObj->oMarioPoleUnk108 / 11;
+ // m->pos[0] += marioObj->oMarioReadingSignDPosX / 11.0f;
+ // m->pos[2] += marioObj->oMarioReadingSignDPosZ / 11.0f;
+ // // create the text box
+ // if (m->actionTimer++ == 10) {
+ // create_dialog_inverted_box(m->usedObj->oBehParams2ndByte);
+ // m->actionState = 2;
+ // }
+ // break;
+ // // in dialog
+ // case 2:
+ // // dialog finished
+ //// if (gCamera->cutscene == 0) {
+ // disable_time_stop();
+ // set_mario_action(m, ACT_IDLE, 0);
+ //// }
+ // break;
+ // }
+ //
+ // vec3f_copy(marioObj->header.gfx.pos, m->pos);
+ // vec3s_set(marioObj->header.gfx.angle, 0, m->faceAngle[1], 0);
+ return FALSE;
}
-s32 act_debug_free_move(struct MarioState *m) {
+s32 act_debug_free_move(struct MarioState *m)
+{
struct Controller *gPlayer1Controller = &gController;
struct SM64SurfaceCollisionData *surf;
@@ -575,21 +616,25 @@ s32 act_debug_free_move(struct MarioState *m) {
// integer immediates, generates convert instructions for some reason
speed = gPlayer1Controller->buttonDown & B_BUTTON ? 4 : 1;
- if (gPlayer1Controller->buttonDown & L_TRIG) {
+ if (gPlayer1Controller->buttonDown & L_TRIG)
+ {
speed = 0.01f;
}
set_mario_animation(m, MARIO_ANIM_A_POSE);
vec3f_copy(pos, m->pos);
- if (gPlayer1Controller->buttonDown & U_JPAD) {
+ if (gPlayer1Controller->buttonDown & U_JPAD)
+ {
pos[1] += 16.0f * speed;
}
- if (gPlayer1Controller->buttonDown & D_JPAD) {
+ if (gPlayer1Controller->buttonDown & D_JPAD)
+ {
pos[1] -= 16.0f * speed;
}
- if (m->intendedMag > 0) {
+ if (m->intendedMag > 0)
+ {
pos[0] += 32.0f * speed * sins(m->intendedYaw);
pos[2] += 32.0f * speed * coss(m->intendedYaw);
}
@@ -597,8 +642,10 @@ s32 act_debug_free_move(struct MarioState *m) {
resolve_and_return_wall_collisions(pos, 60.0f, 50.0f);
floorHeight = find_floor(pos[0], pos[1], pos[2], &surf);
- if (surf != NULL) {
- if (pos[1] < floorHeight) {
+ if (surf != NULL)
+ {
+ if (pos[1] < floorHeight)
+ {
pos[1] = floorHeight;
}
vec3f_copy(m->pos, pos);
@@ -608,10 +655,14 @@ s32 act_debug_free_move(struct MarioState *m) {
vec3f_copy(m->marioObj->header.gfx.pos, m->pos);
vec3s_set(m->marioObj->header.gfx.angle, 0, m->faceAngle[1], 0);
- if (gPlayer1Controller->buttonPressed == A_BUTTON) {
- if (m->pos[1] <= m->waterLevel - 100) {
+ if (gPlayer1Controller->buttonPressed == A_BUTTON)
+ {
+ if (m->pos[1] <= m->waterLevel - 100)
+ {
action = ACT_WATER_IDLE;
- } else {
+ }
+ else
+ {
action = ACT_IDLE;
}
set_mario_action(m, action, 0);
@@ -620,88 +671,98 @@ s32 act_debug_free_move(struct MarioState *m) {
return FALSE;
}
-void general_star_dance_handler(struct MarioState *m, s32 isInWater) {
-// s32 dialogID;
-// if (m->actionState == 0) {
-// switch (++m->actionTimer) {
-// case 1:
-// spawn_object(m->marioObj, MODEL_STAR, bhvCelebrationStar);
-// disable_background_sound();
-// if (m->actionArg & 1) {
-// play_course_clear();
-// } else {
-// if (gCurrLevelNum == LEVEL_BOWSER_1 || gCurrLevelNum == LEVEL_BOWSER_2) {
-// play_music(SEQ_PLAYER_ENV, SEQUENCE_ARGS(15, SEQ_EVENT_CUTSCENE_COLLECT_KEY), 0);
-// } else {
-// play_music(SEQ_PLAYER_ENV, SEQUENCE_ARGS(15, SEQ_EVENT_CUTSCENE_COLLECT_STAR), 0);
-// }
-// }
-// break;
+void general_star_dance_handler(struct MarioState *m, s32 isInWater)
+{
+ // s32 dialogID;
+ // if (m->actionState == 0) {
+ // switch (++m->actionTimer) {
+ // case 1:
+ // spawn_object(m->marioObj, MODEL_STAR, bhvCelebrationStar);
+ // disable_background_sound();
+ // if (m->actionArg & 1) {
+ // play_course_clear();
+ // } else {
+ // if (gCurrLevelNum == LEVEL_BOWSER_1 || gCurrLevelNum == LEVEL_BOWSER_2) {
+ // play_music(SEQ_PLAYER_ENV, SEQUENCE_ARGS(15, SEQ_EVENT_CUTSCENE_COLLECT_KEY), 0);
+ // } else {
+ // play_music(SEQ_PLAYER_ENV, SEQUENCE_ARGS(15, SEQ_EVENT_CUTSCENE_COLLECT_STAR), 0);
+ // }
+ // }
+ // break;
-// case 42:
-// play_sound(SOUND_MARIO_HERE_WE_GO, m->marioObj->header.gfx.cameraToObject);
-// break;
+ // case 42:
+ // play_sound(SOUND_MARIO_HERE_WE_GO, m->marioObj->header.gfx.cameraToObject);
+ // break;
-// case 80:
-// if ((m->actionArg & 1) == 0) {
-// level_trigger_warp(m, WARP_OP_STAR_EXIT);
-// } else {
-// enable_time_stop();
-// create_dialog_box_with_response(gLastCompletedStarNum == 7 ? DIALOG_013 : DIALOG_014);
-// m->actionState = 1;
-// }
-// break;
-// }
-// } else if (m->actionState == 1 && gDialogResponse) {
-// if (gDialogResponse == 1) {
-// save_file_do_save(gCurrSaveFileNum - 1);
-// }
-// m->actionState = 2;
-// } else if (m->actionState == 2 && is_anim_at_end(m)) {
-// disable_time_stop();
-// enable_background_sound();
-// dialogID = get_star_collection_dialog(m);
-// if (dialogID != 0) {
-// // look up for dialog
-// set_mario_action(m, ACT_READING_AUTOMATIC_DIALOG, dialogID);
-// } else {
-// set_mario_action(m, isInWater ? ACT_WATER_IDLE : ACT_IDLE, 0);
-// }
-// }
+ // case 80:
+ // if ((m->actionArg & 1) == 0) {
+ // level_trigger_warp(m, WARP_OP_STAR_EXIT);
+ // } else {
+ // enable_time_stop();
+ // create_dialog_box_with_response(gLastCompletedStarNum == 7 ? DIALOG_013 : DIALOG_014);
+ // m->actionState = 1;
+ // }
+ // break;
+ // }
+ // } else if (m->actionState == 1 && gDialogResponse) {
+ // if (gDialogResponse == 1) {
+ // save_file_do_save(gCurrSaveFileNum - 1);
+ // }
+ // m->actionState = 2;
+ // } else if (m->actionState == 2 && is_anim_at_end(m)) {
+ // disable_time_stop();
+ // enable_background_sound();
+ // dialogID = get_star_collection_dialog(m);
+ // if (dialogID != 0) {
+ // // look up for dialog
+ // set_mario_action(m, ACT_READING_AUTOMATIC_DIALOG, dialogID);
+ // } else {
+ // set_mario_action(m, isInWater ? ACT_WATER_IDLE : ACT_IDLE, 0);
+ // }
+ // }
}
-s32 act_star_dance(struct MarioState *m) {
+s32 act_star_dance(struct MarioState *m)
+{
m->faceAngle[1] = m->area->camera->yaw;
- set_mario_animation(m, m->actionState == 2 ? MARIO_ANIM_RETURN_FROM_STAR_DANCE
- : MARIO_ANIM_STAR_DANCE);
+ set_mario_animation(m, m->actionState == 2
+ ? MARIO_ANIM_RETURN_FROM_STAR_DANCE
+ : MARIO_ANIM_STAR_DANCE);
general_star_dance_handler(m, 0);
- if (m->actionState != 2 && m->actionTimer >= 40) {
+ if (m->actionState != 2 && m->actionTimer >= 40)
+ {
m->marioBodyState->handState = MARIO_HAND_PEACE_SIGN;
}
stop_and_set_height_to_floor(m);
return FALSE;
}
-s32 act_star_dance_water(struct MarioState *m) {
+s32 act_star_dance_water(struct MarioState *m)
+{
m->faceAngle[1] = m->area->camera->yaw;
- set_mario_animation(m, m->actionState == 2 ? MARIO_ANIM_RETURN_FROM_WATER_STAR_DANCE
- : MARIO_ANIM_WATER_STAR_DANCE);
+ set_mario_animation(m, m->actionState == 2
+ ? MARIO_ANIM_RETURN_FROM_WATER_STAR_DANCE
+ : MARIO_ANIM_WATER_STAR_DANCE);
vec3f_copy(m->marioObj->header.gfx.pos, m->pos);
vec3s_set(m->marioObj->header.gfx.angle, 0, m->faceAngle[1], 0);
general_star_dance_handler(m, 1);
- if (m->actionState != 2 && m->actionTimer >= 62) {
+ if (m->actionState != 2 && m->actionTimer >= 62)
+ {
m->marioBodyState->handState = MARIO_HAND_PEACE_SIGN;
}
return FALSE;
}
-s32 act_fall_after_star_grab(struct MarioState *m) {
- if (m->pos[1] < m->waterLevel - 130) {
+s32 act_fall_after_star_grab(struct MarioState *m)
+{
+ if (m->pos[1] < m->waterLevel - 130)
+ {
play_sound(SOUND_ACTION_UNKNOWN430, m->marioObj->header.gfx.cameraToObject);
m->particleFlags |= PARTICLE_WATER_SPLASH;
return set_mario_action(m, ACT_STAR_DANCE_WATER, m->actionArg);
}
- if (perform_air_step(m, 1) == AIR_STEP_LANDED) {
+ if (perform_air_step(m, 1) == AIR_STEP_LANDED)
+ {
play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
set_mario_action(m, m->actionArg & 1 ? ACT_STAR_DANCE_NO_EXIT : ACT_STAR_DANCE_EXIT,
m->actionArg);
@@ -710,9 +771,11 @@ s32 act_fall_after_star_grab(struct MarioState *m) {
return FALSE;
}
-s32 common_death_handler(struct MarioState *m, s32 animation, s32 frameToDeathWarp) {
+s32 common_death_handler(struct MarioState *m, s32 animation, s32 frameToDeathWarp)
+{
s32 animFrame = set_mario_animation(m, animation);
- if (animFrame == frameToDeathWarp) {
+ if (animFrame == frameToDeathWarp)
+ {
level_trigger_warp(m, WARP_OP_DEATH);
}
m->marioBodyState->eyeState = MARIO_EYES_DEAD;
@@ -720,58 +783,72 @@ s32 common_death_handler(struct MarioState *m, s32 animation, s32 frameToDeathWa
return animFrame;
}
-s32 act_standing_death(struct MarioState *m) {
- if (m->input & INPUT_IN_POISON_GAS) {
+s32 act_standing_death(struct MarioState *m)
+{
+ if (m->input & INPUT_IN_POISON_GAS)
+ {
return set_mario_action(m, ACT_SUFFOCATION, 0);
}
play_sound_if_no_flag(m, SOUND_MARIO_DYING, MARIO_ACTION_SOUND_PLAYED);
common_death_handler(m, MARIO_ANIM_DYING_FALL_OVER, 80);
- if (m->marioObj->header.gfx.animInfo.animFrame == 77) {
+ if (m->marioObj->header.gfx.animInfo.animFrame == 77)
+ {
play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_BODY_HIT_GROUND);
}
return FALSE;
}
-s32 act_electrocution(struct MarioState *m) {
+s32 act_electrocution(struct MarioState *m)
+{
play_sound_if_no_flag(m, SOUND_MARIO_DYING, MARIO_ACTION_SOUND_PLAYED);
common_death_handler(m, MARIO_ANIM_ELECTROCUTION, 43);
return FALSE;
}
-s32 act_suffocation(struct MarioState *m) {
+s32 act_suffocation(struct MarioState *m)
+{
play_sound_if_no_flag(m, SOUND_MARIO_DYING, MARIO_ACTION_SOUND_PLAYED);
common_death_handler(m, MARIO_ANIM_SUFFOCATING, 86);
return FALSE;
}
-s32 act_death_on_back(struct MarioState *m) {
+s32 act_death_on_back(struct MarioState *m)
+{
play_sound_if_no_flag(m, SOUND_MARIO_DYING, MARIO_ACTION_SOUND_PLAYED);
- if (common_death_handler(m, MARIO_ANIM_DYING_ON_BACK, 54) == 40) {
+ if (common_death_handler(m, MARIO_ANIM_DYING_ON_BACK, 54) == 40)
+ {
play_mario_heavy_landing_sound(m, SOUND_ACTION_TERRAIN_BODY_HIT_GROUND);
}
return FALSE;
}
-s32 act_death_on_stomach(struct MarioState *m) {
+s32 act_death_on_stomach(struct MarioState *m)
+{
play_sound_if_no_flag(m, SOUND_MARIO_DYING, MARIO_ACTION_SOUND_PLAYED);
- if (common_death_handler(m, MARIO_ANIM_DYING_ON_STOMACH, 37) == 37) {
+ if (common_death_handler(m, MARIO_ANIM_DYING_ON_STOMACH, 37) == 37)
+ {
play_mario_heavy_landing_sound(m, SOUND_ACTION_TERRAIN_BODY_HIT_GROUND);
}
return FALSE;
}
-s32 act_quicksand_death(struct MarioState *m) {
- if (m->actionState == 0) {
+s32 act_quicksand_death(struct MarioState *m)
+{
+ if (m->actionState == 0)
+ {
set_mario_animation(m, MARIO_ANIM_DYING_IN_QUICKSAND);
set_anim_to_frame(m, 60);
m->actionState = 1;
}
- if (m->actionState == 1) {
- if (m->quicksandDepth >= 100.0f) {
+ if (m->actionState == 1)
+ {
+ if (m->quicksandDepth >= 100.0f)
+ {
play_sound_if_no_flag(m, SOUND_MARIO_WAAAOOOW, MARIO_ACTION_SOUND_PLAYED);
}
- if ((m->quicksandDepth += 5.0f) >= 180.0f) {
+ if ((m->quicksandDepth += 5.0f) >= 180.0f)
+ {
level_trigger_warp(m, WARP_OP_DEATH);
m->actionState = 2;
}
@@ -781,12 +858,14 @@ s32 act_quicksand_death(struct MarioState *m) {
return FALSE;
}
-s32 act_eaten_by_bubba(struct MarioState *m) {
+s32 act_eaten_by_bubba(struct MarioState *m)
+{
play_sound_if_no_flag(m, SOUND_MARIO_DYING, MARIO_ACTION_SOUND_PLAYED);
set_mario_animation(m, MARIO_ANIM_A_POSE);
m->marioObj->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE;
m->health = 0xFF;
- if (m->actionTimer++ == 60) {
+ if (m->actionTimer++ == 60)
+ {
level_trigger_warp(m, WARP_OP_DEATH);
}
return FALSE;
@@ -794,111 +873,118 @@ s32 act_eaten_by_bubba(struct MarioState *m) {
// set animation and forwardVel; when perform_air_step returns AIR_STEP_LANDED,
// set the new action
-s32 launch_mario_until_land(struct MarioState *m, s32 endAction, s32 animation, f32 forwardVel) {
+s32 launch_mario_until_land(struct MarioState *m, s32 endAction, s32 animation, f32 forwardVel)
+{
s32 airStepLanded;
mario_set_forward_vel(m, forwardVel);
set_mario_animation(m, animation);
- airStepLanded = (perform_air_step(m, 0) == AIR_STEP_LANDED);
- if (airStepLanded) {
+ airStepLanded = perform_air_step(m, 0) == AIR_STEP_LANDED;
+ if (airStepLanded)
+ {
set_mario_action(m, endAction, 0);
}
return airStepLanded;
}
-s32 act_unlocking_key_door(struct MarioState *m) {
-// m->faceAngle[1] = m->usedObj->oMoveAngleYaw;
+s32 act_unlocking_key_door(struct MarioState *m)
+{
+ // m->faceAngle[1] = m->usedObj->oMoveAngleYaw;
-// m->pos[0] = m->usedObj->oPosX + coss(m->faceAngle[1]) * 75.0f;
-// m->pos[2] = m->usedObj->oPosZ + sins(m->faceAngle[1]) * 75.0f;
+ // m->pos[0] = m->usedObj->oPosX + coss(m->faceAngle[1]) * 75.0f;
+ // m->pos[2] = m->usedObj->oPosZ + sins(m->faceAngle[1]) * 75.0f;
-// if (m->actionArg & 2) {
-// m->faceAngle[1] += 0x8000;
-// }
+ // if (m->actionArg & 2) {
+ // m->faceAngle[1] += 0x8000;
+ // }
-// if (m->actionTimer == 0) {
-// spawn_obj_at_mario_rel_yaw(m, MODEL_BOWSER_KEY_CUTSCENE, bhvBowserKeyUnlockDoor, 0);
-// set_mario_animation(m, MARIO_ANIM_UNLOCK_DOOR);
-// }
+ // if (m->actionTimer == 0) {
+ // spawn_obj_at_mario_rel_yaw(m, MODEL_BOWSER_KEY_CUTSCENE, bhvBowserKeyUnlockDoor, 0);
+ // set_mario_animation(m, MARIO_ANIM_UNLOCK_DOOR);
+ // }
-// switch (m->marioObj->header.gfx.animInfo.animFrame) {
-// case 79:
-// play_sound(SOUND_GENERAL_DOOR_INSERT_KEY, m->marioObj->header.gfx.cameraToObject);
-// break;
-// case 111:
-// play_sound(SOUND_GENERAL_DOOR_TURN_KEY, m->marioObj->header.gfx.cameraToObject);
-// break;
-// }
+ // switch (m->marioObj->header.gfx.animInfo.animFrame) {
+ // case 79:
+ // play_sound(SOUND_GENERAL_DOOR_INSERT_KEY, m->marioObj->header.gfx.cameraToObject);
+ // break;
+ // case 111:
+ // play_sound(SOUND_GENERAL_DOOR_TURN_KEY, m->marioObj->header.gfx.cameraToObject);
+ // break;
+ // }
-// update_mario_pos_for_anim(m);
-// stop_and_set_height_to_floor(m);
+ // update_mario_pos_for_anim(m);
+ // stop_and_set_height_to_floor(m);
-// if (is_anim_at_end(m)) {
-// if (m->usedObj->oBehParams >> 24 == 1) {
-// save_file_set_flags(SAVE_FLAG_UNLOCKED_UPSTAIRS_DOOR);
-// save_file_clear_flags(SAVE_FLAG_HAVE_KEY_2);
-// } else {
-// save_file_set_flags(SAVE_FLAG_UNLOCKED_BASEMENT_DOOR);
-// save_file_clear_flags(SAVE_FLAG_HAVE_KEY_1);
-// }
-// set_mario_action(m, ACT_WALKING, 0);
-// }
+ // if (is_anim_at_end(m)) {
+ // if (m->usedObj->oBehParams >> 24 == 1) {
+ // save_file_set_flags(SAVE_FLAG_UNLOCKED_UPSTAIRS_DOOR);
+ // save_file_clear_flags(SAVE_FLAG_HAVE_KEY_2);
+ // } else {
+ // save_file_set_flags(SAVE_FLAG_UNLOCKED_BASEMENT_DOOR);
+ // save_file_clear_flags(SAVE_FLAG_HAVE_KEY_1);
+ // }
+ // set_mario_action(m, ACT_WALKING, 0);
+ // }
-// m->actionTimer++;
+ // m->actionTimer++;
return FALSE;
}
-s32 act_unlocking_star_door(struct MarioState *m) {
-// switch (m->actionState) {
-// case 0:
-// m->faceAngle[1] = m->usedObj->oMoveAngleYaw;
-// if (m->actionArg & 2) {
-// m->faceAngle[1] += 0x8000;
-// }
-// m->marioObj->oMarioReadingSignDPosX = m->pos[0];
-// m->marioObj->oMarioReadingSignDPosZ = m->pos[2];
-// set_mario_animation(m, MARIO_ANIM_SUMMON_STAR);
-// m->actionState++;
-// break;
-// case 1:
-// if (is_anim_at_end(m)) {
-// spawn_object(m->marioObj, MODEL_STAR, bhvUnlockDoorStar);
-// m->actionState++;
-// }
-// break;
-// case 2:
-// if (m->actionTimer++ == 70) {
-// set_mario_animation(m, MARIO_ANIM_RETURN_STAR_APPROACH_DOOR);
-// m->actionState++;
-// }
-// break;
-// case 3:
-// if (is_anim_at_end(m)) {
-// save_file_set_flags(get_door_save_file_flag(m->usedObj));
-// set_mario_action(m, ACT_READING_AUTOMATIC_DIALOG, DIALOG_038);
-// }
-// break;
-// }
+s32 act_unlocking_star_door(struct MarioState *m)
+{
+ // switch (m->actionState) {
+ // case 0:
+ // m->faceAngle[1] = m->usedObj->oMoveAngleYaw;
+ // if (m->actionArg & 2) {
+ // m->faceAngle[1] += 0x8000;
+ // }
+ // m->marioObj->oMarioReadingSignDPosX = m->pos[0];
+ // m->marioObj->oMarioReadingSignDPosZ = m->pos[2];
+ // set_mario_animation(m, MARIO_ANIM_SUMMON_STAR);
+ // m->actionState++;
+ // break;
+ // case 1:
+ // if (is_anim_at_end(m)) {
+ // spawn_object(m->marioObj, MODEL_STAR, bhvUnlockDoorStar);
+ // m->actionState++;
+ // }
+ // break;
+ // case 2:
+ // if (m->actionTimer++ == 70) {
+ // set_mario_animation(m, MARIO_ANIM_RETURN_STAR_APPROACH_DOOR);
+ // m->actionState++;
+ // }
+ // break;
+ // case 3:
+ // if (is_anim_at_end(m)) {
+ // save_file_set_flags(get_door_save_file_flag(m->usedObj));
+ // set_mario_action(m, ACT_READING_AUTOMATIC_DIALOG, DIALOG_038);
+ // }
+ // break;
+ // }
-// m->pos[0] = m->marioObj->oMarioReadingSignDPosX;
-// m->pos[2] = m->marioObj->oMarioReadingSignDPosZ;
+ // m->pos[0] = m->marioObj->oMarioReadingSignDPosX;
+ // m->pos[2] = m->marioObj->oMarioReadingSignDPosZ;
-// update_mario_pos_for_anim(m);
-// stop_and_set_height_to_floor(m);
+ // update_mario_pos_for_anim(m);
+ // stop_and_set_height_to_floor(m);
return FALSE;
}
-s32 act_entering_star_door(struct MarioState *m) {
+s32 act_entering_star_door(struct MarioState *m)
+{
f32 targetDX;
f32 targetDZ;
s16 targetAngle;
- if (m->actionTimer++ == 0) {
+ if (m->actionTimer++ == 0)
+ {
m->interactObj->oInteractStatus = 0x00010000;
// ~30 degrees / 1/12 rot
targetAngle = m->usedObj->oMoveAngleYaw + 0x1555;
- if (m->actionArg & 2) {
+ if (m->actionArg & 2)
+ {
targetAngle += 0x5556; // ~120 degrees / 1/3 rot (total 150d / 5/12)
}
@@ -915,22 +1001,26 @@ s32 act_entering_star_door(struct MarioState *m) {
}
// set Mario's animation
- if (m->actionTimer < 15) {
+ if (m->actionTimer < 15)
+ {
set_mario_animation(m, MARIO_ANIM_FIRST_PERSON);
}
// go through door? for 20 frames
- else if (m->actionTimer < 35) {
+ else if (m->actionTimer < 35)
+ {
m->pos[0] += m->marioObj->oMarioReadingSignDPosX;
m->pos[2] += m->marioObj->oMarioReadingSignDPosZ;
set_mario_anim_with_accel(m, MARIO_ANIM_WALKING, 0x00028000);
}
- else {
+ else
+ {
m->faceAngle[1] = m->usedObj->oMoveAngleYaw;
- if (m->actionArg & 2) {
+ if (m->actionArg & 2)
+ {
m->faceAngle[1] += 0x8000;
}
@@ -942,19 +1032,25 @@ s32 act_entering_star_door(struct MarioState *m) {
stop_and_set_height_to_floor(m);
- if (m->actionTimer == 48) {
+ if (m->actionTimer == 48)
+ {
set_mario_action(m, ACT_IDLE, 0);
}
return FALSE;
}
-s32 act_going_through_door(struct MarioState *m) {
- if (m->actionTimer == 0) {
- if (m->actionArg & 1) {
+s32 act_going_through_door(struct MarioState *m)
+{
+ if (m->actionTimer == 0)
+ {
+ if (m->actionArg & 1)
+ {
m->interactObj->oInteractStatus = 0x00010000;
set_mario_animation(m, MARIO_ANIM_PULL_DOOR_WALK_IN);
- } else {
+ }
+ else
+ {
m->interactObj->oInteractStatus = 0x00020000;
set_mario_animation(m, MARIO_ANIM_PUSH_DOOR_WALK_IN);
}
@@ -966,12 +1062,17 @@ s32 act_going_through_door(struct MarioState *m) {
update_mario_pos_for_anim(m);
stop_and_set_height_to_floor(m);
- if (m->actionArg & 4) {
- if (m->actionTimer == 16) {
+ if (m->actionArg & 4)
+ {
+ if (m->actionTimer == 16)
+ {
level_trigger_warp(m, WARP_OP_WARP_DOOR);
}
- } else if (is_anim_at_end(m)) {
- if (m->actionArg & 2) {
+ }
+ else if (is_anim_at_end(m))
+ {
+ if (m->actionArg & 2)
+ {
m->faceAngle[1] += 0x8000;
}
set_mario_action(m, ACT_IDLE, 0);
@@ -981,30 +1082,39 @@ s32 act_going_through_door(struct MarioState *m) {
return FALSE;
}
-s32 act_warp_door_spawn(struct MarioState *m) {
- if (m->actionState == 0) {
+s32 act_warp_door_spawn(struct MarioState *m)
+{
+ if (m->actionState == 0)
+ {
m->actionState = 1;
- if (m->actionArg & 1) {
+ if (m->actionArg & 1)
+ {
m->usedObj->oInteractStatus = 0x00040000;
- } else {
+ }
+ else
+ {
m->usedObj->oInteractStatus = 0x00080000;
}
- } else if (m->usedObj->oAction == 0) {
-// if (gNeverEnteredCastle == TRUE && gCurrLevelNum == LEVEL_CASTLE) {
- set_mario_action(m, ACT_READING_AUTOMATIC_DIALOG, 0); // DIALOG_021);
-// } else {
-// set_mario_action(m, ACT_IDLE, 0);
-// }
+ }
+ else if (m->usedObj->oAction == 0)
+ {
+ // if (gNeverEnteredCastle == TRUE && gCurrLevelNum == LEVEL_CASTLE) {
+ set_mario_action(m, ACT_READING_AUTOMATIC_DIALOG, 0); // DIALOG_021);
+ // } else {
+ // set_mario_action(m, ACT_IDLE, 0);
+ // }
}
set_mario_animation(m, MARIO_ANIM_FIRST_PERSON);
stop_and_set_height_to_floor(m);
return FALSE;
}
-s32 act_emerge_from_pipe(struct MarioState *m) {
+s32 act_emerge_from_pipe(struct MarioState *m)
+{
struct Object *marioObj = m->marioObj;
- if (m->actionTimer++ < 11) {
+ if (m->actionTimer++ < 11)
+ {
marioObj->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE;
return FALSE;
}
@@ -1013,24 +1123,28 @@ s32 act_emerge_from_pipe(struct MarioState *m) {
play_sound_if_no_flag(m, SOUND_MARIO_YAHOO, MARIO_MARIO_SOUND_PLAYED);
- if (gCurrLevelNum == LEVEL_THI) {
-// if (gCurrAreaIndex == 2) {
- play_sound_if_no_flag(m, SOUND_MENU_EXIT_PIPE, MARIO_ACTION_SOUND_PLAYED);
-// } else {
-// play_sound_if_no_flag(m, SOUND_MENU_ENTER_PIPE, MARIO_ACTION_SOUND_PLAYED);
-// }
+ if (gCurrLevelNum == LEVEL_THI)
+ {
+ // if (gCurrAreaIndex == 2) {
+ play_sound_if_no_flag(m, SOUND_MENU_EXIT_PIPE, MARIO_ACTION_SOUND_PLAYED);
+ // } else {
+ // play_sound_if_no_flag(m, SOUND_MENU_ENTER_PIPE, MARIO_ACTION_SOUND_PLAYED);
+ // }
}
- if (launch_mario_until_land(m, ACT_JUMP_LAND_STOP, MARIO_ANIM_SINGLE_JUMP, 8.0f)) {
+ if (launch_mario_until_land(m, ACT_JUMP_LAND_STOP, MARIO_ANIM_SINGLE_JUMP, 8.0f))
+ {
mario_set_forward_vel(m, 0.0f);
play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
}
return FALSE;
}
-s32 act_spawn_spin_airborne(struct MarioState *m) {
+s32 act_spawn_spin_airborne(struct MarioState *m)
+{
// entered water, exit action
- if (m->pos[1] < m->waterLevel - 100) {
+ if (m->pos[1] < m->waterLevel - 100)
+ {
load_level_init_text(0);
return set_water_plunge_action(m);
}
@@ -1039,20 +1153,24 @@ s32 act_spawn_spin_airborne(struct MarioState *m) {
mario_set_forward_vel(m, m->forwardVel);
// landed on floor, play spawn land animation
- if (perform_air_step(m, 0.0) == AIR_STEP_LANDED) {
+ if (perform_air_step(m, 0.0) == AIR_STEP_LANDED)
+ {
play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
set_mario_action(m, ACT_SPAWN_SPIN_LANDING, 0);
}
// is 300 units above floor, spin and play woosh sounds
- if (m->actionState == 0 && m->pos[1] - m->floorHeight > 300.0f) {
- if (set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING) == 0) { // first anim frame
+ if (m->actionState == 0 && m->pos[1] - m->floorHeight > 300.0f)
+ {
+ if (set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING) == 0)
+ { // first anim frame
play_sound(SOUND_ACTION_SPIN, m->marioObj->header.gfx.cameraToObject);
}
}
// under 300 units above floor, enter freefall animation
- else {
+ else
+ {
m->actionState = 1;
set_mario_animation(m, MARIO_ANIM_GENERAL_FALL);
}
@@ -1060,10 +1178,12 @@ s32 act_spawn_spin_airborne(struct MarioState *m) {
return FALSE;
}
-s32 act_spawn_spin_landing(struct MarioState *m) {
+s32 act_spawn_spin_landing(struct MarioState *m)
+{
stop_and_set_height_to_floor(m);
set_mario_animation(m, MARIO_ANIM_GENERAL_LAND);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
load_level_init_text(0);
set_mario_action(m, ACT_IDLE, 0);
}
@@ -1080,9 +1200,11 @@ s32 act_spawn_spin_landing(struct MarioState *m) {
* his heal counter to 31 to restore 7.75 units of his health, and enable the
* particle flag that generates sparkles.
*/
-s32 act_exit_airborne(struct MarioState *m) {
+s32 act_exit_airborne(struct MarioState *m)
+{
if (15 < m->actionTimer++
- && launch_mario_until_land(m, ACT_EXIT_LAND_SAVE_DIALOG, MARIO_ANIM_GENERAL_FALL, -32.0f)) {
+ && launch_mario_until_land(m, ACT_EXIT_LAND_SAVE_DIALOG, MARIO_ANIM_GENERAL_FALL, -32.0f))
+ {
// heal Mario
m->healCounter = 31;
}
@@ -1092,8 +1214,10 @@ s32 act_exit_airborne(struct MarioState *m) {
return FALSE;
}
-s32 act_falling_exit_airborne(struct MarioState *m) {
- if (launch_mario_until_land(m, ACT_EXIT_LAND_SAVE_DIALOG, MARIO_ANIM_GENERAL_FALL, 0.0f)) {
+s32 act_falling_exit_airborne(struct MarioState *m)
+{
+ if (launch_mario_until_land(m, ACT_EXIT_LAND_SAVE_DIALOG, MARIO_ANIM_GENERAL_FALL, 0.0f))
+ {
// heal Mario
m->healCounter = 31;
}
@@ -1103,100 +1227,103 @@ s32 act_falling_exit_airborne(struct MarioState *m) {
return FALSE;
}
-s32 act_exit_land_save_dialog(struct MarioState *m) {
-// s32 animFrame;
-// stationary_ground_step(m);
-// play_mario_landing_sound_once(m, SOUND_ACTION_TERRAIN_LANDING);
-// switch (m->actionState) {
-// // determine type of exit
-// case 0:
-// set_mario_animation(m, m->actionArg == 0 ? MARIO_ANIM_GENERAL_LAND
-// : MARIO_ANIM_LAND_FROM_SINGLE_JUMP);
-// if (is_anim_past_end(m)) {
-// if (gLastCompletedCourseNum != COURSE_BITDW
-// && gLastCompletedCourseNum != COURSE_BITFS) {
-// enable_time_stop();
-// }
+s32 act_exit_land_save_dialog(struct MarioState *m)
+{
+ // s32 animFrame;
+ // stationary_ground_step(m);
+ // play_mario_landing_sound_once(m, SOUND_ACTION_TERRAIN_LANDING);
+ // switch (m->actionState) {
+ // // determine type of exit
+ // case 0:
+ // set_mario_animation(m, m->actionArg == 0 ? MARIO_ANIM_GENERAL_LAND
+ // : MARIO_ANIM_LAND_FROM_SINGLE_JUMP);
+ // if (is_anim_past_end(m)) {
+ // if (gLastCompletedCourseNum != COURSE_BITDW
+ // && gLastCompletedCourseNum != COURSE_BITFS) {
+ // enable_time_stop();
+ // }
-// set_menu_mode(RENDER_COURSE_DONE_SCREEN);
-// gSaveOptSelectIndex = 0;
+ // set_menu_mode(RENDER_COURSE_DONE_SCREEN);
+ // gSaveOptSelectIndex = 0;
-// m->actionState = 3; // star exit with cap
-// if (!(m->flags & MARIO_CAP_ON_HEAD)) {
-// m->actionState = 2; // star exit without cap
-// }
-// if (gLastCompletedCourseNum == COURSE_BITDW
-// || gLastCompletedCourseNum == COURSE_BITFS) {
-// m->actionState = 1; // key exit
-// }
-// }
-// break;
-// // key exit
-// case 1:
-// animFrame = set_mario_animation(m, MARIO_ANIM_THROW_CATCH_KEY);
-// switch (animFrame) {
-// case -1:
-// spawn_obj_at_mario_rel_yaw(m, MODEL_BOWSER_KEY_CUTSCENE, bhvBowserKeyCourseExit, -32768);
-// //! fall through
-// case 67:
-// play_sound(SOUND_ACTION_KEY_SWISH, m->marioObj->header.gfx.cameraToObject);
-// //! fall through
-// case 83:
-// play_sound(SOUND_ACTION_PAT_BACK, m->marioObj->header.gfx.cameraToObject);
-// //! fall through
-// case 111:
-// play_sound(SOUND_ACTION_UNKNOWN45C, m->marioObj->header.gfx.cameraToObject);
-// // no break
-// }
-// handle_save_menu(m);
-// break;
-// // exit without cap
-// case 2:
-// animFrame = set_mario_animation(m, MARIO_ANIM_MISSING_CAP);
-// if ((animFrame >= 18 && animFrame < 55) || (animFrame >= 112 && animFrame < 134)) {
-// m->marioBodyState->handState = MARIO_HAND_OPEN;
-// }
-// if (!(animFrame < 109) && animFrame < 154) {
-// m->marioBodyState->eyeState = MARIO_EYES_HALF_CLOSED;
-// }
+ // m->actionState = 3; // star exit with cap
+ // if (!(m->flags & MARIO_CAP_ON_HEAD)) {
+ // m->actionState = 2; // star exit without cap
+ // }
+ // if (gLastCompletedCourseNum == COURSE_BITDW
+ // || gLastCompletedCourseNum == COURSE_BITFS) {
+ // m->actionState = 1; // key exit
+ // }
+ // }
+ // break;
+ // // key exit
+ // case 1:
+ // animFrame = set_mario_animation(m, MARIO_ANIM_THROW_CATCH_KEY);
+ // switch (animFrame) {
+ // case -1:
+ // spawn_obj_at_mario_rel_yaw(m, MODEL_BOWSER_KEY_CUTSCENE, bhvBowserKeyCourseExit, -32768);
+ // //! fall through
+ // case 67:
+ // play_sound(SOUND_ACTION_KEY_SWISH, m->marioObj->header.gfx.cameraToObject);
+ // //! fall through
+ // case 83:
+ // play_sound(SOUND_ACTION_PAT_BACK, m->marioObj->header.gfx.cameraToObject);
+ // //! fall through
+ // case 111:
+ // play_sound(SOUND_ACTION_UNKNOWN45C, m->marioObj->header.gfx.cameraToObject);
+ // // no break
+ // }
+ // handle_save_menu(m);
+ // break;
+ // // exit without cap
+ // case 2:
+ // animFrame = set_mario_animation(m, MARIO_ANIM_MISSING_CAP);
+ // if ((animFrame >= 18 && animFrame < 55) || (animFrame >= 112 && animFrame < 134)) {
+ // m->marioBodyState->handState = MARIO_HAND_OPEN;
+ // }
+ // if (!(animFrame < 109) && animFrame < 154) {
+ // m->marioBodyState->eyeState = MARIO_EYES_HALF_CLOSED;
+ // }
-// handle_save_menu(m);
-// break;
-// // exit with cap
-// case 3:
-// animFrame = set_mario_animation(m, MARIO_ANIM_TAKE_CAP_OFF_THEN_ON);
-// switch (animFrame) {
-// case 12:
-// cutscene_take_cap_off(m);
-// break;
-// case 37:
-// // fall through
-// case 53:
-// play_sound(SOUND_ACTION_BRUSH_HAIR, m->marioObj->header.gfx.cameraToObject);
-// break;
-// case 82:
-// cutscene_put_cap_on(m);
-// break;
-// }
-// handle_save_menu(m);
-// break;
-// }
+ // handle_save_menu(m);
+ // break;
+ // // exit with cap
+ // case 3:
+ // animFrame = set_mario_animation(m, MARIO_ANIM_TAKE_CAP_OFF_THEN_ON);
+ // switch (animFrame) {
+ // case 12:
+ // cutscene_take_cap_off(m);
+ // break;
+ // case 37:
+ // // fall through
+ // case 53:
+ // play_sound(SOUND_ACTION_BRUSH_HAIR, m->marioObj->header.gfx.cameraToObject);
+ // break;
+ // case 82:
+ // cutscene_put_cap_on(m);
+ // break;
+ // }
+ // handle_save_menu(m);
+ // break;
+ // }
-// m->marioObj->header.gfx.angle[1] += 0x8000;
+ // m->marioObj->header.gfx.angle[1] += 0x8000;
return FALSE;
}
-s32 act_death_exit(struct MarioState *m) {
+s32 act_death_exit(struct MarioState *m)
+{
if (15 < m->actionTimer++
- && launch_mario_until_land(m, ACT_DEATH_EXIT_LAND, MARIO_ANIM_GENERAL_FALL, -32.0f)) {
-#ifdef VERSION_JP
+ && launch_mario_until_land(m, ACT_DEATH_EXIT_LAND, MARIO_ANIM_GENERAL_FALL, -32.0f))
+ {
+ #ifdef VERSION_JP
play_sound(SOUND_MARIO_OOOF, m->marioObj->header.gfx.cameraToObject);
-#else
+ #else
play_sound(SOUND_MARIO_OOOF2, m->marioObj->header.gfx.cameraToObject);
-#endif
-#ifdef VERSION_SH
+ #endif
+ #ifdef VERSION_SH
queue_rumble_data(5, 80);
-#endif
+ #endif
m->numLives--;
// restore 7.75 units of health
m->healCounter = 31;
@@ -1206,13 +1333,15 @@ s32 act_death_exit(struct MarioState *m) {
return FALSE;
}
-s32 act_unused_death_exit(struct MarioState *m) {
- if (launch_mario_until_land(m, ACT_FREEFALL_LAND_STOP, MARIO_ANIM_GENERAL_FALL, 0.0f)) {
-#ifdef VERSION_JP
+s32 act_unused_death_exit(struct MarioState *m)
+{
+ if (launch_mario_until_land(m, ACT_FREEFALL_LAND_STOP, MARIO_ANIM_GENERAL_FALL, 0.0f))
+ {
+ #ifdef VERSION_JP
play_sound(SOUND_MARIO_OOOF, m->marioObj->header.gfx.cameraToObject);
-#else
+ #else
play_sound(SOUND_MARIO_OOOF2, m->marioObj->header.gfx.cameraToObject);
-#endif
+ #endif
m->numLives--;
// restore 7.75 units of health
m->healCounter = 31;
@@ -1222,16 +1351,18 @@ s32 act_unused_death_exit(struct MarioState *m) {
return FALSE;
}
-s32 act_falling_death_exit(struct MarioState *m) {
- if (launch_mario_until_land(m, ACT_DEATH_EXIT_LAND, MARIO_ANIM_GENERAL_FALL, 0.0f)) {
-#ifdef VERSION_JP
+s32 act_falling_death_exit(struct MarioState *m)
+{
+ if (launch_mario_until_land(m, ACT_DEATH_EXIT_LAND, MARIO_ANIM_GENERAL_FALL, 0.0f))
+ {
+ #ifdef VERSION_JP
play_sound(SOUND_MARIO_OOOF, m->marioObj->header.gfx.cameraToObject);
-#else
+ #else
play_sound(SOUND_MARIO_OOOF2, m->marioObj->header.gfx.cameraToObject);
-#endif
-#ifdef VERSION_SH
+ #endif
+ #ifdef VERSION_SH
queue_rumble_data(5, 80);
-#endif
+ #endif
m->numLives--;
// restore 7.75 units of health
m->healCounter = 31;
@@ -1242,17 +1373,20 @@ s32 act_falling_death_exit(struct MarioState *m) {
}
// waits 11 frames before actually executing, also has reduced fvel
-s32 act_special_exit_airborne(struct MarioState *m) {
+s32 act_special_exit_airborne(struct MarioState *m)
+{
struct Object *marioObj = m->marioObj;
play_sound_if_no_flag(m, SOUND_MARIO_YAHOO, MARIO_MARIO_SOUND_PLAYED);
- if (m->actionTimer++ < 11) {
+ if (m->actionTimer++ < 11)
+ {
marioObj->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE;
return FALSE;
}
- if (launch_mario_until_land(m, ACT_EXIT_LAND_SAVE_DIALOG, MARIO_ANIM_SINGLE_JUMP, -24.0f)) {
+ if (launch_mario_until_land(m, ACT_EXIT_LAND_SAVE_DIALOG, MARIO_ANIM_SINGLE_JUMP, -24.0f))
+ {
// heal Mario
m->healCounter = 31;
m->actionArg = 1;
@@ -1267,18 +1401,21 @@ s32 act_special_exit_airborne(struct MarioState *m) {
return FALSE;
}
-s32 act_special_death_exit(struct MarioState *m) {
+s32 act_special_death_exit(struct MarioState *m)
+{
struct Object *marioObj = m->marioObj;
- if (m->actionTimer++ < 11) {
+ if (m->actionTimer++ < 11)
+ {
marioObj->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE;
return FALSE;
}
- if (launch_mario_until_land(m, ACT_HARD_BACKWARD_GROUND_KB, MARIO_ANIM_BACKWARD_AIR_KB, -24.0f)) {
-#ifdef VERSION_SH
+ if (launch_mario_until_land(m, ACT_HARD_BACKWARD_GROUND_KB, MARIO_ANIM_BACKWARD_AIR_KB, -24.0f))
+ {
+ #ifdef VERSION_SH
queue_rumble_data(5, 80);
-#endif
+ #endif
m->numLives--;
m->healCounter = 31;
}
@@ -1290,26 +1427,31 @@ s32 act_special_death_exit(struct MarioState *m) {
return FALSE;
}
-s32 act_spawn_no_spin_airborne(struct MarioState *m) {
+s32 act_spawn_no_spin_airborne(struct MarioState *m)
+{
launch_mario_until_land(m, ACT_SPAWN_NO_SPIN_LANDING, MARIO_ANIM_GENERAL_FALL, 0.0f);
- if (m->pos[1] < m->waterLevel - 100) {
+ if (m->pos[1] < m->waterLevel - 100)
+ {
set_water_plunge_action(m);
}
return FALSE;
}
-s32 act_spawn_no_spin_landing(struct MarioState *m) {
+s32 act_spawn_no_spin_landing(struct MarioState *m)
+{
play_mario_landing_sound_once(m, SOUND_ACTION_TERRAIN_LANDING);
set_mario_animation(m, MARIO_ANIM_GENERAL_LAND);
stop_and_set_height_to_floor(m);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
load_level_init_text(0);
set_mario_action(m, ACT_IDLE, 0);
}
return FALSE;
}
-s32 act_bbh_enter_spin(struct MarioState *m) {
+s32 act_bbh_enter_spin(struct MarioState *m)
+{
f32 floorDist;
f32 scale;
f32 cageDX;
@@ -1321,63 +1463,76 @@ s32 act_bbh_enter_spin(struct MarioState *m) {
cageDZ = m->usedObj->oPosZ - m->pos[2];
cageDist = sqrtf(cageDX * cageDX + cageDZ * cageDZ);
- if (cageDist > 20.0f) {
+ if (cageDist > 20.0f)
+ {
forwardVel = 10.0f;
- } else {
+ }
+ else
+ {
forwardVel = cageDist / 2.0f;
}
- if (forwardVel < 0.5f) {
+ if (forwardVel < 0.5f)
+ {
forwardVel = 0.0f;
}
- switch (m->actionState) {
+ switch (m->actionState)
+ {
case 0:
floorDist = 512.0f - (m->pos[1] - m->floorHeight);
m->vel[1] = floorDist > 0 ? sqrtf(4.0f * floorDist + 1.0f) - 1.0f : 2.0f;
m->actionState = 1;
m->actionTimer = 100;
- // fall through
+ // fall through
case 1:
m->faceAngle[1] = atan2s(cageDZ, cageDX);
mario_set_forward_vel(m, forwardVel);
- if (set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING) == 0) {
+ if (set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING) == 0)
+ {
play_sound(SOUND_ACTION_SPIN, m->marioObj->header.gfx.cameraToObject);
}
m->flags &= ~MARIO_UNKNOWN_08;
perform_air_step(m, 0);
- if (m->vel[1] <= 0) {
+ if (m->vel[1] <= 0)
+ {
m->actionState = 2;
}
break;
case 2:
- // fall through
+ // fall through
case 3:
m->faceAngle[1] = atan2s(cageDZ, cageDX);
mario_set_forward_vel(m, forwardVel);
m->flags &= ~MARIO_UNKNOWN_08;
- if (perform_air_step(m, 0) == AIR_STEP_LANDED) {
+ if (perform_air_step(m, 0) == AIR_STEP_LANDED)
+ {
level_trigger_warp(m, WARP_OP_UNKNOWN_02);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
queue_rumble_data(15, 80);
-#endif
+ #endif
m->actionState = 4;
}
- if (m->actionState == 2) {
- if (m->marioObj->header.gfx.animInfo.animFrame == 0) {
+ if (m->actionState == 2)
+ {
+ if (m->marioObj->header.gfx.animInfo.animFrame == 0)
+ {
m->actionState = 3;
}
- } else {
+ }
+ else
+ {
play_sound_if_no_flag(m, SOUND_ACTION_SHRINK_INTO_BBH, MARIO_ACTION_SOUND_PLAYED);
set_mario_animation(m, MARIO_ANIM_DIVE);
m->marioObj->header.gfx.angle[0] = atan2s(m->forwardVel, -m->vel[1]);
}
m->squishTimer = 0xFF;
- if (m->actionTimer >= 11) {
+ if (m->actionTimer >= 11)
+ {
m->actionTimer -= 6;
scale = m->actionTimer / 100.0f;
vec3f_set(m->marioObj->header.gfx.scale, scale, scale, scale);
@@ -1393,7 +1548,8 @@ s32 act_bbh_enter_spin(struct MarioState *m) {
return FALSE;
}
-s32 act_bbh_enter_jump(struct MarioState *m) {
+s32 act_bbh_enter_jump(struct MarioState *m)
+{
f32 cageDX;
f32 cageDZ;
f32 cageDist;
@@ -1402,7 +1558,8 @@ s32 act_bbh_enter_jump(struct MarioState *m) {
m, m->flags & MARIO_METAL_CAP ? SOUND_ACTION_METAL_JUMP : SOUND_ACTION_TERRAIN_JUMP, 1);
play_mario_jump_sound(m);
- if (m->actionState == 0) {
+ if (m->actionState == 0)
+ {
cageDX = m->usedObj->oPosX - m->pos[0];
cageDZ = m->usedObj->oPosZ - m->pos[2];
cageDist = sqrtf(cageDX * cageDX + cageDZ * cageDZ);
@@ -1418,32 +1575,38 @@ s32 act_bbh_enter_jump(struct MarioState *m) {
set_mario_animation(m, MARIO_ANIM_DOUBLE_JUMP_RISE);
perform_air_step(m, 0);
- if (m->vel[1] <= 0.0f) {
+ if (m->vel[1] <= 0.0f)
+ {
set_mario_action(m, ACT_BBH_ENTER_SPIN, 0);
}
return FALSE;
}
-s32 act_teleport_fade_out(struct MarioState *m) {
+s32 act_teleport_fade_out(struct MarioState *m)
+{
play_sound_if_no_flag(m, SOUND_ACTION_TELEPORT, MARIO_ACTION_SOUND_PLAYED);
- set_mario_animation(m, m->prevAction == ACT_CROUCHING ? MARIO_ANIM_CROUCHING
- : MARIO_ANIM_FIRST_PERSON);
+ set_mario_animation(m, m->prevAction == ACT_CROUCHING
+ ? MARIO_ANIM_CROUCHING
+ : MARIO_ANIM_FIRST_PERSON);
-#ifdef VERSION_SH
- if (m->actionTimer == 0) {
+ #ifdef VERSION_SH
+ if (m->actionTimer == 0)
+ {
queue_rumble_data(30, 70);
func_sh_8024C89C(2);
}
-#endif
+ #endif
m->flags |= MARIO_TELEPORTING;
- if (m->actionTimer < 32) {
+ if (m->actionTimer < 32)
+ {
m->fadeWarpOpacity = (-m->actionTimer << 3) + 0xF8;
}
- if (m->actionTimer++ == 20) {
+ if (m->actionTimer++ == 20)
+ {
level_trigger_warp(m, WARP_OP_TELEPORT);
}
@@ -1452,32 +1615,42 @@ s32 act_teleport_fade_out(struct MarioState *m) {
return FALSE;
}
-s32 act_teleport_fade_in(struct MarioState *m) {
+s32 act_teleport_fade_in(struct MarioState *m)
+{
play_sound_if_no_flag(m, SOUND_ACTION_TELEPORT, MARIO_ACTION_SOUND_PLAYED);
set_mario_animation(m, MARIO_ANIM_FIRST_PERSON);
-#ifdef VERSION_SH
- if (m->actionTimer == 0) {
+ #ifdef VERSION_SH
+ if (m->actionTimer == 0)
+ {
queue_rumble_data(30, 70);
func_sh_8024C89C(2);
}
-#endif
+ #endif
- if (m->actionTimer < 32) {
+ if (m->actionTimer < 32)
+ {
m->flags |= MARIO_TELEPORTING;
m->fadeWarpOpacity = m->actionTimer << 3;
- } else {
+ }
+ else
+ {
m->flags &= ~MARIO_TELEPORTING;
}
- if (m->actionTimer++ == 32) {
- if (m->pos[1] < m->waterLevel - 100) {
+ if (m->actionTimer++ == 32)
+ {
+ if (m->pos[1] < m->waterLevel - 100)
+ {
// Check if the camera is not underwater.
- if (m->area->camera->mode != CAMERA_MODE_WATER_SURFACE) {
+ if (m->area->camera->mode != CAMERA_MODE_WATER_SURFACE)
+ {
set_camera_mode(m->area->camera, CAMERA_MODE_WATER_SURFACE, 1);
}
set_mario_action(m, ACT_WATER_IDLE, 0);
- } else {
+ }
+ else
+ {
set_mario_action(m, ACT_IDLE, 0);
}
}
@@ -1487,24 +1660,31 @@ s32 act_teleport_fade_in(struct MarioState *m) {
return FALSE;
}
-s32 act_shocked(struct MarioState *m) {
+s32 act_shocked(struct MarioState *m)
+{
play_sound_if_no_flag(m, SOUND_MARIO_WAAAOOOW, MARIO_ACTION_SOUND_PLAYED);
play_sound(SOUND_MOVING_SHOCKED, m->marioObj->header.gfx.cameraToObject);
set_camera_shake_from_hit(SHAKE_SHOCK);
- if (set_mario_animation(m, MARIO_ANIM_SHOCKED) == 0) {
+ if (set_mario_animation(m, MARIO_ANIM_SHOCKED) == 0)
+ {
m->actionTimer++;
m->flags |= MARIO_METAL_SHOCK;
}
- if (m->actionArg == 0) {
+ if (m->actionArg == 0)
+ {
mario_set_forward_vel(m, 0.0f);
- if (perform_air_step(m, 1) == AIR_STEP_LANDED) {
+ if (perform_air_step(m, 1) == AIR_STEP_LANDED)
+ {
play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
m->actionArg = 1;
}
- } else {
- if (m->actionTimer >= 6) {
+ }
+ else
+ {
+ if (m->actionTimer >= 6)
+ {
m->invincTimer = 30;
set_mario_action(m, m->health < 0x0100 ? ACT_ELECTROCUTION : ACT_IDLE, 0);
}
@@ -1514,33 +1694,41 @@ s32 act_shocked(struct MarioState *m) {
return FALSE;
}
-s32 act_squished(struct MarioState *m) {
+s32 act_squished(struct MarioState *m)
+{
UNUSED s32 pad;
f32 squishAmount;
f32 spaceUnderCeil;
s16 surfAngle;
s32 underSteepSurf = FALSE; // seems to be responsible for setting velocity?
- if ((spaceUnderCeil = m->ceilHeight - m->floorHeight) < 0) {
+ if ((spaceUnderCeil = m->ceilHeight - m->floorHeight) < 0)
+ {
spaceUnderCeil = 0;
}
- switch (m->actionState) {
+ switch (m->actionState)
+ {
case 0:
- if (spaceUnderCeil > 160.0f) {
+ if (spaceUnderCeil > 160.0f)
+ {
m->squishTimer = 0;
return set_mario_action(m, ACT_IDLE, 0);
}
m->squishTimer = 0xFF;
- if (spaceUnderCeil >= 10.1f) {
+ if (spaceUnderCeil >= 10.1f)
+ {
// Mario becomes a pancake
squishAmount = spaceUnderCeil / 160.0f;
vec3f_set(m->marioObj->header.gfx.scale, 2.0f - squishAmount, squishAmount,
2.0f - squishAmount);
- } else {
- if (!(m->flags & MARIO_METAL_CAP) && m->invincTimer == 0) {
+ }
+ else
+ {
+ if (!(m->flags & MARIO_METAL_CAP) && m->invincTimer == 0)
+ {
// cap on: 3 units; cap off: 4.5 units
m->hurtCounter += m->flags & MARIO_CAP_ON_HEAD ? 12 : 18;
play_sound_if_no_flag(m, SOUND_MARIO_ATTACKED, MARIO_MARIO_SOUND_PLAYED);
@@ -1549,26 +1737,31 @@ s32 act_squished(struct MarioState *m) {
// Both of the 1.8's are really floats, but one of them has to
// be written as a double for this to match on -O2.
vec3f_set(m->marioObj->header.gfx.scale, 1.8, 0.05f, 1.8f);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
queue_rumble_data(10, 80);
-#endif
+ #endif
m->actionState = 1;
}
break;
case 1:
- if (spaceUnderCeil >= 30.0f) {
+ if (spaceUnderCeil >= 30.0f)
+ {
m->actionState = 2;
}
break;
case 2:
m->actionTimer++;
- if (m->actionTimer >= 15) {
+ if (m->actionTimer >= 15)
+ {
// 1 unit of health
- if (m->health < 0x0100) {
+ if (m->health < 0x0100)
+ {
level_trigger_warp(m, WARP_OP_DEATH);
// woosh, he's gone!
set_mario_action(m, ACT_DISAPPEARED, 0);
- } else if (m->hurtCounter == 0) {
+ }
+ else if (m->hurtCounter == 0)
+ {
// un-squish animation
m->squishTimer = 30;
set_mario_action(m, ACT_IDLE, 0);
@@ -1578,23 +1771,27 @@ s32 act_squished(struct MarioState *m) {
}
// steep floor
- if (m->floor != NULL && m->floor->normal.y < 0.5f) {
+ if (m->floor != NULL && m->floor->normal.y < 0.5f)
+ {
surfAngle = atan2s(m->floor->normal.z, m->floor->normal.x);
underSteepSurf = TRUE;
}
// steep ceiling
- if (m->ceil != NULL && -0.5f < m->ceil->normal.y) {
+ if (m->ceil != NULL && -0.5f < m->ceil->normal.y)
+ {
surfAngle = atan2s(m->ceil->normal.z, m->ceil->normal.x);
underSteepSurf = TRUE;
}
- if (underSteepSurf) {
+ if (underSteepSurf)
+ {
m->vel[0] = sins(surfAngle) * 10.0f;
m->vel[2] = coss(surfAngle) * 10.0f;
m->vel[1] = 0;
// check if there's no floor 10 units away from the surface
- if (perform_ground_step(m) == GROUND_STEP_LEFT_GROUND) {
+ if (perform_ground_step(m) == GROUND_STEP_LEFT_GROUND)
+ {
// instant un-squish
m->squishTimer = 0;
set_mario_action(m, ACT_IDLE, 0);
@@ -1603,7 +1800,8 @@ s32 act_squished(struct MarioState *m) {
}
// squished for more than 10 seconds, so kill Mario
- if (m->actionArg++ > 300) {
+ if (m->actionArg++ > 300)
+ {
// 0 units of health
m->health = 0x00FF;
m->hurtCounter = 0;
@@ -1616,18 +1814,22 @@ s32 act_squished(struct MarioState *m) {
return FALSE;
}
-s32 act_putting_on_cap(struct MarioState *m) {
+s32 act_putting_on_cap(struct MarioState *m)
+{
s32 animFrame = set_mario_animation(m, MARIO_ANIM_PUT_CAP_ON);
- if (animFrame == 0) {
+ if (animFrame == 0)
+ {
enable_time_stop();
}
- if (animFrame == 28) {
+ if (animFrame == 28)
+ {
cutscene_put_cap_on(m);
}
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_action(m, ACT_IDLE, 0);
disable_time_stop();
}
@@ -1636,13 +1838,17 @@ s32 act_putting_on_cap(struct MarioState *m) {
return FALSE;
}
-void stuck_in_ground_handler(struct MarioState *m, s32 animation, s32 unstuckFrame, s32 target2,
- s32 target3, s32 endAction) {
+void stuck_in_ground_handler(
+ struct MarioState *m, s32 animation, s32 unstuckFrame, s32 target2,
+ s32 target3, s32 endAction)
+{
s32 animFrame = set_mario_animation(m, animation);
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
m->actionTimer++;
- if (m->actionTimer >= 5 && animFrame < unstuckFrame - 1) {
+ if (m->actionTimer >= 5 && animFrame < unstuckFrame - 1)
+ {
animFrame = unstuckFrame - 1;
set_anim_to_frame(m, animFrame);
}
@@ -1650,33 +1856,42 @@ void stuck_in_ground_handler(struct MarioState *m, s32 animation, s32 unstuckFra
stop_and_set_height_to_floor(m);
- if (animFrame == -1) {
+ if (animFrame == -1)
+ {
play_sound_and_spawn_particles(m, SOUND_ACTION_TERRAIN_STUCK_IN_GROUND, 1);
- } else if (animFrame == unstuckFrame) {
-#ifdef VERSION_SH
+ }
+ else if (animFrame == unstuckFrame)
+ {
+ #ifdef VERSION_SH
queue_rumble_data(5, 80);
-#endif
+ #endif
play_sound_and_spawn_particles(m, SOUND_ACTION_UNSTUCK_FROM_GROUND, 1);
- } else if (animFrame == target2 || animFrame == target3) {
+ }
+ else if (animFrame == target2 || animFrame == target3)
+ {
play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
}
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_action(m, endAction, 0);
}
}
-s32 act_head_stuck_in_ground(struct MarioState *m) {
+s32 act_head_stuck_in_ground(struct MarioState *m)
+{
stuck_in_ground_handler(m, MARIO_ANIM_HEAD_STUCK_IN_GROUND, 96, 105, 135, ACT_IDLE);
return FALSE;
}
-s32 act_butt_stuck_in_ground(struct MarioState *m) {
+s32 act_butt_stuck_in_ground(struct MarioState *m)
+{
stuck_in_ground_handler(m, MARIO_ANIM_BOTTOM_STUCK_IN_GROUND, 127, 136, -2, ACT_GROUND_POUND_LAND);
return FALSE;
}
-s32 act_feet_stuck_in_ground(struct MarioState *m) {
+s32 act_feet_stuck_in_ground(struct MarioState *m)
+{
stuck_in_ground_handler(m, MARIO_ANIM_LEGS_STUCK_IN_GROUND, 116, 129, -2, ACT_IDLE);
return FALSE;
}
@@ -1686,124 +1901,136 @@ s32 act_feet_stuck_in_ground(struct MarioState *m) {
* Resets action state and action timer, adds 1 to the action arg (responsible
* for keeping track of what step of the cutscene Mario is in.)
*/
-static void advance_cutscene_step(struct MarioState *m) {
+static void advance_cutscene_step(struct MarioState *m)
+{
m->actionState = 0;
m->actionTimer = 0;
m->actionArg++;
}
-static void intro_cutscene_hide_hud_and_mario(struct MarioState *m) {
-// gHudDisplay.flags = HUD_DISPLAY_NONE;
-// m->statusForCamera->cameraEvent = CAM_EVENT_START_INTRO;
-// m->marioObj->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE;
-// advance_cutscene_step(m);
+static void intro_cutscene_hide_hud_and_mario(struct MarioState *m)
+{
+ // gHudDisplay.flags = HUD_DISPLAY_NONE;
+ // m->statusForCamera->cameraEvent = CAM_EVENT_START_INTRO;
+ // m->marioObj->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE;
+ // advance_cutscene_step(m);
}
#ifdef VERSION_EU
- #define TIMER_SPAWN_PIPE 47
+#define TIMER_SPAWN_PIPE 47
#else
- #define TIMER_SPAWN_PIPE 37
+#define TIMER_SPAWN_PIPE 37
#endif
-static void intro_cutscene_peach_lakitu_scene(struct MarioState *m) {
-// if ((s16) m->statusForCamera->cameraEvent != CAM_EVENT_START_INTRO) {
-// if (m->actionTimer++ == TIMER_SPAWN_PIPE) {
-// sIntroWarpPipeObj =
-// spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_CASTLE_GROUNDS_WARP_PIPE,
-// bhvStaticObject, -1328, 60, 4664, 0, 180, 0);
-// advance_cutscene_step(m);
-// }
-// }
+static void intro_cutscene_peach_lakitu_scene(struct MarioState *m)
+{
+ // if ((s16) m->statusForCamera->cameraEvent != CAM_EVENT_START_INTRO) {
+ // if (m->actionTimer++ == TIMER_SPAWN_PIPE) {
+ // sIntroWarpPipeObj =
+ // spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_CASTLE_GROUNDS_WARP_PIPE,
+ // bhvStaticObject, -1328, 60, 4664, 0, 180, 0);
+ // advance_cutscene_step(m);
+ // }
+ // }
}
#undef TIMER_SPAWN_PIPE
#ifdef VERSION_EU
- #define TIMER_RAISE_PIPE 28
+#define TIMER_RAISE_PIPE 28
#else
- #define TIMER_RAISE_PIPE 38
+#define TIMER_RAISE_PIPE 38
#endif
-static void intro_cutscene_raise_pipe(struct MarioState *m) {
-// sIntroWarpPipeObj->oPosY = camera_approach_f32_symmetric(sIntroWarpPipeObj->oPosY, 260.0f, 10.0f);
+static void intro_cutscene_raise_pipe(struct MarioState *m)
+{
+ // sIntroWarpPipeObj->oPosY = camera_approach_f32_symmetric(sIntroWarpPipeObj->oPosY, 260.0f, 10.0f);
-// if (m->actionTimer == 0) {
-// play_sound(SOUND_MENU_EXIT_PIPE, sIntroWarpPipeObj->header.gfx.cameraToObject);
-// }
+ // if (m->actionTimer == 0) {
+ // play_sound(SOUND_MENU_EXIT_PIPE, sIntroWarpPipeObj->header.gfx.cameraToObject);
+ // }
-// if (m->actionTimer++ == TIMER_RAISE_PIPE) {
-// m->vel[1] = 60.0f;
-// advance_cutscene_step(m);
-// }
+ // if (m->actionTimer++ == TIMER_RAISE_PIPE) {
+ // m->vel[1] = 60.0f;
+ // advance_cutscene_step(m);
+ // }
}
#undef TIMER_RAISE_PIPE
-static void intro_cutscene_jump_out_of_pipe(struct MarioState *m) {
-// if (m->actionTimer == 25) {
-// gHudDisplay.flags = HUD_DISPLAY_DEFAULT;
-// }
-//
-// if (m->actionTimer++ >= 118) {
-// m->marioObj->header.gfx.node.flags |= GRAPH_RENDER_ACTIVE;
-//
-//#ifdef VERSION_EU
-// // For some reason these calls were swapped.
-// play_sound_if_no_flag(m, SOUND_ACTION_HIT_3, MARIO_ACTION_SOUND_PLAYED);
-// play_sound_if_no_flag(m, SOUND_MARIO_YAHOO, MARIO_MARIO_SOUND_PLAYED);
-//#else
-// play_sound_if_no_flag(m, SOUND_MARIO_YAHOO, MARIO_MARIO_SOUND_PLAYED);
-// #ifndef VERSION_JP
-// play_sound_if_no_flag(m, SOUND_ACTION_HIT_3, MARIO_ACTION_SOUND_PLAYED);
-// #endif
-//#endif
-//
-// set_mario_animation(m, MARIO_ANIM_SINGLE_JUMP);
-// mario_set_forward_vel(m, 10.0f);
-// if (perform_air_step(m, 0) == AIR_STEP_LANDED) {
-// sound_banks_enable(2, 0x0330);
-// play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
-//#ifndef VERSION_JP
-// play_sound(SOUND_MARIO_HAHA, m->marioObj->header.gfx.cameraToObject);
-//#endif
-// advance_cutscene_step(m);
-// }
-// }
+static void intro_cutscene_jump_out_of_pipe(struct MarioState *m)
+{
+ // if (m->actionTimer == 25) {
+ // gHudDisplay.flags = HUD_DISPLAY_DEFAULT;
+ // }
+ //
+ // if (m->actionTimer++ >= 118) {
+ // m->marioObj->header.gfx.node.flags |= GRAPH_RENDER_ACTIVE;
+ //
+ //#ifdef VERSION_EU
+ // // For some reason these calls were swapped.
+ // play_sound_if_no_flag(m, SOUND_ACTION_HIT_3, MARIO_ACTION_SOUND_PLAYED);
+ // play_sound_if_no_flag(m, SOUND_MARIO_YAHOO, MARIO_MARIO_SOUND_PLAYED);
+ //#else
+ // play_sound_if_no_flag(m, SOUND_MARIO_YAHOO, MARIO_MARIO_SOUND_PLAYED);
+ // #ifndef VERSION_JP
+ // play_sound_if_no_flag(m, SOUND_ACTION_HIT_3, MARIO_ACTION_SOUND_PLAYED);
+ // #endif
+ //#endif
+ //
+ // set_mario_animation(m, MARIO_ANIM_SINGLE_JUMP);
+ // mario_set_forward_vel(m, 10.0f);
+ // if (perform_air_step(m, 0) == AIR_STEP_LANDED) {
+ // sound_banks_enable(2, 0x0330);
+ // play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
+ //#ifndef VERSION_JP
+ // play_sound(SOUND_MARIO_HAHA, m->marioObj->header.gfx.cameraToObject);
+ //#endif
+ // advance_cutscene_step(m);
+ // }
+ // }
}
-static void intro_cutscene_land_outside_pipe(struct MarioState *m) {
+static void intro_cutscene_land_outside_pipe(struct MarioState *m)
+{
set_mario_animation(m, MARIO_ANIM_LAND_FROM_SINGLE_JUMP);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
advance_cutscene_step(m);
}
stop_and_set_height_to_floor(m);
}
-static void intro_cutscene_lower_pipe(struct MarioState *m) {
- if (m->actionTimer++ == 0) {
+static void intro_cutscene_lower_pipe(struct MarioState *m)
+{
+ if (m->actionTimer++ == 0)
+ {
play_sound(SOUND_MENU_ENTER_PIPE, sIntroWarpPipeObj->header.gfx.cameraToObject);
set_mario_animation(m, MARIO_ANIM_FIRST_PERSON);
}
sIntroWarpPipeObj->oPosY -= 5.0f;
- if (sIntroWarpPipeObj->oPosY <= 50.0f) {
-// obj_mark_for_deletion(sIntroWarpPipeObj);
+ if (sIntroWarpPipeObj->oPosY <= 50.0f)
+ {
+ // obj_mark_for_deletion(sIntroWarpPipeObj);
advance_cutscene_step(m);
}
stop_and_set_height_to_floor(m);
}
-static void intro_cutscene_set_mario_to_idle(struct MarioState *m) {
-// if (gCamera->cutscene == 0) {
- gCameraMovementFlags &= ~CAM_MOVE_C_UP_MODE;
- set_mario_action(m, ACT_IDLE, 0);
-// }
+static void intro_cutscene_set_mario_to_idle(struct MarioState *m)
+{
+ // if (gCamera->cutscene == 0) {
+ gCameraMovementFlags &= ~CAM_MOVE_C_UP_MODE;
+ set_mario_action(m, ACT_IDLE, 0);
+ // }
stop_and_set_height_to_floor(m);
}
-enum {
+enum
+{
INTRO_CUTSCENE_HIDE_HUD_AND_MARIO,
INTRO_CUTSCENE_PEACH_LAKITU_SCENE,
INTRO_CUTSCENE_RAISE_PIPE,
@@ -1813,8 +2040,10 @@ enum {
INTRO_CUTSCENE_SET_MARIO_TO_IDLE
};
-static s32 act_intro_cutscene(struct MarioState *m) {
- switch (m->actionArg) {
+static s32 act_intro_cutscene(struct MarioState *m)
+{
+ switch (m->actionArg)
+ {
case INTRO_CUTSCENE_HIDE_HUD_AND_MARIO:
intro_cutscene_hide_hud_and_mario(m);
break;
@@ -1841,55 +2070,64 @@ static s32 act_intro_cutscene(struct MarioState *m) {
}
// jumbo star cutscene: Mario lands after grabbing the jumbo star
-static void jumbo_star_cutscene_falling(struct MarioState *m) {
-// if (m->actionState == 0) {
-// m->input |= INPUT_A_DOWN;
-// m->flags |= (MARIO_WING_CAP | MARIO_CAP_ON_HEAD);
+static void jumbo_star_cutscene_falling(struct MarioState *m)
+{
+ // if (m->actionState == 0) {
+ // m->input |= INPUT_A_DOWN;
+ // m->flags |= (MARIO_WING_CAP | MARIO_CAP_ON_HEAD);
-// m->faceAngle[1] = -0x8000;
-// m->pos[0] = 0.0f;
-// m->pos[2] = 0.0f;
+ // m->faceAngle[1] = -0x8000;
+ // m->pos[0] = 0.0f;
+ // m->pos[2] = 0.0f;
-// mario_set_forward_vel(m, 0.0f);
-// set_mario_animation(m, MARIO_ANIM_GENERAL_FALL);
+ // mario_set_forward_vel(m, 0.0f);
+ // set_mario_animation(m, MARIO_ANIM_GENERAL_FALL);
-// if (perform_air_step(m, 1) == AIR_STEP_LANDED) {
-// play_cutscene_music(SEQUENCE_ARGS(15, SEQ_EVENT_CUTSCENE_VICTORY));
-// play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
-// m->actionState++;
-// }
-// } else {
-// set_mario_animation(m, MARIO_ANIM_GENERAL_LAND);
-// if (is_anim_at_end(m)) {
-// m->statusForCamera->cameraEvent = CAM_EVENT_START_GRAND_STAR;
-// advance_cutscene_step(m);
-// }
-// }
+ // if (perform_air_step(m, 1) == AIR_STEP_LANDED) {
+ // play_cutscene_music(SEQUENCE_ARGS(15, SEQ_EVENT_CUTSCENE_VICTORY));
+ // play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
+ // m->actionState++;
+ // }
+ // } else {
+ // set_mario_animation(m, MARIO_ANIM_GENERAL_LAND);
+ // if (is_anim_at_end(m)) {
+ // m->statusForCamera->cameraEvent = CAM_EVENT_START_GRAND_STAR;
+ // advance_cutscene_step(m);
+ // }
+ // }
}
// jumbo star cutscene: Mario takes off
-static s32 jumbo_star_cutscene_taking_off(struct MarioState *m) {
+static s32 jumbo_star_cutscene_taking_off(struct MarioState *m)
+{
struct Object *marioObj = m->marioObj;
s32 animFrame;
- if (m->actionState == 0) {
+ if (m->actionState == 0)
+ {
set_mario_animation(m, MARIO_ANIM_FINAL_BOWSER_RAISE_HAND_SPIN);
marioObj->rawData.asF32[0x22] = 0.0f;
- if (is_anim_past_end(m)) {
+ if (is_anim_past_end(m))
+ {
play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
m->actionState++;
}
- } else {
+ }
+ else
+ {
animFrame = set_mario_animation(m, MARIO_ANIM_FINAL_BOWSER_WING_CAP_TAKE_OFF);
- if (animFrame == 3 || animFrame == 28 || animFrame == 60) {
+ if (animFrame == 3 || animFrame == 28 || animFrame == 60)
+ {
play_sound_and_spawn_particles(m, SOUND_ACTION_TERRAIN_JUMP, 1);
}
- if (animFrame >= 3) {
+ if (animFrame >= 3)
+ {
marioObj->rawData.asF32[0x22] -= 32.0f;
}
- switch (animFrame) {
+ switch (animFrame)
+ {
case 3:
play_sound(SOUND_MARIO_YAH_WAH_HOO + (gAudioRandom % 3 << 16),
m->marioObj->header.gfx.cameraToObject);
@@ -1905,7 +2143,8 @@ static s32 jumbo_star_cutscene_taking_off(struct MarioState *m) {
}
m->particleFlags |= PARTICLE_SPARKLES;
- if (is_anim_past_end(m)) {
+ if (is_anim_past_end(m))
+ {
advance_cutscene_step(m);
}
}
@@ -1921,27 +2160,33 @@ static s32 jumbo_star_cutscene_taking_off(struct MarioState *m) {
}
// jumbo star cutscene: Mario flying
-static s32 jumbo_star_cutscene_flying(struct MarioState *m) {
+static s32 jumbo_star_cutscene_flying(struct MarioState *m)
+{
Vec3f targetPos;
- UNUSED struct Object *marioObj = m->marioObj;
+ UNUSED
+ struct Object *marioObj = m->marioObj;
f32 targetDX;
f32 targetDY;
f32 targetDZ;
f32 targetHyp;
s16 targetAngle;
- switch (m->actionState) {
+ switch (m->actionState)
+ {
case 0:
set_mario_animation(m, MARIO_ANIM_WING_CAP_FLY);
anim_spline_init(sJumboStarKeyframes);
m->actionState++;
- // fall through
+ // fall through
case 1:
- if (anim_spline_poll(targetPos)) {
+ if (anim_spline_poll(targetPos))
+ {
// does this twice
set_mario_action(m, ACT_FREEFALL, 0);
m->actionState++;
- } else {
+ }
+ else
+ {
targetDX = targetPos[0] - m->pos[0];
targetDY = targetPos[1] - m->pos[1];
targetDZ = targetPos[2] - m->pos[2];
@@ -1964,17 +2209,23 @@ static s32 jumbo_star_cutscene_flying(struct MarioState *m) {
vec3f_copy(m->marioObj->header.gfx.pos, m->pos);
m->particleFlags |= PARTICLE_SPARKLES;
- if (m->actionTimer++ == 500) {
+ if (m->actionTimer++ == 500)
+ {
level_trigger_warp(m, WARP_OP_CREDITS_START);
}
return FALSE;
}
-enum { JUMBO_STAR_CUTSCENE_FALLING, JUMBO_STAR_CUTSCENE_TAKING_OFF, JUMBO_STAR_CUTSCENE_FLYING };
+enum
+{
+ JUMBO_STAR_CUTSCENE_FALLING, JUMBO_STAR_CUTSCENE_TAKING_OFF, JUMBO_STAR_CUTSCENE_FLYING
+};
-static s32 act_jumbo_star_cutscene(struct MarioState *m) {
- switch (m->actionArg) {
+static s32 act_jumbo_star_cutscene(struct MarioState *m)
+{
+ switch (m->actionArg)
+ {
case JUMBO_STAR_CUTSCENE_FALLING:
jumbo_star_cutscene_falling(m);
break;
@@ -1988,27 +2239,28 @@ static s32 act_jumbo_star_cutscene(struct MarioState *m) {
return FALSE;
}
-void generate_yellow_sparkles(s16 x, s16 y, s16 z, f32 radius) {
-// static s32 sSparkleGenTheta = 0;
-// static s32 sSparkleGenPhi = 0;
+void generate_yellow_sparkles(s16 x, s16 y, s16 z, f32 radius)
+{
+ // static s32 sSparkleGenTheta = 0;
+ // static s32 sSparkleGenPhi = 0;
-// s16 offsetX = radius * coss(sSparkleGenTheta) * sins(sSparkleGenPhi);
-// s16 offsetY = radius * sins(sSparkleGenTheta);
-// s16 offsetZ = radius * coss(sSparkleGenTheta) * coss(sSparkleGenPhi);
+ // s16 offsetX = radius * coss(sSparkleGenTheta) * sins(sSparkleGenPhi);
+ // s16 offsetY = radius * sins(sSparkleGenTheta);
+ // s16 offsetZ = radius * coss(sSparkleGenTheta) * coss(sSparkleGenPhi);
-// spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_NONE, bhvSparkleSpawn, x + offsetX, y + offsetY,
-// z + offsetZ, 0, 0, 0);
+ // spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_NONE, bhvSparkleSpawn, x + offsetX, y + offsetY,
+ // z + offsetZ, 0, 0, 0);
-// //! copy paste error
-// offsetX = offsetX * 4 / 3;
-// offsetX = offsetY * 4 / 3;
-// offsetX = offsetZ * 4 / 3;
+ // //! copy paste error
+ // offsetX = offsetX * 4 / 3;
+ // offsetX = offsetY * 4 / 3;
+ // offsetX = offsetZ * 4 / 3;
-// spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_NONE, bhvSparkleSpawn, x - offsetX, y - offsetY,
-// z - offsetZ, 0, 0, 0);
+ // spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_NONE, bhvSparkleSpawn, x - offsetX, y - offsetY,
+ // z - offsetZ, 0, 0, 0);
-// sSparkleGenTheta += 0x3800;
-// sSparkleGenPhi += 0x6000;
+ // sSparkleGenTheta += 0x3800;
+ // sSparkleGenPhi += 0x6000;
}
// not sure what this does, returns the height of the floor.
@@ -2019,157 +2271,169 @@ void generate_yellow_sparkles(s16 x, s16 y, s16 z, f32 radius) {
// f32 sp20;
// f32 sp1C;
// f32 sp18;
-//
+//
// find_mario_anim_flags_and_translation(o, o->header.gfx.angle[1], sp24);
-//
+//
// sp20 = o->header.gfx.pos[0] + sp24[0];
// sp1C = o->header.gfx.pos[1] + 10.0f;
// sp18 = o->header.gfx.pos[2] + sp24[2];
-//
+//
// return find_floor(sp20, sp1C, sp18, &surf);
// }
// make Mario fall and soften wing cap gravity
-static void end_peach_cutscene_mario_falling(struct MarioState *m) {
-// if (m->actionTimer == 1) {
-// m->statusForCamera->cameraEvent = CAM_EVENT_START_ENDING;
-// }
+static void end_peach_cutscene_mario_falling(struct MarioState *m)
+{
+ // if (m->actionTimer == 1) {
+ // m->statusForCamera->cameraEvent = CAM_EVENT_START_ENDING;
+ // }
-// m->input |= INPUT_A_DOWN;
-// m->flags |= (MARIO_WING_CAP | MARIO_CAP_ON_HEAD);
+ // m->input |= INPUT_A_DOWN;
+ // m->flags |= (MARIO_WING_CAP | MARIO_CAP_ON_HEAD);
-// set_mario_animation(m, MARIO_ANIM_GENERAL_FALL);
-// mario_set_forward_vel(m, 0.0f);
+ // set_mario_animation(m, MARIO_ANIM_GENERAL_FALL);
+ // mario_set_forward_vel(m, 0.0f);
-// if (perform_air_step(m, 0) == AIR_STEP_LANDED) {
-// play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
-// advance_cutscene_step(m);
-// }
+ // if (perform_air_step(m, 0) == AIR_STEP_LANDED) {
+ // play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
+ // advance_cutscene_step(m);
+ // }
}
// set Mario on the ground, wait and spawn the jumbo star outside the castle.
-static void end_peach_cutscene_mario_landing(struct MarioState *m) {
-// set_mario_animation(m, MARIO_ANIM_GENERAL_LAND);
-// stop_and_set_height_to_floor(m);
+static void end_peach_cutscene_mario_landing(struct MarioState *m)
+{
+ // set_mario_animation(m, MARIO_ANIM_GENERAL_LAND);
+ // stop_and_set_height_to_floor(m);
-// if (is_anim_at_end(m)) {
-// // make wing cap run out
-// m->capTimer = 60;
+ // if (is_anim_at_end(m)) {
+ // // make wing cap run out
+ // m->capTimer = 60;
-// sEndJumboStarObj = spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_STAR, bhvStaticObject, 0,
-// 2528, -1800, 0, 0, 0);
-// obj_scale(sEndJumboStarObj, 3.0);
-// advance_cutscene_step(m);
-// }
+ // sEndJumboStarObj = spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_STAR, bhvStaticObject, 0,
+ // 2528, -1800, 0, 0, 0);
+ // obj_scale(sEndJumboStarObj, 3.0);
+ // advance_cutscene_step(m);
+ // }
}
// raise hand animation, lower hand animation, do some special effects
-static void end_peach_cutscene_summon_jumbo_star(struct MarioState *m) {
-// set_mario_animation(m, m->actionState == 0 ? MARIO_ANIM_CREDITS_RAISE_HAND
-// : MARIO_ANIM_CREDITS_LOWER_HAND);
+static void end_peach_cutscene_summon_jumbo_star(struct MarioState *m)
+{
+ // set_mario_animation(m, m->actionState == 0 ? MARIO_ANIM_CREDITS_RAISE_HAND
+ // : MARIO_ANIM_CREDITS_LOWER_HAND);
-// if (m->actionState == 0 && is_anim_past_end(m)) {
-// m->actionState++;
-// }
-// if (m->actionTimer == 90) {
-// play_cutscene_music(SEQUENCE_ARGS(0, SEQ_EVENT_CUTSCENE_ENDING));
-// }
-// if (m->actionTimer == 255) {
-// advance_cutscene_step(m);
-// }
+ // if (m->actionState == 0 && is_anim_past_end(m)) {
+ // m->actionState++;
+ // }
+ // if (m->actionTimer == 90) {
+ // play_cutscene_music(SEQUENCE_ARGS(0, SEQ_EVENT_CUTSCENE_ENDING));
+ // }
+ // if (m->actionTimer == 255) {
+ // advance_cutscene_step(m);
+ // }
-// sEndJumboStarObj->oFaceAngleYaw += 0x0400;
-// generate_yellow_sparkles(0, 2528, -1800, 250.0f);
-// play_sound(SOUND_AIR_PEACH_TWINKLE, sEndJumboStarObj->header.gfx.cameraToObject);
+ // sEndJumboStarObj->oFaceAngleYaw += 0x0400;
+ // generate_yellow_sparkles(0, 2528, -1800, 250.0f);
+ // play_sound(SOUND_AIR_PEACH_TWINKLE, sEndJumboStarObj->header.gfx.cameraToObject);
}
#ifdef VERSION_EU
- #define TIMER_FADE_IN_PEACH 201
- #define TIMER_DESCEND_PEACH 280
+#define TIMER_FADE_IN_PEACH 201
+#define TIMER_DESCEND_PEACH 280
#else
- #define TIMER_FADE_IN_PEACH 276
- #define TIMER_DESCEND_PEACH 355
+#define TIMER_FADE_IN_PEACH 276
+#define TIMER_DESCEND_PEACH 355
#endif
// free peach from the stained glass window
-static void end_peach_cutscene_spawn_peach(struct MarioState *m) {
-// if (m->actionTimer == 1) {
-// play_transition(WARP_TRANSITION_FADE_INTO_COLOR, 14, 255, 255, 255);
-// }
-// if (m->actionTimer == 2) {
-// play_sound(SOUND_MENU_STAR_SOUND, gDefaultSoundArgs);
-// }
-// if (m->actionTimer == 44) {
-// play_transition(WARP_TRANSITION_FADE_FROM_COLOR, 192, 255, 255, 255);
-// }
-// if (m->actionTimer == 40) {
-// obj_mark_for_deletion(sEndJumboStarObj);
+static void end_peach_cutscene_spawn_peach(struct MarioState *m)
+{
+ // if (m->actionTimer == 1) {
+ // play_transition(WARP_TRANSITION_FADE_INTO_COLOR, 14, 255, 255, 255);
+ // }
+ // if (m->actionTimer == 2) {
+ // play_sound(SOUND_MENU_STAR_SOUND, gDefaultSoundArgs);
+ // }
+ // if (m->actionTimer == 44) {
+ // play_transition(WARP_TRANSITION_FADE_FROM_COLOR, 192, 255, 255, 255);
+ // }
+ // if (m->actionTimer == 40) {
+ // obj_mark_for_deletion(sEndJumboStarObj);
-// sEndPeachObj = spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_PEACH, bhvEndPeach, 0, 2428,
-// -1300, 0, 0, 0);
-// gCutsceneFocus = sEndPeachObj;
+ // sEndPeachObj = spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_PEACH, bhvEndPeach, 0, 2428,
+ // -1300, 0, 0, 0);
+ // gCutsceneFocus = sEndPeachObj;
-// sEndRightToadObj = spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_TOAD, bhvEndToad, 200,
-// 906, -1290, 0, 0, 0);
+ // sEndRightToadObj = spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_TOAD, bhvEndToad, 200,
+ // 906, -1290, 0, 0, 0);
-// sEndLeftToadObj = spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_TOAD, bhvEndToad, -200,
-// 906, -1290, 0, 0, 0);
+ // sEndLeftToadObj = spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_TOAD, bhvEndToad, -200,
+ // 906, -1290, 0, 0, 0);
-// sEndPeachObj->oOpacity = 127;
-// sEndRightToadObj->oOpacity = 255;
-// sEndLeftToadObj->oOpacity = 255;
+ // sEndPeachObj->oOpacity = 127;
+ // sEndRightToadObj->oOpacity = 255;
+ // sEndLeftToadObj->oOpacity = 255;
-// D_8032CBE4 = 4;
-// sEndPeachAnimation = 4;
+ // D_8032CBE4 = 4;
+ // sEndPeachAnimation = 4;
-// sEndToadAnims[0] = 4;
-// sEndToadAnims[1] = 5;
-// }
+ // sEndToadAnims[0] = 4;
+ // sEndToadAnims[1] = 5;
+ // }
-// if (m->actionTimer >= TIMER_FADE_IN_PEACH) {
-// sEndPeachObj->oOpacity = camera_approach_f32_symmetric(sEndPeachObj->oOpacity, 255.0f, 2.0f);
-// }
-// if (m->actionTimer >= 40) {
-// generate_yellow_sparkles(0, 2628, -1300, 150.0f);
-// }
+ // if (m->actionTimer >= TIMER_FADE_IN_PEACH) {
+ // sEndPeachObj->oOpacity = camera_approach_f32_symmetric(sEndPeachObj->oOpacity, 255.0f, 2.0f);
+ // }
+ // if (m->actionTimer >= 40) {
+ // generate_yellow_sparkles(0, 2628, -1300, 150.0f);
+ // }
-// if (m->actionTimer == TIMER_DESCEND_PEACH) {
-// advance_cutscene_step(m);
-// }
-// // probably added sounds later and missed the previous >= 40 check
-// if (m->actionTimer >= 40) {
-// play_sound(SOUND_AIR_PEACH_TWINKLE, sEndPeachObj->header.gfx.cameraToObject);
-// }
+ // if (m->actionTimer == TIMER_DESCEND_PEACH) {
+ // advance_cutscene_step(m);
+ // }
+ // // probably added sounds later and missed the previous >= 40 check
+ // if (m->actionTimer >= 40) {
+ // play_sound(SOUND_AIR_PEACH_TWINKLE, sEndPeachObj->header.gfx.cameraToObject);
+ // }
}
#ifdef VERSION_EU
- #define TIMER_RUN_TO_PEACH 531
+#define TIMER_RUN_TO_PEACH 531
#else
- #define TIMER_RUN_TO_PEACH 584
+#define TIMER_RUN_TO_PEACH 584
#endif
// descend peach
-static void end_peach_cutscene_descend_peach(struct MarioState *m) {
+static void end_peach_cutscene_descend_peach(struct MarioState *m)
+{
generate_yellow_sparkles(0, sEndPeachObj->oPosY, -1300, 150.0f);
- if (sEndPeachObj->oPosY >= 1300.0f) {
- if (m->actionState < 60) {
+ if (sEndPeachObj->oPosY >= 1300.0f)
+ {
+ if (m->actionState < 60)
+ {
m->actionState += 5;
}
- } else {
- if (m->actionState >= 27) {
+ }
+ else
+ {
+ if (m->actionState >= 27)
+ {
m->actionState -= 2;
}
set_mario_animation(m, MARIO_ANIM_CREDITS_RETURN_FROM_LOOK_UP);
}
- if ((sEndPeachObj->oPosY -= m->actionState / 10) <= 907.0f) {
+ if ((sEndPeachObj->oPosY -= m->actionState / 10) <= 907.0f)
+ {
sEndPeachObj->oPosY = 906.0f;
}
play_sound(SOUND_AIR_PEACH_TWINKLE, sEndPeachObj->header.gfx.cameraToObject);
- if (m->actionTimer >= TIMER_RUN_TO_PEACH) {
+ if (m->actionTimer >= TIMER_RUN_TO_PEACH)
+ {
advance_cutscene_step(m);
}
}
@@ -2177,14 +2441,17 @@ static void end_peach_cutscene_descend_peach(struct MarioState *m) {
#undef TIMER_RUN_TO_PEACH
// Mario runs to peach
-static void end_peach_cutscene_run_to_peach(struct MarioState *m) {
+static void end_peach_cutscene_run_to_peach(struct MarioState *m)
+{
struct SM64SurfaceCollisionData *surf;
- if (m->actionTimer == 22) {
+ if (m->actionTimer == 22)
+ {
sEndPeachAnimation = 5;
}
- if ((m->pos[2] -= 20.0f) <= -1181.0f) {
+ if ((m->pos[2] -= 20.0f) <= -1181.0f)
+ {
m->pos[2] = -1180.0f;
advance_cutscene_step(m);
}
@@ -2201,109 +2468,111 @@ static void end_peach_cutscene_run_to_peach(struct MarioState *m) {
// dialog 1
// "Mario!"
// "The power of the Stars is restored to the castle..."
-static void end_peach_cutscene_dialog_1(struct MarioState *m) {
-// s32 animFrame = set_mario_animation(m, m->actionState == 0 ? MARIO_ANIM_CREDITS_TAKE_OFF_CAP
-// : MARIO_ANIM_CREDITS_LOOK_UP);
-//
-// if (m->actionState == 0) {
-// if (animFrame == 8) {
-// cutscene_take_cap_off(m);
-// }
-//
-// if (is_anim_at_end(m)) {
-// m->actionState++;
-// }
-// }
-//
-// switch (m->actionTimer) {
-// case 80:
-// sEndPeachAnimation = 6;
-// break;
-//
-// case 81:
-// D_8032CBE4 = 3;
-// break;
-//
-// case 145:
-// D_8032CBE4 = 2;
-// break;
-//
-// case 228:
-// D_8032CBE4 = 1;
-// D_8032CBE8 = 1;
-// break;
-//
-// case 230:
-// set_cutscene_message(160, 227, 0, 30);
-//#ifndef VERSION_JP
-//// func_8031FFB4(SEQ_PLAYER_LEVEL, 60, 40);
-// play_sound(SOUND_PEACH_MARIO, sEndPeachObj->header.gfx.cameraToObject);
-//#endif
-// break;
-//
-// case 275:
-// D_8032CBE4 = 0;
-// D_8032CBE8 = 0;
-// break;
-//
-// case 290:
-// set_cutscene_message(160, 227, 1, 60);
-//#ifndef VERSION_JP
-// play_sound(SOUND_PEACH_POWER_OF_THE_STARS, sEndPeachObj->header.gfx.cameraToObject);
-//#endif
-// break;
-//
-// case 480:
-// advance_cutscene_step(m);
-// break;
-// }
+static void end_peach_cutscene_dialog_1(struct MarioState *m)
+{
+ // s32 animFrame = set_mario_animation(m, m->actionState == 0 ? MARIO_ANIM_CREDITS_TAKE_OFF_CAP
+ // : MARIO_ANIM_CREDITS_LOOK_UP);
+ //
+ // if (m->actionState == 0) {
+ // if (animFrame == 8) {
+ // cutscene_take_cap_off(m);
+ // }
+ //
+ // if (is_anim_at_end(m)) {
+ // m->actionState++;
+ // }
+ // }
+ //
+ // switch (m->actionTimer) {
+ // case 80:
+ // sEndPeachAnimation = 6;
+ // break;
+ //
+ // case 81:
+ // D_8032CBE4 = 3;
+ // break;
+ //
+ // case 145:
+ // D_8032CBE4 = 2;
+ // break;
+ //
+ // case 228:
+ // D_8032CBE4 = 1;
+ // D_8032CBE8 = 1;
+ // break;
+ //
+ // case 230:
+ // set_cutscene_message(160, 227, 0, 30);
+ //#ifndef VERSION_JP
+ //// func_8031FFB4(SEQ_PLAYER_LEVEL, 60, 40);
+ // play_sound(SOUND_PEACH_MARIO, sEndPeachObj->header.gfx.cameraToObject);
+ //#endif
+ // break;
+ //
+ // case 275:
+ // D_8032CBE4 = 0;
+ // D_8032CBE8 = 0;
+ // break;
+ //
+ // case 290:
+ // set_cutscene_message(160, 227, 1, 60);
+ //#ifndef VERSION_JP
+ // play_sound(SOUND_PEACH_POWER_OF_THE_STARS, sEndPeachObj->header.gfx.cameraToObject);
+ //#endif
+ // break;
+ //
+ // case 480:
+ // advance_cutscene_step(m);
+ // break;
+ // }
}
#ifdef VERSION_EU
- #define TIMER_SOMETHING_SPECIAL 150
- #define TIMER_PEACH_KISS 260
+#define TIMER_SOMETHING_SPECIAL 150
+#define TIMER_PEACH_KISS 260
#else
- #define TIMER_SOMETHING_SPECIAL 130
- #define TIMER_PEACH_KISS 200
+#define TIMER_SOMETHING_SPECIAL 130
+#define TIMER_PEACH_KISS 200
#endif
// dialog 2
// "...and it's all thanks to you!"
// "Thank you Mario!"
// "We have to do something special for you..."
-static void end_peach_cutscene_dialog_2(struct MarioState *m) {
-// sEndPeachAnimation = 9;
-//
-// switch (m->actionTimer) {
-// case 29:
-// set_cutscene_message(160, 227, 2, 30);
-//#ifndef VERSION_JP
-// play_sound(SOUND_PEACH_THANKS_TO_YOU, sEndPeachObj->header.gfx.cameraToObject);
-//#endif
-// break;
-//
-// case 45:
-// D_8032CBE8 = 1;
-// break;
-//
-// case 75:
-// set_cutscene_message(160, 227, 3, 30);
-//#ifndef VERSION_JP
-// play_sound(SOUND_PEACH_THANK_YOU_MARIO, sEndPeachObj->header.gfx.cameraToObject);
-//#endif
-// break;
-//
-// case TIMER_SOMETHING_SPECIAL:
-// set_cutscene_message(160, 227, 4, 40);
-//#ifndef VERSION_JP
-// play_sound(SOUND_PEACH_SOMETHING_SPECIAL, sEndPeachObj->header.gfx.cameraToObject);
-//#endif
-// break;
-//
-// case TIMER_PEACH_KISS:
-// advance_cutscene_step(m);
-// break;
-// }
+static void end_peach_cutscene_dialog_2(struct MarioState *m)
+{
+ // sEndPeachAnimation = 9;
+ //
+ // switch (m->actionTimer) {
+ // case 29:
+ // set_cutscene_message(160, 227, 2, 30);
+ //#ifndef VERSION_JP
+ // play_sound(SOUND_PEACH_THANKS_TO_YOU, sEndPeachObj->header.gfx.cameraToObject);
+ //#endif
+ // break;
+ //
+ // case 45:
+ // D_8032CBE8 = 1;
+ // break;
+ //
+ // case 75:
+ // set_cutscene_message(160, 227, 3, 30);
+ //#ifndef VERSION_JP
+ // play_sound(SOUND_PEACH_THANK_YOU_MARIO, sEndPeachObj->header.gfx.cameraToObject);
+ //#endif
+ // break;
+ //
+ // case TIMER_SOMETHING_SPECIAL:
+ // set_cutscene_message(160, 227, 4, 40);
+ //#ifndef VERSION_JP
+ // play_sound(SOUND_PEACH_SOMETHING_SPECIAL, sEndPeachObj->header.gfx.cameraToObject);
+ //#endif
+ // break;
+ //
+ // case TIMER_PEACH_KISS:
+ // advance_cutscene_step(m);
+ // break;
+ // }
}
#undef TIMER_SOMETHING_SPECIAL
@@ -2318,167 +2587,174 @@ static void end_peach_cutscene_dialog_2(struct MarioState *m) {
// MARIO_EYES_HALF_CLOSED, MARIO_EYES_HALF_CLOSED, MARIO_EYES_CLOSED, MARIO_EYES_CLOSED,
// };
-static void end_peach_cutscene_kiss_from_peach(struct MarioState *m) {
-// sEndPeachAnimation = 10;
-//
-// if (m->actionTimer >= 90) {
-// m->marioBodyState->eyeState =
-// m->actionTimer < 110 ? sMarioBlinkOverride[m->actionTimer - 90] : MARIO_EYES_HALF_CLOSED;
-// }
-//
-// switch (m->actionTimer) {
-// case 8:
-// D_8032CBE8 = 0;
-// break;
-//
-// case 10:
-// D_8032CBE4 = 3;
-// break;
-//
-// case 50:
-// D_8032CBE4 = 4;
-// break;
-//
-// case 75:
-// m->marioBodyState->eyeState = MARIO_EYES_HALF_CLOSED;
-// break;
-//
-// case 76:
-// m->marioBodyState->eyeState = MARIO_EYES_CLOSED;
-// break;
-//
-// case 100:
-// D_8032CBE4 = 3;
-// break;
-//
-// case 136:
-// D_8032CBE4 = 0;
-// break;
-//
-// case 140:
-// advance_cutscene_step(m);
-// break;
-// }
+static void end_peach_cutscene_kiss_from_peach(struct MarioState *m)
+{
+ // sEndPeachAnimation = 10;
+ //
+ // if (m->actionTimer >= 90) {
+ // m->marioBodyState->eyeState =
+ // m->actionTimer < 110 ? sMarioBlinkOverride[m->actionTimer - 90] : MARIO_EYES_HALF_CLOSED;
+ // }
+ //
+ // switch (m->actionTimer) {
+ // case 8:
+ // D_8032CBE8 = 0;
+ // break;
+ //
+ // case 10:
+ // D_8032CBE4 = 3;
+ // break;
+ //
+ // case 50:
+ // D_8032CBE4 = 4;
+ // break;
+ //
+ // case 75:
+ // m->marioBodyState->eyeState = MARIO_EYES_HALF_CLOSED;
+ // break;
+ //
+ // case 76:
+ // m->marioBodyState->eyeState = MARIO_EYES_CLOSED;
+ // break;
+ //
+ // case 100:
+ // D_8032CBE4 = 3;
+ // break;
+ //
+ // case 136:
+ // D_8032CBE4 = 0;
+ // break;
+ //
+ // case 140:
+ // advance_cutscene_step(m);
+ // break;
+ // }
}
-static void end_peach_cutscene_star_dance(struct MarioState *m) {
-// s32 animFrame = set_mario_animation(m, MARIO_ANIM_CREDITS_PEACE_SIGN);
-//
-// if (animFrame == 77) {
-// cutscene_put_cap_on(m);
-// }
-// if (animFrame == 88) {
-// play_sound(SOUND_MARIO_HERE_WE_GO, m->marioObj->header.gfx.cameraToObject);
-// }
-// if (animFrame >= 98) {
-// m->marioBodyState->handState = MARIO_HAND_PEACE_SIGN;
-// }
-//
-// if (m->actionTimer < 52) {
-// m->marioBodyState->eyeState = MARIO_EYES_HALF_CLOSED;
-// }
-//
-// switch (m->actionTimer) {
-// case 70:
-// D_8032CBE4 = 1;
-// break;
-//
-// case 86:
-// D_8032CBE4 = 2;
-// break;
-//
-// case 90:
-// D_8032CBE4 = 3;
-// break;
-//
-// case 120:
-// D_8032CBE4 = 0;
-// break;
-//
-// case 140:
-//#ifndef VERSION_JP
-//// sequence_player_unlower(SEQ_PLAYER_LEVEL, 60);
-//#endif
-// play_cutscene_music(SEQUENCE_ARGS(15, SEQ_EVENT_CUTSCENE_CREDITS));
-// break;
-//
-// case 142:
-// advance_cutscene_step(m);
-// break;
-// }
+static void end_peach_cutscene_star_dance(struct MarioState *m)
+{
+ // s32 animFrame = set_mario_animation(m, MARIO_ANIM_CREDITS_PEACE_SIGN);
+ //
+ // if (animFrame == 77) {
+ // cutscene_put_cap_on(m);
+ // }
+ // if (animFrame == 88) {
+ // play_sound(SOUND_MARIO_HERE_WE_GO, m->marioObj->header.gfx.cameraToObject);
+ // }
+ // if (animFrame >= 98) {
+ // m->marioBodyState->handState = MARIO_HAND_PEACE_SIGN;
+ // }
+ //
+ // if (m->actionTimer < 52) {
+ // m->marioBodyState->eyeState = MARIO_EYES_HALF_CLOSED;
+ // }
+ //
+ // switch (m->actionTimer) {
+ // case 70:
+ // D_8032CBE4 = 1;
+ // break;
+ //
+ // case 86:
+ // D_8032CBE4 = 2;
+ // break;
+ //
+ // case 90:
+ // D_8032CBE4 = 3;
+ // break;
+ //
+ // case 120:
+ // D_8032CBE4 = 0;
+ // break;
+ //
+ // case 140:
+ //#ifndef VERSION_JP
+ //// sequence_player_unlower(SEQ_PLAYER_LEVEL, 60);
+ //#endif
+ // play_cutscene_music(SEQUENCE_ARGS(15, SEQ_EVENT_CUTSCENE_CREDITS));
+ // break;
+ //
+ // case 142:
+ // advance_cutscene_step(m);
+ // break;
+ // }
}
// dialog 3
// "Listen everybody"
// "let's bake a delicious cake..."
// "...for Mario..."
-static void end_peach_cutscene_dialog_3(struct MarioState *m) {
-// set_mario_animation(m, MARIO_ANIM_FIRST_PERSON);
-//
-// sEndPeachObj->oPosY = end_obj_set_visual_pos(sEndPeachObj);
-// sEndRightToadObj->oPosY = end_obj_set_visual_pos(sEndRightToadObj);
-// sEndLeftToadObj->oPosY = end_obj_set_visual_pos(sEndLeftToadObj);
-//
-// switch (m->actionTimer) {
-// case 1:
-// sEndPeachAnimation = 0;
-// sEndToadAnims[0] = 0;
-// sEndToadAnims[1] = 2;
-// D_8032CBE8 = 1;
-// set_cutscene_message(160, 227, 5, 30);
-//#ifndef VERSION_JP
-// play_sound(SOUND_PEACH_BAKE_A_CAKE, sEndPeachObj->header.gfx.cameraToObject);
-//#endif
-// break;
-//
-// case 55:
-// set_cutscene_message(160, 227, 6, 40);
-// break;
-//
-// case 130:
-// set_cutscene_message(160, 227, 7, 50);
-//#ifndef VERSION_JP
-// play_sound(SOUND_PEACH_FOR_MARIO, sEndPeachObj->header.gfx.cameraToObject);
-//#endif
-// break;
-// }
-//
-// if (m->actionTimer == 350) {
-// advance_cutscene_step(m);
-// }
+static void end_peach_cutscene_dialog_3(struct MarioState *m)
+{
+ // set_mario_animation(m, MARIO_ANIM_FIRST_PERSON);
+ //
+ // sEndPeachObj->oPosY = end_obj_set_visual_pos(sEndPeachObj);
+ // sEndRightToadObj->oPosY = end_obj_set_visual_pos(sEndRightToadObj);
+ // sEndLeftToadObj->oPosY = end_obj_set_visual_pos(sEndLeftToadObj);
+ //
+ // switch (m->actionTimer) {
+ // case 1:
+ // sEndPeachAnimation = 0;
+ // sEndToadAnims[0] = 0;
+ // sEndToadAnims[1] = 2;
+ // D_8032CBE8 = 1;
+ // set_cutscene_message(160, 227, 5, 30);
+ //#ifndef VERSION_JP
+ // play_sound(SOUND_PEACH_BAKE_A_CAKE, sEndPeachObj->header.gfx.cameraToObject);
+ //#endif
+ // break;
+ //
+ // case 55:
+ // set_cutscene_message(160, 227, 6, 40);
+ // break;
+ //
+ // case 130:
+ // set_cutscene_message(160, 227, 7, 50);
+ //#ifndef VERSION_JP
+ // play_sound(SOUND_PEACH_FOR_MARIO, sEndPeachObj->header.gfx.cameraToObject);
+ //#endif
+ // break;
+ // }
+ //
+ // if (m->actionTimer == 350) {
+ // advance_cutscene_step(m);
+ // }
}
// "Mario!"
-static void end_peach_cutscene_run_to_castle(struct MarioState *m) {
-// set_mario_animation(m, m->actionState == 0 ? MARIO_ANIM_CREDITS_START_WALK_LOOK_UP
-// : MARIO_ANIM_CREDITS_LOOK_BACK_THEN_RUN);
-//
-// m->marioObj->header.gfx.pos[1] = end_obj_set_visual_pos(m->marioObj);
-//
-// if (m->actionState == 0 && is_anim_past_end(m)) {
-// m->actionState = 1;
-// }
-//
-// if (m->actionTimer == 95) {
-// set_cutscene_message(160, 227, 0, 40);
-//#ifndef VERSION_JP
-// play_sound(SOUND_PEACH_MARIO2, sEndPeachObj->header.gfx.cameraToObject);
-//#endif
-// }
-// if (m->actionTimer == 389) {
-// advance_cutscene_step(m);
-// }
+static void end_peach_cutscene_run_to_castle(struct MarioState *m)
+{
+ // set_mario_animation(m, m->actionState == 0 ? MARIO_ANIM_CREDITS_START_WALK_LOOK_UP
+ // : MARIO_ANIM_CREDITS_LOOK_BACK_THEN_RUN);
+ //
+ // m->marioObj->header.gfx.pos[1] = end_obj_set_visual_pos(m->marioObj);
+ //
+ // if (m->actionState == 0 && is_anim_past_end(m)) {
+ // m->actionState = 1;
+ // }
+ //
+ // if (m->actionTimer == 95) {
+ // set_cutscene_message(160, 227, 0, 40);
+ //#ifndef VERSION_JP
+ // play_sound(SOUND_PEACH_MARIO2, sEndPeachObj->header.gfx.cameraToObject);
+ //#endif
+ // }
+ // if (m->actionTimer == 389) {
+ // advance_cutscene_step(m);
+ // }
}
-static void end_peach_cutscene_fade_out(struct MarioState *m) {
- if (m->actionState == 0) {
+static void end_peach_cutscene_fade_out(struct MarioState *m)
+{
+ if (m->actionState == 0)
+ {
level_trigger_warp(m, WARP_OP_CREDITS_NEXT);
-// gPaintingMarioYEntry = 1500.0f; // ensure medium water level in WDW credits cutscene
+ // gPaintingMarioYEntry = 1500.0f; // ensure medium water level in WDW credits cutscene
m->actionState = 1;
}
}
-enum {
+enum
+{
END_PEACH_CUTSCENE_MARIO_FALLING,
END_PEACH_CUTSCENE_MARIO_LANDING,
END_PEACH_CUTSCENE_SUMMON_JUMBO_STAR,
@@ -2494,8 +2770,10 @@ enum {
END_PEACH_CUTSCENE_FADE_OUT
};
-static s32 act_end_peach_cutscene(struct MarioState *m) {
- switch (m->actionArg) {
+static s32 act_end_peach_cutscene(struct MarioState *m)
+{
+ switch (m->actionArg)
+ {
case END_PEACH_CUTSCENE_MARIO_FALLING:
end_peach_cutscene_mario_falling(m);
break;
@@ -2543,129 +2821,135 @@ static s32 act_end_peach_cutscene(struct MarioState *m) {
sEndCutsceneVp.vp.vscale[1] = 360;
sEndCutsceneVp.vp.vtrans[0] = 640;
sEndCutsceneVp.vp.vtrans[1] = 480;
-// override_viewport_and_clip(NULL, &sEndCutsceneVp, 0, 0, 0);
+ // override_viewport_and_clip(NULL, &sEndCutsceneVp, 0, 0, 0);
return FALSE;
}
#ifdef VERSION_EU
- #define TIMER_CREDITS_SHOW 51
- #define TIMER_CREDITS_PROGRESS 80
- #define TIMER_CREDITS_WARP 160
+#define TIMER_CREDITS_SHOW 51
+#define TIMER_CREDITS_PROGRESS 80
+#define TIMER_CREDITS_WARP 160
#else
- #define TIMER_CREDITS_SHOW 61
- #define TIMER_CREDITS_PROGRESS 90
- #define TIMER_CREDITS_WARP 200
+#define TIMER_CREDITS_SHOW 61
+#define TIMER_CREDITS_PROGRESS 90
+#define TIMER_CREDITS_WARP 200
#endif
-static s32 act_credits_cutscene(struct MarioState *m) {
-// s32 width;
-// s32 height;
-//
-// m->statusForCamera->cameraEvent = CAM_EVENT_START_CREDITS;
-// // checks if Mario is underwater (JRB, DDD, SA, etc.)
-// if (m->pos[1] < m->waterLevel - 100) {
-// if (m->area->camera->mode != CAMERA_MODE_BEHIND_MARIO) {
-// set_camera_mode(m->area->camera, CAMERA_MODE_BEHIND_MARIO, 1);
-// }
-// set_mario_animation(m, MARIO_ANIM_WATER_IDLE);
-// vec3f_copy(m->marioObj->header.gfx.pos, m->pos);
-// // will copy over roll and pitch, if set
-// vec3s_copy(m->marioObj->header.gfx.angle, m->faceAngle);
-// m->particleFlags |= PARTICLE_BUBBLE;
-// } else {
-// set_mario_animation(m, MARIO_ANIM_FIRST_PERSON);
-// if (m->actionTimer > 0) {
-// stop_and_set_height_to_floor(m);
-// }
-// }
-//
-// if (m->actionTimer >= TIMER_CREDITS_SHOW) {
-// if (m->actionState < 40) {
-// m->actionState += 2;
-// }
-//
-// width = m->actionState * 640 / 100;
-// height = m->actionState * 480 / 100;
-//
-// sEndCutsceneVp.vp.vscale[0] = 640 - width;
-// sEndCutsceneVp.vp.vscale[1] = 480 - height;
-// sEndCutsceneVp.vp.vtrans[0] =
-// (gCurrCreditsEntry->unk02 & 0x10 ? width : -width) * 56 / 100 + 640;
-// sEndCutsceneVp.vp.vtrans[1] =
-// (gCurrCreditsEntry->unk02 & 0x20 ? height : -height) * 66 / 100 + 480;
-//
-// override_viewport_and_clip(&sEndCutsceneVp, 0, 0, 0, 0);
-// }
-//
-// if (m->actionTimer == TIMER_CREDITS_PROGRESS) {
-// reset_cutscene_msg_fade();
-// }
-//
-// if (m->actionTimer >= TIMER_CREDITS_PROGRESS) {
-// sDispCreditsEntry = gCurrCreditsEntry;
-// }
-//
-// if (m->actionTimer++ == TIMER_CREDITS_WARP) {
-// level_trigger_warp(m, WARP_OP_CREDITS_NEXT);
-// }
-//
-// m->marioObj->header.gfx.angle[1] += (gCurrCreditsEntry->unk02 & 0xC0) << 8;
-//
- return FALSE;
+static s32 act_credits_cutscene(struct MarioState *m)
+{
+ // s32 width;
+ // s32 height;
+ //
+ // m->statusForCamera->cameraEvent = CAM_EVENT_START_CREDITS;
+ // // checks if Mario is underwater (JRB, DDD, SA, etc.)
+ // if (m->pos[1] < m->waterLevel - 100) {
+ // if (m->area->camera->mode != CAMERA_MODE_BEHIND_MARIO) {
+ // set_camera_mode(m->area->camera, CAMERA_MODE_BEHIND_MARIO, 1);
+ // }
+ // set_mario_animation(m, MARIO_ANIM_WATER_IDLE);
+ // vec3f_copy(m->marioObj->header.gfx.pos, m->pos);
+ // // will copy over roll and pitch, if set
+ // vec3s_copy(m->marioObj->header.gfx.angle, m->faceAngle);
+ // m->particleFlags |= PARTICLE_BUBBLE;
+ // } else {
+ // set_mario_animation(m, MARIO_ANIM_FIRST_PERSON);
+ // if (m->actionTimer > 0) {
+ // stop_and_set_height_to_floor(m);
+ // }
+ // }
+ //
+ // if (m->actionTimer >= TIMER_CREDITS_SHOW) {
+ // if (m->actionState < 40) {
+ // m->actionState += 2;
+ // }
+ //
+ // width = m->actionState * 640 / 100;
+ // height = m->actionState * 480 / 100;
+ //
+ // sEndCutsceneVp.vp.vscale[0] = 640 - width;
+ // sEndCutsceneVp.vp.vscale[1] = 480 - height;
+ // sEndCutsceneVp.vp.vtrans[0] =
+ // (gCurrCreditsEntry->unk02 & 0x10 ? width : -width) * 56 / 100 + 640;
+ // sEndCutsceneVp.vp.vtrans[1] =
+ // (gCurrCreditsEntry->unk02 & 0x20 ? height : -height) * 66 / 100 + 480;
+ //
+ // override_viewport_and_clip(&sEndCutsceneVp, 0, 0, 0, 0);
+ // }
+ //
+ // if (m->actionTimer == TIMER_CREDITS_PROGRESS) {
+ // reset_cutscene_msg_fade();
+ // }
+ //
+ // if (m->actionTimer >= TIMER_CREDITS_PROGRESS) {
+ // sDispCreditsEntry = gCurrCreditsEntry;
+ // }
+ //
+ // if (m->actionTimer++ == TIMER_CREDITS_WARP) {
+ // level_trigger_warp(m, WARP_OP_CREDITS_NEXT);
+ // }
+ //
+ // m->marioObj->header.gfx.angle[1] += (gCurrCreditsEntry->unk02 & 0xC0) << 8;
+ //
+ return FALSE;
}
-static s32 act_end_waving_cutscene(struct MarioState *m) {
-// if (m->actionState == 0) {
-// m->statusForCamera->cameraEvent = CAM_EVENT_START_END_WAVING;
+static s32 act_end_waving_cutscene(struct MarioState *m)
+{
+ // if (m->actionState == 0) {
+ // m->statusForCamera->cameraEvent = CAM_EVENT_START_END_WAVING;
-// sEndPeachObj = spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_PEACH, bhvEndPeach, 60, 906,
-// -1180, 0, 0, 0);
+ // sEndPeachObj = spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_PEACH, bhvEndPeach, 60, 906,
+ // -1180, 0, 0, 0);
-// sEndRightToadObj = spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_TOAD, bhvEndToad, 180,
-// 906, -1170, 0, 0, 0);
+ // sEndRightToadObj = spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_TOAD, bhvEndToad, 180,
+ // 906, -1170, 0, 0, 0);
-// sEndLeftToadObj = spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_TOAD, bhvEndToad, -180,
-// 906, -1170, 0, 0, 0);
+ // sEndLeftToadObj = spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_TOAD, bhvEndToad, -180,
+ // 906, -1170, 0, 0, 0);
-// sEndPeachObj->oOpacity = 255;
-// sEndRightToadObj->oOpacity = 255;
-// sEndLeftToadObj->oOpacity = 255;
+ // sEndPeachObj->oOpacity = 255;
+ // sEndRightToadObj->oOpacity = 255;
+ // sEndLeftToadObj->oOpacity = 255;
-// sEndPeachAnimation = 11;
-// sEndToadAnims[0] = 6;
-// sEndToadAnims[1] = 7;
+ // sEndPeachAnimation = 11;
+ // sEndToadAnims[0] = 6;
+ // sEndToadAnims[1] = 7;
-// m->actionState = 1;
-// }
+ // m->actionState = 1;
+ // }
-// set_mario_animation(m, MARIO_ANIM_CREDITS_WAVING);
-// stop_and_set_height_to_floor(m);
+ // set_mario_animation(m, MARIO_ANIM_CREDITS_WAVING);
+ // stop_and_set_height_to_floor(m);
-// m->marioObj->header.gfx.angle[1] += 0x8000;
-// m->marioObj->header.gfx.pos[0] -= 60.0f;
-// m->marioBodyState->handState = MARIO_HAND_RIGHT_OPEN;
+ // m->marioObj->header.gfx.angle[1] += 0x8000;
+ // m->marioObj->header.gfx.pos[0] -= 60.0f;
+ // m->marioBodyState->handState = MARIO_HAND_RIGHT_OPEN;
-// if (m->actionTimer++ == 300) {
-// level_trigger_warp(m, WARP_OP_CREDITS_END);
-// }
+ // if (m->actionTimer++ == 300) {
+ // level_trigger_warp(m, WARP_OP_CREDITS_END);
+ // }
return FALSE;
}
-static s32 check_for_instant_quicksand(struct MarioState *m) {
+static s32 check_for_instant_quicksand(struct MarioState *m)
+{
if (m->floor->type == SURFACE_INSTANT_QUICKSAND && m->action & ACT_FLAG_INVULNERABLE
- && m->action != ACT_QUICKSAND_DEATH) {
+ && m->action != ACT_QUICKSAND_DEATH)
+ {
update_mario_sound_and_camera(m);
return drop_and_set_mario_action(m, ACT_QUICKSAND_DEATH, 0);
}
return FALSE;
}
-s32 mario_execute_cutscene_action(struct MarioState *m) {
+s32 mario_execute_cutscene_action(struct MarioState *m)
+{
s32 cancel;
- if (check_for_instant_quicksand(m)) {
+ if (check_for_instant_quicksand(m))
+ {
return TRUE;
}
@@ -2725,7 +3009,8 @@ s32 mario_execute_cutscene_action(struct MarioState *m) {
}
/* clang-format on */
- if (!cancel && (m->input & INPUT_IN_WATER)) {
+ if (!cancel && m->input & INPUT_IN_WATER)
+ {
m->particleFlags |= PARTICLE_IDLE_WATER_WAVE;
}
diff --git a/src/decomp/game/mario_actions_cutscene.h b/src/decomp/game/mario_actions_cutscene.h
index e84601a..d9cb92c 100644
--- a/src/decomp/game/mario_actions_cutscene.h
+++ b/src/decomp/game/mario_actions_cutscene.h
@@ -7,11 +7,17 @@
#include "../include/types.h"
void print_displaying_credits_entry(void);
+
void bhv_end_peach_loop(void);
+
void bhv_end_toad_loop(void);
+
s32 geo_switch_peach_eyes(s32 run, struct GraphNode *node, UNUSED s32 a2);
+
s32 mario_ready_to_speak(void);
+
s32 set_mario_npc_dialog(s32 actionArg);
+
s32 mario_execute_cutscene_action(struct MarioState *m);
#endif // MARIO_ACTIONS_CUTSCENE_H
diff --git a/src/decomp/game/mario_actions_moving.c b/src/decomp/game/mario_actions_moving.c
index 1f3e135..ec085e4 100644
--- a/src/decomp/game/mario_actions_moving.c
+++ b/src/decomp/game/mario_actions_moving.c
@@ -19,7 +19,8 @@
#include "../include/object_fields.h"
#include "../include/mario_geo_switch_case_ids.h"
-struct LandingAction {
+struct LandingAction
+{
s16 numFrames;
s16 unk02;
u32 verySteepAction;
@@ -65,43 +66,59 @@ struct LandingAction sBackflipLandAction = {
4, 0, ACT_FREEFALL, ACT_BACKFLIP_LAND_STOP, ACT_BACKFLIP, ACT_FREEFALL, ACT_BEGIN_SLIDING,
};
-s16 tilt_body_running(struct MarioState *m) {
+s16 tilt_body_running(struct MarioState *m)
+{
s16 pitch = find_floor_slope(m, 0);
pitch = pitch * m->forwardVel / 40.0f;
return -pitch;
}
-void play_step_sound(struct MarioState *m, s16 frame1, s16 frame2) {
- if (is_anim_past_frame(m, frame1) || is_anim_past_frame(m, frame2)) {
- if (m->flags & MARIO_METAL_CAP) {
- if (m->marioObj->header.gfx.animInfo.animID == MARIO_ANIM_TIPTOE) {
+void play_step_sound(struct MarioState *m, s16 frame1, s16 frame2)
+{
+ if (is_anim_past_frame(m, frame1) || is_anim_past_frame(m, frame2))
+ {
+ if (m->flags & MARIO_METAL_CAP)
+ {
+ if (m->marioObj->header.gfx.animInfo.animID == MARIO_ANIM_TIPTOE)
+ {
play_sound_and_spawn_particles(m, SOUND_ACTION_METAL_STEP_TIPTOE, 0);
- } else {
+ }
+ else
+ {
play_sound_and_spawn_particles(m, SOUND_ACTION_METAL_STEP, 0);
}
- } else if (m->quicksandDepth > 50.0f) {
+ }
+ else if (m->quicksandDepth > 50.0f)
+ {
play_sound(SOUND_ACTION_QUICKSAND_STEP, m->marioObj->header.gfx.cameraToObject);
- } else if (m->marioObj->header.gfx.animInfo.animID == MARIO_ANIM_TIPTOE) {
+ }
+ else if (m->marioObj->header.gfx.animInfo.animID == MARIO_ANIM_TIPTOE)
+ {
play_sound_and_spawn_particles(m, SOUND_ACTION_TERRAIN_STEP_TIPTOE, 0);
- } else {
+ }
+ else
+ {
play_sound_and_spawn_particles(m, SOUND_ACTION_TERRAIN_STEP, 0);
}
}
}
-void align_with_floor(struct MarioState *m) {
+void align_with_floor(struct MarioState *m)
+{
m->pos[1] = m->floorHeight;
mtxf_align_terrain_triangle(g_state->msFloorAlignMatrix, m->pos, m->faceAngle[1], 40.0f);
m->marioObj->header.gfx.throwMatrix = &g_state->msFloorAlignMatrix;
}
-s32 begin_walking_action(struct MarioState *m, f32 forwardVel, u32 action, u32 actionArg) {
+s32 begin_walking_action(struct MarioState *m, f32 forwardVel, u32 action, u32 actionArg)
+{
m->faceAngle[1] = m->intendedYaw;
mario_set_forward_vel(m, forwardVel);
return set_mario_action(m, action, actionArg);
}
-void check_ledge_climb_down(struct MarioState *m) {
+void check_ledge_climb_down(struct MarioState *m)
+{
struct SM64WallCollisionData wallCols;
struct SM64SurfaceCollisionData *floor;
f32 floorHeight;
@@ -109,21 +126,25 @@ void check_ledge_climb_down(struct MarioState *m) {
s16 wallAngle;
s16 wallDYaw;
- if (m->forwardVel < 10.0f) {
+ if (m->forwardVel < 10.0f)
+ {
wallCols.x = m->pos[0];
wallCols.y = m->pos[1];
wallCols.z = m->pos[2];
wallCols.radius = 10.0f;
wallCols.offsetY = -10.0f;
- if (find_wall_collisions(&wallCols) != 0) {
+ if (find_wall_collisions(&wallCols) != 0)
+ {
floorHeight = find_floor(wallCols.x, wallCols.y, wallCols.z, &floor);
- if (floor != NULL && (wallCols.y - floorHeight > 160.0f)) {
+ if (floor != NULL && wallCols.y - floorHeight > 160.0f)
+ {
wall = wallCols.walls[wallCols.numWalls - 1];
wallAngle = atan2s(wall->normal.z, wall->normal.x);
wallDYaw = wallAngle - m->faceAngle[1];
- if (wallDYaw > -0x4000 && wallDYaw < 0x4000) {
+ if (wallDYaw > -0x4000 && wallDYaw < 0x4000)
+ {
m->pos[0] = wallCols.x - 20.0f * wall->normal.x;
m->pos[2] = wallCols.z - 20.0f * wall->normal.z;
@@ -138,29 +159,40 @@ void check_ledge_climb_down(struct MarioState *m) {
}
}
-void slide_bonk(struct MarioState *m, u32 fastAction, u32 slowAction) {
- if (m->forwardVel > 16.0f) {
+void slide_bonk(struct MarioState *m, u32 fastAction, u32 slowAction)
+{
+ if (m->forwardVel > 16.0f)
+ {
mario_bonk_reflection(m, TRUE);
drop_and_set_mario_action(m, fastAction, 0);
- } else {
+ }
+ else
+ {
mario_set_forward_vel(m, 0.0f);
set_mario_action(m, slowAction, 0);
}
}
-s32 set_triple_jump_action(struct MarioState *m, UNUSED u32 action, UNUSED u32 actionArg) {
- if (m->flags & MARIO_WING_CAP) {
+s32 set_triple_jump_action(struct MarioState *m, UNUSED u32 action, UNUSED u32 actionArg)
+{
+ if (m->flags & MARIO_WING_CAP)
+ {
return set_mario_action(m, ACT_FLYING_TRIPLE_JUMP, 0);
- } else if (m->forwardVel > 20.0f) {
+ }
+ else if (m->forwardVel > 20.0f)
+ {
return set_mario_action(m, ACT_TRIPLE_JUMP, 0);
- } else {
+ }
+ else
+ {
return set_mario_action(m, ACT_JUMP, 0);
}
return FALSE;
}
-void update_sliding_angle(struct MarioState *m, f32 accel, f32 lossFactor) {
+void update_sliding_angle(struct MarioState *m, f32 accel, f32 lossFactor)
+{
s32 newFacingDYaw;
s16 facingDYaw;
@@ -181,20 +213,31 @@ void update_sliding_angle(struct MarioState *m, f32 accel, f32 lossFactor) {
newFacingDYaw = facingDYaw;
//! -0x4000 not handled - can slide down a slope while facing perpendicular to it
- if (newFacingDYaw > 0 && newFacingDYaw <= 0x4000) {
- if ((newFacingDYaw -= 0x200) < 0) {
+ if (newFacingDYaw > 0 && newFacingDYaw <= 0x4000)
+ {
+ if ((newFacingDYaw -= 0x200) < 0)
+ {
newFacingDYaw = 0;
}
- } else if (newFacingDYaw > -0x4000 && newFacingDYaw < 0) {
- if ((newFacingDYaw += 0x200) > 0) {
+ }
+ else if (newFacingDYaw > -0x4000 && newFacingDYaw < 0)
+ {
+ if ((newFacingDYaw += 0x200) > 0)
+ {
newFacingDYaw = 0;
}
- } else if (newFacingDYaw > 0x4000 && newFacingDYaw < 0x8000) {
- if ((newFacingDYaw += 0x200) > 0x8000) {
+ }
+ else if (newFacingDYaw > 0x4000 && newFacingDYaw < 0x8000)
+ {
+ if ((newFacingDYaw += 0x200) > 0x8000)
+ {
newFacingDYaw = 0x8000;
}
- } else if (newFacingDYaw > -0x8000 && newFacingDYaw < -0x4000) {
- if ((newFacingDYaw -= 0x200) < -0x8000) {
+ }
+ else if (newFacingDYaw > -0x8000 && newFacingDYaw < -0x4000)
+ {
+ if ((newFacingDYaw -= 0x200) < -0x8000)
+ {
newFacingDYaw = -0x8000;
}
}
@@ -210,17 +253,20 @@ void update_sliding_angle(struct MarioState *m, f32 accel, f32 lossFactor) {
//! Speed is capped a frame late (butt slide HSG)
m->forwardVel = sqrtf(m->slideVelX * m->slideVelX + m->slideVelZ * m->slideVelZ);
- if (m->forwardVel > 100.0f) {
+ if (m->forwardVel > 100.0f)
+ {
m->slideVelX = m->slideVelX * 100.0f / m->forwardVel;
m->slideVelZ = m->slideVelZ * 100.0f / m->forwardVel;
}
- if (newFacingDYaw < -0x4000 || newFacingDYaw > 0x4000) {
+ if (newFacingDYaw < -0x4000 || newFacingDYaw > 0x4000)
+ {
m->forwardVel *= -1.0f;
}
}
-s32 update_sliding(struct MarioState *m, f32 stopSpeed) {
+s32 update_sliding(struct MarioState *m, f32 stopSpeed)
+{
f32 lossFactor;
f32 accel;
f32 oldSpeed;
@@ -233,11 +279,13 @@ s32 update_sliding(struct MarioState *m, f32 stopSpeed) {
f32 sideward = sins(intendedDYaw);
//! 10k glitch
- if (forward < 0.0f && m->forwardVel >= 0.0f) {
+ if (forward < 0.0f && m->forwardVel >= 0.0f)
+ {
forward *= 0.5f + 0.5f * m->forwardVel / 100.0f;
}
- switch (mario_get_floor_class(m)) {
+ switch (mario_get_floor_class(m))
+ {
case SURFACE_CLASS_VERY_SLIPPERY:
accel = 10.0f;
lossFactor = m->intendedMag / 32.0f * forward * 0.02f + 0.98f;
@@ -269,14 +317,16 @@ s32 update_sliding(struct MarioState *m, f32 stopSpeed) {
newSpeed = sqrtf(m->slideVelX * m->slideVelX + m->slideVelZ * m->slideVelZ);
- if (oldSpeed > 0.0f && newSpeed > 0.0f) {
+ if (oldSpeed > 0.0f && newSpeed > 0.0f)
+ {
m->slideVelX = m->slideVelX * oldSpeed / newSpeed;
m->slideVelZ = m->slideVelZ * oldSpeed / newSpeed;
}
update_sliding_angle(m, accel, lossFactor);
- if (!mario_floor_is_slope(m) && m->forwardVel * m->forwardVel < stopSpeed * stopSpeed) {
+ if (!mario_floor_is_slope(m) && m->forwardVel * m->forwardVel < stopSpeed * stopSpeed)
+ {
mario_set_forward_vel(m, 0.0f);
stopped = TRUE;
}
@@ -284,7 +334,8 @@ s32 update_sliding(struct MarioState *m, f32 stopSpeed) {
return stopped;
}
-void apply_slope_accel(struct MarioState *m) {
+void apply_slope_accel(struct MarioState *m)
+{
f32 slopeAccel;
struct SM64SurfaceCollisionData *floor = m->floor;
@@ -293,14 +344,17 @@ void apply_slope_accel(struct MarioState *m) {
UNUSED f32 normalY = floor->normal.y;
s16 floorDYaw = m->floorAngle - m->faceAngle[1];
- if (mario_floor_is_slope(m)) {
+ if (mario_floor_is_slope(m))
+ {
s16 slopeClass = 0;
- if (m->action != ACT_SOFT_BACKWARD_GROUND_KB && m->action != ACT_SOFT_FORWARD_GROUND_KB) {
+ if (m->action != ACT_SOFT_BACKWARD_GROUND_KB && m->action != ACT_SOFT_FORWARD_GROUND_KB)
+ {
slopeClass = mario_get_floor_class(m);
}
- switch (slopeClass) {
+ switch (slopeClass)
+ {
case SURFACE_CLASS_VERY_SLIPPERY:
slopeAccel = 5.3f;
break;
@@ -315,9 +369,12 @@ void apply_slope_accel(struct MarioState *m) {
break;
}
- if (floorDYaw > -0x4000 && floorDYaw < 0x4000) {
+ if (floorDYaw > -0x4000 && floorDYaw < 0x4000)
+ {
m->forwardVel += slopeAccel * steepness;
- } else {
+ }
+ else
+ {
m->forwardVel -= slopeAccel * steepness;
}
}
@@ -335,14 +392,17 @@ void apply_slope_accel(struct MarioState *m) {
mario_update_windy_ground(m);
}
-s32 apply_landing_accel(struct MarioState *m, f32 frictionFactor) {
+s32 apply_landing_accel(struct MarioState *m, f32 frictionFactor)
+{
s32 stopped = FALSE;
apply_slope_accel(m);
- if (!mario_floor_is_slope(m)) {
+ if (!mario_floor_is_slope(m))
+ {
m->forwardVel *= frictionFactor;
- if (m->forwardVel * m->forwardVel < 1.0f) {
+ if (m->forwardVel * m->forwardVel < 1.0f)
+ {
mario_set_forward_vel(m, 0.0f);
stopped = TRUE;
}
@@ -351,54 +411,69 @@ s32 apply_landing_accel(struct MarioState *m, f32 frictionFactor) {
return stopped;
}
-void update_shell_speed(struct MarioState *m) {
+void update_shell_speed(struct MarioState *m)
+{
f32 maxTargetSpeed;
f32 targetSpeed;
- if (m->floorHeight < m->waterLevel) {
+ if (m->floorHeight < m->waterLevel)
+ {
m->floorHeight = m->waterLevel;
m->floor = &gWaterSurfacePseudoFloor;
m->floor->originOffset = m->waterLevel; //! Negative origin offset
}
- if (m->floor != NULL && m->floor->type == SURFACE_SLOW) {
+ if (m->floor != NULL && m->floor->type == SURFACE_SLOW)
+ {
maxTargetSpeed = 48.0f;
- } else {
+ }
+ else
+ {
maxTargetSpeed = 64.0f;
}
targetSpeed = m->intendedMag * 2.0f;
- if (targetSpeed > maxTargetSpeed) {
+ if (targetSpeed > maxTargetSpeed)
+ {
targetSpeed = maxTargetSpeed;
}
- if (targetSpeed < 24.0f) {
+ if (targetSpeed < 24.0f)
+ {
targetSpeed = 24.0f;
}
- if (m->forwardVel <= 0.0f) {
+ if (m->forwardVel <= 0.0f)
+ {
m->forwardVel += 1.1f;
- } else if (m->forwardVel <= targetSpeed) {
+ }
+ else if (m->forwardVel <= targetSpeed)
+ {
m->forwardVel += 1.1f - m->forwardVel / 58.0f;
- } else if (m->floor->normal.y >= 0.95f) {
+ }
+ else if (m->floor->normal.y >= 0.95f)
+ {
m->forwardVel -= 1.0f;
}
//! No backward speed cap (shell hyperspeed)
- if (m->forwardVel > 64.0f) {
+ if (m->forwardVel > 64.0f)
+ {
m->forwardVel = 64.0f;
}
m->faceAngle[1] =
- m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x800, 0x800);
+ m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x800, 0x800);
apply_slope_accel(m);
}
-s32 apply_slope_decel(struct MarioState *m, f32 decelCoef) {
+s32 apply_slope_decel(struct MarioState *m, f32 decelCoef)
+{
f32 decel;
s32 stopped = FALSE;
- switch (mario_get_floor_class(m)) {
+ switch (mario_get_floor_class(m))
+ {
case SURFACE_CLASS_VERY_SLIPPERY:
decel = decelCoef * 0.2f;
break;
@@ -413,7 +488,8 @@ s32 apply_slope_decel(struct MarioState *m, f32 decelCoef) {
break;
}
- if ((m->forwardVel = approach_f32(m->forwardVel, 0.0f, decel, decel)) == 0.0f) {
+ if ((m->forwardVel = approach_f32(m->forwardVel, 0.0f, decel, decel)) == 0.0f)
+ {
stopped = TRUE;
}
@@ -421,10 +497,12 @@ s32 apply_slope_decel(struct MarioState *m, f32 decelCoef) {
return stopped;
}
-s32 update_decelerating_speed(struct MarioState *m) {
+s32 update_decelerating_speed(struct MarioState *m)
+{
s32 stopped = FALSE;
- if ((m->forwardVel = approach_f32(m->forwardVel, 0.0f, 1.0f, 1.0f)) == 0.0f) {
+ if ((m->forwardVel = approach_f32(m->forwardVel, 0.0f, 1.0f, 1.0f)) == 0.0f)
+ {
stopped = TRUE;
}
@@ -435,45 +513,59 @@ s32 update_decelerating_speed(struct MarioState *m) {
return stopped;
}
-void update_walking_speed(struct MarioState *m) {
+void update_walking_speed(struct MarioState *m)
+{
f32 maxTargetSpeed;
f32 targetSpeed;
- if (m->floor != NULL && m->floor->type == SURFACE_SLOW) {
+ if (m->floor != NULL && m->floor->type == SURFACE_SLOW)
+ {
maxTargetSpeed = 24.0f;
- } else {
+ }
+ else
+ {
maxTargetSpeed = 32.0f;
}
targetSpeed = m->intendedMag < maxTargetSpeed ? m->intendedMag : maxTargetSpeed;
- if (m->quicksandDepth > 10.0f) {
+ if (m->quicksandDepth > 10.0f)
+ {
targetSpeed *= 6.25 / m->quicksandDepth;
}
- if (m->forwardVel <= 0.0f) {
+ if (m->forwardVel <= 0.0f)
+ {
m->forwardVel += 1.1f;
- } else if (m->forwardVel <= targetSpeed) {
+ }
+ else if (m->forwardVel <= targetSpeed)
+ {
m->forwardVel += 1.1f - m->forwardVel / 43.0f;
- } else if (m->floor->normal.y >= 0.95f) {
+ }
+ else if (m->floor->normal.y >= 0.95f)
+ {
m->forwardVel -= 1.0f;
}
- if (m->forwardVel > 48.0f) {
+ if (m->forwardVel > 48.0f)
+ {
m->forwardVel = 48.0f;
}
m->faceAngle[1] =
- m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x800, 0x800);
+ m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x800, 0x800);
apply_slope_accel(m);
}
-s32 should_begin_sliding(struct MarioState *m) {
- if (m->input & INPUT_ABOVE_SLIDE) {
+s32 should_begin_sliding(struct MarioState *m)
+{
+ if (m->input & INPUT_ABOVE_SLIDE)
+ {
s32 slideLevel = m->curTerrain == TERRAIN_SLIDE;
s32 movingBackward = m->forwardVel <= -1.0f;
- if (slideLevel || movingBackward || mario_facing_downhill(m, FALSE)) {
+ if (slideLevel || movingBackward || mario_facing_downhill(m, FALSE))
+ {
return TRUE;
}
}
@@ -481,17 +573,21 @@ s32 should_begin_sliding(struct MarioState *m) {
return FALSE;
}
-s32 analog_stick_held_back(struct MarioState *m) {
+s32 analog_stick_held_back(struct MarioState *m)
+{
s16 intendedDYaw = m->intendedYaw - m->faceAngle[1];
return intendedDYaw < -0x471C || intendedDYaw > 0x471C;
}
-s32 check_ground_dive_or_punch(struct MarioState *m) {
+s32 check_ground_dive_or_punch(struct MarioState *m)
+{
UNUSED s32 unused;
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
//! Speed kick (shoutouts to SimpleFlips)
- if (m->forwardVel >= 29.0f && m->controller->stickMag > 48.0f) {
+ if (m->forwardVel >= 29.0f && m->controller->stickMag > 48.0f)
+ {
m->vel[1] = 20.0f;
return set_mario_action(m, ACT_DIVE, 1);
}
@@ -502,22 +598,26 @@ s32 check_ground_dive_or_punch(struct MarioState *m) {
return FALSE;
}
-s32 begin_braking_action(struct MarioState *m) {
+s32 begin_braking_action(struct MarioState *m)
+{
mario_drop_held_object(m);
- if (m->actionState == 1) {
+ if (m->actionState == 1)
+ {
m->faceAngle[1] = m->actionArg;
return set_mario_action(m, ACT_STANDING_AGAINST_WALL, 0);
}
- if (m->forwardVel >= 16.0f && m->floor->normal.y >= 0.17364818f) {
+ if (m->forwardVel >= 16.0f && m->floor->normal.y >= 0.17364818f)
+ {
return set_mario_action(m, ACT_BRAKING, 0);
}
return set_mario_action(m, ACT_DECELERATING, 0);
}
-void anim_and_audio_for_walk(struct MarioState *m) {
+void anim_and_audio_for_walk(struct MarioState *m)
+{
s32 val14;
struct Object *marioObj = m->marioObj;
s32 val0C = TRUE;
@@ -526,29 +626,40 @@ void anim_and_audio_for_walk(struct MarioState *m) {
val04 = m->intendedMag > m->forwardVel ? m->intendedMag : m->forwardVel;
- if (val04 < 4.0f) {
+ if (val04 < 4.0f)
+ {
val04 = 4.0f;
}
- if (m->quicksandDepth > 50.0f) {
+ if (m->quicksandDepth > 50.0f)
+ {
val14 = (s32)(val04 / 4.0f * 0x10000);
set_mario_anim_with_accel(m, MARIO_ANIM_MOVE_IN_QUICKSAND, val14);
play_step_sound(m, 19, 93);
m->actionTimer = 0;
- } else {
- while (val0C) {
- switch (m->actionTimer) {
+ }
+ else
+ {
+ while (val0C)
+ {
+ switch (m->actionTimer)
+ {
case 0:
- if (val04 > 8.0f) {
+ if (val04 > 8.0f)
+ {
m->actionTimer = 2;
- } else {
+ }
+ else
+ {
//! (Speed Crash) If Mario's speed is more than 2^17.
- if ((val14 = (s32)(val04 / 4.0f * 0x10000)) < 0x1000) {
+ if ((val14 = (s32)(val04 / 4.0f * 0x10000)) < 0x1000)
+ {
val14 = 0x1000;
}
set_mario_anim_with_accel(m, MARIO_ANIM_START_TIPTOE, val14);
play_step_sound(m, 7, 22);
- if (is_anim_past_frame(m, 23)) {
+ if (is_anim_past_frame(m, 23))
+ {
m->actionTimer = 2;
}
@@ -557,11 +668,15 @@ void anim_and_audio_for_walk(struct MarioState *m) {
break;
case 1:
- if (val04 > 8.0f) {
+ if (val04 > 8.0f)
+ {
m->actionTimer = 2;
- } else {
+ }
+ else
+ {
//! (Speed Crash) If Mario's speed is more than 2^17.
- if ((val14 = (s32)(val04 * 0x10000)) < 0x1000) {
+ if ((val14 = (s32)(val04 * 0x10000)) < 0x1000)
+ {
val14 = 0x1000;
}
set_mario_anim_with_accel(m, MARIO_ANIM_TIPTOE, val14);
@@ -572,11 +687,16 @@ void anim_and_audio_for_walk(struct MarioState *m) {
break;
case 2:
- if (val04 < 5.0f) {
+ if (val04 < 5.0f)
+ {
m->actionTimer = 1;
- } else if (val04 > 22.0f) {
+ }
+ else if (val04 > 22.0f)
+ {
m->actionTimer = 3;
- } else {
+ }
+ else
+ {
//! (Speed Crash) If Mario's speed is more than 2^17.
val14 = (s32)(val04 / 4.0f * 0x10000);
set_mario_anim_with_accel(m, MARIO_ANIM_WALKING, val14);
@@ -587,9 +707,12 @@ void anim_and_audio_for_walk(struct MarioState *m) {
break;
case 3:
- if (val04 < 18.0f) {
+ if (val04 < 18.0f)
+ {
m->actionTimer = 2;
- } else {
+ }
+ else
+ {
//! (Speed Crash) If Mario's speed is more than 2^17.
val14 = (s32)(val04 / 4.0f * 0x10000);
set_mario_anim_with_accel(m, MARIO_ANIM_RUNNING, val14);
@@ -604,27 +727,34 @@ void anim_and_audio_for_walk(struct MarioState *m) {
}
marioObj->oMarioWalkingPitch =
- (s16) approach_s32(marioObj->oMarioWalkingPitch, targetPitch, 0x800, 0x800);
+ (s16)approach_s32(marioObj->oMarioWalkingPitch, targetPitch, 0x800, 0x800);
marioObj->header.gfx.angle[0] = marioObj->oMarioWalkingPitch;
}
-void anim_and_audio_for_hold_walk(struct MarioState *m) {
+void anim_and_audio_for_hold_walk(struct MarioState *m)
+{
s32 val0C;
s32 val08 = TRUE;
f32 val04;
val04 = m->intendedMag > m->forwardVel ? m->intendedMag : m->forwardVel;
- if (val04 < 2.0f) {
+ if (val04 < 2.0f)
+ {
val04 = 2.0f;
}
- while (val08) {
- switch (m->actionTimer) {
+ while (val08)
+ {
+ switch (m->actionTimer)
+ {
case 0:
- if (val04 > 6.0f) {
+ if (val04 > 6.0f)
+ {
m->actionTimer = 1;
- } else {
+ }
+ else
+ {
//! (Speed Crash) Crashes if Mario's speed exceeds or equals 2^15.
val0C = (s32)(val04 * 0x10000);
set_mario_anim_with_accel(m, MARIO_ANIM_SLOW_WALK_WITH_LIGHT_OBJ, val0C);
@@ -635,11 +765,16 @@ void anim_and_audio_for_hold_walk(struct MarioState *m) {
break;
case 1:
- if (val04 < 3.0f) {
+ if (val04 < 3.0f)
+ {
m->actionTimer = 0;
- } else if (val04 > 11.0f) {
+ }
+ else if (val04 > 11.0f)
+ {
m->actionTimer = 2;
- } else {
+ }
+ else
+ {
//! (Speed Crash) Crashes if Mario's speed exceeds or equals 2^15.
val0C = (s32)(val04 * 0x10000);
set_mario_anim_with_accel(m, MARIO_ANIM_WALK_WITH_LIGHT_OBJ, val0C);
@@ -650,9 +785,12 @@ void anim_and_audio_for_hold_walk(struct MarioState *m) {
break;
case 2:
- if (val04 < 8.0f) {
+ if (val04 < 8.0f)
+ {
m->actionTimer = 1;
- } else {
+ }
+ else
+ {
//! (Speed Crash) Crashes if Mario's speed exceeds or equals 2^16.
val0C = (s32)(val04 / 2.0f * 0x10000);
set_mario_anim_with_accel(m, MARIO_ANIM_RUN_WITH_LIGHT_OBJ, val0C);
@@ -665,13 +803,15 @@ void anim_and_audio_for_hold_walk(struct MarioState *m) {
}
}
-void anim_and_audio_for_heavy_walk(struct MarioState *m) {
+void anim_and_audio_for_heavy_walk(struct MarioState *m)
+{
s32 val04 = (s32)(m->intendedMag * 0x10000);
set_mario_anim_with_accel(m, MARIO_ANIM_WALK_WITH_HEAVY_OBJ, val04);
play_step_sound(m, 26, 79);
}
-void push_or_sidle_wall(struct MarioState *m, Vec3f startPos) {
+void push_or_sidle_wall(struct MarioState *m, Vec3f startPos)
+{
s16 wallAngle;
s16 dWallAngle;
f32 dx = m->pos[0] - startPos[0];
@@ -680,27 +820,36 @@ void push_or_sidle_wall(struct MarioState *m, Vec3f startPos) {
//! (Speed Crash) If a wall is after moving 16384 distance, this crashes.
s32 val04 = (s32)(movedDistance * 2.0f * 0x10000);
- if (m->forwardVel > 6.0f) {
+ if (m->forwardVel > 6.0f)
+ {
mario_set_forward_vel(m, 6.0f);
}
- if (m->wall != NULL) {
+ if (m->wall != NULL)
+ {
wallAngle = atan2s(m->wall->normal.z, m->wall->normal.x);
dWallAngle = wallAngle - m->faceAngle[1];
}
- if (m->wall == NULL || dWallAngle <= -0x71C8 || dWallAngle >= 0x71C8) {
+ if (m->wall == NULL || dWallAngle <= -0x71C8 || dWallAngle >= 0x71C8)
+ {
m->flags |= MARIO_UNKNOWN_31;
set_mario_animation(m, MARIO_ANIM_PUSHING);
play_step_sound(m, 6, 18);
- } else {
- if (dWallAngle < 0) {
+ }
+ else
+ {
+ if (dWallAngle < 0)
+ {
set_mario_anim_with_accel(m, MARIO_ANIM_SIDESTEP_RIGHT, val04);
- } else {
+ }
+ else
+ {
set_mario_anim_with_accel(m, MARIO_ANIM_SIDESTEP_LEFT, val04);
}
- if (m->marioObj->header.gfx.animInfo.animFrame < 20) {
+ if (m->marioObj->header.gfx.animInfo.animFrame < 20)
+ {
play_sound(SOUND_MOVING_TERRAIN_SLIDE + m->terrainSoundAddend, m->marioObj->header.gfx.cameraToObject);
m->particleFlags |= PARTICLE_DUST;
}
@@ -712,45 +861,54 @@ void push_or_sidle_wall(struct MarioState *m, Vec3f startPos) {
}
}
-void tilt_body_walking(struct MarioState *m, s16 startYaw) {
+void tilt_body_walking(struct MarioState *m, s16 startYaw)
+{
struct MarioBodyState *val0C = m->marioBodyState;
- UNUSED struct Object *marioObj = m->marioObj;
+ UNUSED
+ struct Object *marioObj = m->marioObj;
s16 animID = m->marioObj->header.gfx.animInfo.animID;
s16 dYaw;
s16 val02;
s16 val00;
- if (animID == MARIO_ANIM_WALKING || animID == MARIO_ANIM_RUNNING) {
+ if (animID == MARIO_ANIM_WALKING || animID == MARIO_ANIM_RUNNING)
+ {
dYaw = m->faceAngle[1] - startYaw;
//! (Speed Crash) These casts can cause a crash if (dYaw * forwardVel / 12) or
//! (forwardVel * 170) exceed or equal 2^31.
val02 = -(s16)(dYaw * m->forwardVel / 12.0f);
val00 = (s16)(m->forwardVel * 170.0f);
- if (val02 > 0x1555) {
+ if (val02 > 0x1555)
+ {
val02 = 0x1555;
}
- if (val02 < -0x1555) {
+ if (val02 < -0x1555)
+ {
val02 = -0x1555;
}
- if (val00 > 0x1555) {
+ if (val00 > 0x1555)
+ {
val00 = 0x1555;
}
- if (val00 < 0) {
+ if (val00 < 0)
+ {
val00 = 0;
}
val0C->torsoAngle[2] = approach_s32(val0C->torsoAngle[2], val02, 0x400, 0x400);
- val0C->torsoAngle[0] = approach_s32(val0C->torsoAngle[0], val00, 0x400, 0x400);
- ;
- } else {
+ val0C->torsoAngle[0] = approach_s32(val0C->torsoAngle[0], val00, 0x400, 0x400);;
+ }
+ else
+ {
val0C->torsoAngle[2] = 0;
val0C->torsoAngle[0] = 0;
}
}
-void tilt_body_ground_shell(struct MarioState *m, s16 startYaw) {
+void tilt_body_ground_shell(struct MarioState *m, s16 startYaw)
+{
struct MarioBodyState *val0C = m->marioBodyState;
struct Object *marioObj = m->marioObj;
s16 dYaw = m->faceAngle[1] - startYaw;
@@ -760,17 +918,21 @@ void tilt_body_ground_shell(struct MarioState *m, s16 startYaw) {
s16 val04 = -(s16)(dYaw * m->forwardVel / 12.0f);
s16 val02 = (s16)(m->forwardVel * 170.0f);
- if (val04 > 0x1800) {
+ if (val04 > 0x1800)
+ {
val04 = 0x1800;
}
- if (val04 < -0x1800) {
+ if (val04 < -0x1800)
+ {
val04 = -0x1800;
}
- if (val02 > 0x1000) {
+ if (val02 > 0x1000)
+ {
val02 = 0x1000;
}
- if (val02 < 0) {
+ if (val02 < 0)
+ {
val02 = 0;
}
@@ -782,37 +944,45 @@ void tilt_body_ground_shell(struct MarioState *m, s16 startYaw) {
marioObj->header.gfx.pos[1] += 45.0f;
}
-s32 act_walking(struct MarioState *m) {
+s32 act_walking(struct MarioState *m)
+{
Vec3f startPos;
s16 startYaw = m->faceAngle[1];
mario_drop_held_object(m);
- if (should_begin_sliding(m)) {
+ if (should_begin_sliding(m))
+ {
return set_mario_action(m, ACT_BEGIN_SLIDING, 0);
}
- if (m->input & INPUT_FIRST_PERSON) {
+ if (m->input & INPUT_FIRST_PERSON)
+ {
return begin_braking_action(m);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_jump_from_landing(m);
}
- if (check_ground_dive_or_punch(m)) {
+ if (check_ground_dive_or_punch(m))
+ {
return TRUE;
}
- if (m->input & INPUT_UNKNOWN_5) {
+ if (m->input & INPUT_UNKNOWN_5)
+ {
return begin_braking_action(m);
}
- if (analog_stick_held_back(m) && m->forwardVel >= 16.0f) {
+ if (analog_stick_held_back(m) && m->forwardVel >= 16.0f)
+ {
return set_mario_action(m, ACT_TURNING_AROUND, 0);
}
- if (m->input & INPUT_Z_PRESSED) {
+ if (m->input & INPUT_Z_PRESSED)
+ {
return set_mario_action(m, ACT_CROUCH_SLIDE, 0);
}
@@ -821,7 +991,8 @@ s32 act_walking(struct MarioState *m) {
vec3f_copy(startPos, m->pos);
update_walking_speed(m);
- switch (perform_ground_step(m)) {
+ switch (perform_ground_step(m))
+ {
case GROUND_STEP_LEFT_GROUND:
set_mario_action(m, ACT_FREEFALL, 0);
set_mario_animation(m, MARIO_ANIM_GENERAL_FALL);
@@ -829,7 +1000,8 @@ s32 act_walking(struct MarioState *m) {
case GROUND_STEP_NONE:
anim_and_audio_for_walk(m);
- if (m->intendedMag - m->forwardVel > 16.0f) {
+ if (m->intendedMag - m->forwardVel > 16.0f)
+ {
m->particleFlags |= PARTICLE_DUST;
}
break;
@@ -845,12 +1017,15 @@ s32 act_walking(struct MarioState *m) {
return FALSE;
}
-s32 act_move_punching(struct MarioState *m) {
- if (should_begin_sliding(m)) {
+s32 act_move_punching(struct MarioState *m)
+{
+ if (should_begin_sliding(m))
+ {
return set_mario_action(m, ACT_BEGIN_SLIDING, 0);
}
- if (m->actionState == 0 && (m->input & INPUT_A_DOWN)) {
+ if (m->actionState == 0 && m->input & INPUT_A_DOWN)
+ {
return set_mario_action(m, ACT_JUMP_KICK, 0);
}
@@ -858,16 +1033,21 @@ s32 act_move_punching(struct MarioState *m) {
mario_update_punch_sequence(m);
- if (m->forwardVel >= 0.0f) {
+ if (m->forwardVel >= 0.0f)
+ {
apply_slope_decel(m, 0.5f);
- } else {
- if ((m->forwardVel += 8.0f) >= 0.0f) {
+ }
+ else
+ {
+ if ((m->forwardVel += 8.0f) >= 0.0f)
+ {
m->forwardVel = 0.0f;
}
apply_slope_accel(m);
}
- switch (perform_ground_step(m)) {
+ switch (perform_ground_step(m))
+ {
case GROUND_STEP_LEFT_GROUND:
set_mario_action(m, ACT_FREEFALL, 0);
break;
@@ -880,32 +1060,39 @@ s32 act_move_punching(struct MarioState *m) {
return FALSE;
}
-s32 act_hold_walking(struct MarioState *m) {
-// if (m->heldObj->behavior == segmented_to_virtual(bhvJumpingBox)) {
-// return set_mario_action(m, ACT_CRAZY_BOX_BOUNCE, 0);
-// }
+s32 act_hold_walking(struct MarioState *m)
+{
+ // if (m->heldObj->behavior == segmented_to_virtual(bhvJumpingBox)) {
+ // return set_mario_action(m, ACT_CRAZY_BOX_BOUNCE, 0);
+ // }
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_WALKING, 0);
}
- if (should_begin_sliding(m)) {
+ if (should_begin_sliding(m))
+ {
return set_mario_action(m, ACT_HOLD_BEGIN_SLIDING, 0);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_THROWING, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_jumping_action(m, ACT_HOLD_JUMP, 0);
}
- if (m->input & INPUT_UNKNOWN_5) {
+ if (m->input & INPUT_UNKNOWN_5)
+ {
return set_mario_action(m, ACT_HOLD_DECELERATING, 0);
}
- if (m->input & INPUT_Z_PRESSED) {
+ if (m->input & INPUT_Z_PRESSED)
+ {
return drop_and_set_mario_action(m, ACT_CROUCH_SLIDE, 0);
}
@@ -913,13 +1100,15 @@ s32 act_hold_walking(struct MarioState *m) {
update_walking_speed(m);
- switch (perform_ground_step(m)) {
+ switch (perform_ground_step(m))
+ {
case GROUND_STEP_LEFT_GROUND:
set_mario_action(m, ACT_HOLD_FREEFALL, 0);
break;
case GROUND_STEP_HIT_WALL:
- if (m->forwardVel > 16.0f) {
+ if (m->forwardVel > 16.0f)
+ {
mario_set_forward_vel(m, 16.0f);
}
break;
@@ -927,23 +1116,28 @@ s32 act_hold_walking(struct MarioState *m) {
anim_and_audio_for_hold_walk(m);
- if (0.4f * m->intendedMag - m->forwardVel > 10.0f) {
+ if (0.4f * m->intendedMag - m->forwardVel > 10.0f)
+ {
m->particleFlags |= PARTICLE_DUST;
}
return FALSE;
}
-s32 act_hold_heavy_walking(struct MarioState *m) {
- if (m->input & INPUT_B_PRESSED) {
+s32 act_hold_heavy_walking(struct MarioState *m)
+{
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_HEAVY_THROW, 0);
}
- if (should_begin_sliding(m)) {
+ if (should_begin_sliding(m))
+ {
return drop_and_set_mario_action(m, ACT_BEGIN_SLIDING, 0);
}
- if (m->input & INPUT_UNKNOWN_5) {
+ if (m->input & INPUT_UNKNOWN_5)
+ {
return set_mario_action(m, ACT_HOLD_HEAVY_IDLE, 0);
}
@@ -951,13 +1145,15 @@ s32 act_hold_heavy_walking(struct MarioState *m) {
update_walking_speed(m);
- switch (perform_ground_step(m)) {
+ switch (perform_ground_step(m))
+ {
case GROUND_STEP_LEFT_GROUND:
drop_and_set_mario_action(m, ACT_FREEFALL, 0);
break;
case GROUND_STEP_HIT_WALL:
- if (m->forwardVel > 10.0f) {
+ if (m->forwardVel > 10.0f)
+ {
mario_set_forward_vel(m, 10.0f);
}
break;
@@ -967,24 +1163,30 @@ s32 act_hold_heavy_walking(struct MarioState *m) {
return FALSE;
}
-s32 act_turning_around(struct MarioState *m) {
- if (m->input & INPUT_ABOVE_SLIDE) {
+s32 act_turning_around(struct MarioState *m)
+{
+ if (m->input & INPUT_ABOVE_SLIDE)
+ {
return set_mario_action(m, ACT_BEGIN_SLIDING, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_jumping_action(m, ACT_SIDE_FLIP, 0);
}
- if (m->input & INPUT_UNKNOWN_5) {
+ if (m->input & INPUT_UNKNOWN_5)
+ {
return set_mario_action(m, ACT_BRAKING, 0);
}
- if (!analog_stick_held_back(m)) {
+ if (!analog_stick_held_back(m))
+ {
return set_mario_action(m, ACT_WALKING, 0);
}
- if (apply_slope_decel(m, 2.0f)) {
+ if (apply_slope_decel(m, 2.0f))
+ {
return begin_walking_action(m, 8.0f, ACT_FINISH_TURNING_AROUND, 0);
}
@@ -992,7 +1194,8 @@ s32 act_turning_around(struct MarioState *m) {
adjust_sound_for_speed(m);
- switch (perform_ground_step(m)) {
+ switch (perform_ground_step(m))
+ {
case GROUND_STEP_LEFT_GROUND:
set_mario_action(m, ACT_FREEFALL, 0);
break;
@@ -1002,14 +1205,21 @@ s32 act_turning_around(struct MarioState *m) {
break;
}
- if (m->forwardVel >= 18.0f) {
+ if (m->forwardVel >= 18.0f)
+ {
set_mario_animation(m, MARIO_ANIM_TURNING_PART1);
- } else {
+ }
+ else
+ {
set_mario_animation(m, MARIO_ANIM_TURNING_PART2);
- if (is_anim_at_end(m)) {
- if (m->forwardVel > 0.0f) {
+ if (is_anim_at_end(m))
+ {
+ if (m->forwardVel > 0.0f)
+ {
begin_walking_action(m, -m->forwardVel, ACT_WALKING, 0);
- } else {
+ }
+ else
+ {
begin_walking_action(m, 8.0f, ACT_WALKING, 0);
}
}
@@ -1018,23 +1228,28 @@ s32 act_turning_around(struct MarioState *m) {
return FALSE;
}
-s32 act_finish_turning_around(struct MarioState *m) {
- if (m->input & INPUT_ABOVE_SLIDE) {
+s32 act_finish_turning_around(struct MarioState *m)
+{
+ if (m->input & INPUT_ABOVE_SLIDE)
+ {
return set_mario_action(m, ACT_BEGIN_SLIDING, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_jumping_action(m, ACT_SIDE_FLIP, 0);
}
update_walking_speed(m);
set_mario_animation(m, MARIO_ANIM_TURNING_PART2);
- if (perform_ground_step(m) == GROUND_STEP_LEFT_GROUND) {
+ if (perform_ground_step(m) == GROUND_STEP_LEFT_GROUND)
+ {
set_mario_action(m, ACT_FREEFALL, 0);
}
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_action(m, ACT_WALKING, 0);
}
@@ -1042,22 +1257,27 @@ s32 act_finish_turning_around(struct MarioState *m) {
return FALSE;
}
-s32 act_braking(struct MarioState *m) {
+s32 act_braking(struct MarioState *m)
+{
if (!(m->input & INPUT_FIRST_PERSON)
- && (m->input
- & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE))) {
+ && m->input
+ & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE))
+ {
return check_common_action_exits(m);
}
- if (apply_slope_decel(m, 2.0f)) {
+ if (apply_slope_decel(m, 2.0f))
+ {
return set_mario_action(m, ACT_BRAKING_STOP, 0);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_MOVE_PUNCHING, 0);
}
- switch (perform_ground_step(m)) {
+ switch (perform_ground_step(m))
+ {
case GROUND_STEP_LEFT_GROUND:
set_mario_action(m, ACT_FREEFALL, 0);
break;
@@ -1077,58 +1297,74 @@ s32 act_braking(struct MarioState *m) {
return FALSE;
}
-s32 act_decelerating(struct MarioState *m) {
+s32 act_decelerating(struct MarioState *m)
+{
s32 val0C;
s16 slopeClass = mario_get_floor_class(m);
- if (!(m->input & INPUT_FIRST_PERSON)) {
- if (should_begin_sliding(m)) {
+ if (!(m->input & INPUT_FIRST_PERSON))
+ {
+ if (should_begin_sliding(m))
+ {
return set_mario_action(m, ACT_BEGIN_SLIDING, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_jump_from_landing(m);
}
- if (check_ground_dive_or_punch(m)) {
+ if (check_ground_dive_or_punch(m))
+ {
return TRUE;
}
- if (m->input & INPUT_NONZERO_ANALOG) {
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
return set_mario_action(m, ACT_WALKING, 0);
}
- if (m->input & INPUT_Z_PRESSED) {
+ if (m->input & INPUT_Z_PRESSED)
+ {
return set_mario_action(m, ACT_CROUCH_SLIDE, 0);
}
}
- if (update_decelerating_speed(m)) {
+ if (update_decelerating_speed(m))
+ {
return set_mario_action(m, ACT_IDLE, 0);
}
- switch (perform_ground_step(m)) {
+ switch (perform_ground_step(m))
+ {
case GROUND_STEP_LEFT_GROUND:
set_mario_action(m, ACT_FREEFALL, 0);
break;
case GROUND_STEP_HIT_WALL:
- if (slopeClass == SURFACE_CLASS_VERY_SLIPPERY) {
+ if (slopeClass == SURFACE_CLASS_VERY_SLIPPERY)
+ {
mario_bonk_reflection(m, TRUE);
- } else {
+ }
+ else
+ {
mario_set_forward_vel(m, 0.0f);
}
break;
}
- if (slopeClass == SURFACE_CLASS_VERY_SLIPPERY) {
+ if (slopeClass == SURFACE_CLASS_VERY_SLIPPERY)
+ {
set_mario_animation(m, MARIO_ANIM_IDLE_HEAD_LEFT);
play_sound(SOUND_MOVING_TERRAIN_SLIDE + m->terrainSoundAddend, m->marioObj->header.gfx.cameraToObject);
adjust_sound_for_speed(m);
m->particleFlags |= PARTICLE_DUST;
- } else {
+ }
+ else
+ {
// (Speed Crash) Crashes if speed exceeds 2^17.
- if ((val0C = (s32)(m->forwardVel / 4.0f * 0x10000)) < 0x1000) {
+ if ((val0C = (s32)(m->forwardVel / 4.0f * 0x10000)) < 0x1000)
+ {
val0C = 0x1000;
}
@@ -1139,62 +1375,78 @@ s32 act_decelerating(struct MarioState *m) {
return FALSE;
}
-s32 act_hold_decelerating(struct MarioState *m) {
+s32 act_hold_decelerating(struct MarioState *m)
+{
s32 val0C;
s16 slopeClass = mario_get_floor_class(m);
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_WALKING, 0);
}
- if (should_begin_sliding(m)) {
+ if (should_begin_sliding(m))
+ {
return set_mario_action(m, ACT_HOLD_BEGIN_SLIDING, 0);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_THROWING, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_jumping_action(m, ACT_HOLD_JUMP, 0);
}
- if (m->input & INPUT_Z_PRESSED) {
+ if (m->input & INPUT_Z_PRESSED)
+ {
return drop_and_set_mario_action(m, ACT_CROUCH_SLIDE, 0);
}
- if (m->input & INPUT_NONZERO_ANALOG) {
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
return set_mario_action(m, ACT_HOLD_WALKING, 0);
}
- if (update_decelerating_speed(m)) {
+ if (update_decelerating_speed(m))
+ {
return set_mario_action(m, ACT_HOLD_IDLE, 0);
}
m->intendedMag *= 0.4f;
- switch (perform_ground_step(m)) {
+ switch (perform_ground_step(m))
+ {
case GROUND_STEP_LEFT_GROUND:
set_mario_action(m, ACT_HOLD_FREEFALL, 0);
break;
case GROUND_STEP_HIT_WALL:
- if (slopeClass == SURFACE_CLASS_VERY_SLIPPERY) {
+ if (slopeClass == SURFACE_CLASS_VERY_SLIPPERY)
+ {
mario_bonk_reflection(m, TRUE);
- } else {
+ }
+ else
+ {
mario_set_forward_vel(m, 0.0f);
}
break;
}
- if (slopeClass == SURFACE_CLASS_VERY_SLIPPERY) {
+ if (slopeClass == SURFACE_CLASS_VERY_SLIPPERY)
+ {
set_mario_animation(m, MARIO_ANIM_IDLE_WITH_LIGHT_OBJ);
play_sound(SOUND_MOVING_TERRAIN_SLIDE + m->terrainSoundAddend, m->marioObj->header.gfx.cameraToObject);
adjust_sound_for_speed(m);
m->particleFlags |= PARTICLE_DUST;
- } else {
+ }
+ else
+ {
//! (Speed Crash) This crashes if Mario has more speed than 2^15 speed.
- if ((val0C = (s32)(m->forwardVel * 0x10000)) < 0x1000) {
+ if ((val0C = (s32)(m->forwardVel * 0x10000)) < 0x1000)
+ {
val0C = 0x1000;
}
@@ -1205,16 +1457,20 @@ s32 act_hold_decelerating(struct MarioState *m) {
return FALSE;
}
-s32 act_riding_shell_ground(struct MarioState *m) {
+s32 act_riding_shell_ground(struct MarioState *m)
+{
s16 startYaw = m->faceAngle[1];
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_mario_action(m, ACT_RIDING_SHELL_JUMP, 0);
}
- if (m->input & INPUT_Z_PRESSED) {
+ if (m->input & INPUT_Z_PRESSED)
+ {
mario_stop_riding_object(m);
- if (m->forwardVel < 24.0f) {
+ if (m->forwardVel < 24.0f)
+ {
mario_set_forward_vel(m, 24.0f);
}
return set_mario_action(m, ACT_CROUCH_SLIDE, 0);
@@ -1223,7 +1479,8 @@ s32 act_riding_shell_ground(struct MarioState *m) {
update_shell_speed(m);
set_mario_animation(m, m->actionArg == 0 ? MARIO_ANIM_START_RIDING_SHELL : MARIO_ANIM_RIDING_SHELL);
- switch (perform_ground_step(m)) {
+ switch (perform_ground_step(m))
+ {
case GROUND_STEP_LEFT_GROUND:
set_mario_action(m, ACT_RIDING_SHELL_FALL, 0);
break;
@@ -1238,44 +1495,54 @@ s32 act_riding_shell_ground(struct MarioState *m) {
}
tilt_body_ground_shell(m, startYaw);
- if (m->floor->type == SURFACE_BURNING) {
+ if (m->floor->type == SURFACE_BURNING)
+ {
play_sound(SOUND_MOVING_RIDING_SHELL_LAVA, m->marioObj->header.gfx.cameraToObject);
- } else {
+ }
+ else
+ {
play_sound(SOUND_MOVING_TERRAIN_RIDING_SHELL + m->terrainSoundAddend,
m->marioObj->header.gfx.cameraToObject);
}
adjust_sound_for_speed(m);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
reset_rumble_timers();
-#endif
+ #endif
return FALSE;
}
-s32 act_crawling(struct MarioState *m) {
+s32 act_crawling(struct MarioState *m)
+{
s32 val04;
- if (should_begin_sliding(m)) {
+ if (should_begin_sliding(m))
+ {
return set_mario_action(m, ACT_BEGIN_SLIDING, 0);
}
- if (m->input & INPUT_FIRST_PERSON) {
+ if (m->input & INPUT_FIRST_PERSON)
+ {
return set_mario_action(m, ACT_STOP_CRAWLING, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_jumping_action(m, ACT_JUMP, 0);
}
- if (check_ground_dive_or_punch(m)) {
+ if (check_ground_dive_or_punch(m))
+ {
return TRUE;
}
- if (m->input & INPUT_UNKNOWN_5) {
+ if (m->input & INPUT_UNKNOWN_5)
+ {
return set_mario_action(m, ACT_STOP_CRAWLING, 0);
}
- if (!(m->input & INPUT_Z_DOWN)) {
+ if (!(m->input & INPUT_Z_DOWN))
+ {
return set_mario_action(m, ACT_STOP_CRAWLING, 0);
}
@@ -1283,16 +1550,18 @@ s32 act_crawling(struct MarioState *m) {
update_walking_speed(m);
- switch (perform_ground_step(m)) {
+ switch (perform_ground_step(m))
+ {
case GROUND_STEP_LEFT_GROUND:
set_mario_action(m, ACT_FREEFALL, 0);
break;
case GROUND_STEP_HIT_WALL:
- if (m->forwardVel > 10.0f) {
+ if (m->forwardVel > 10.0f)
+ {
mario_set_forward_vel(m, 10.0f);
}
- //! Possibly unintended missing break
+ //! Possibly unintended missing break
case GROUND_STEP_NONE:
align_with_floor(m);
@@ -1305,38 +1574,46 @@ s32 act_crawling(struct MarioState *m) {
return FALSE;
}
-s32 act_burning_ground(struct MarioState *m) {
- if (m->input & INPUT_A_PRESSED) {
+s32 act_burning_ground(struct MarioState *m)
+{
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_mario_action(m, ACT_BURNING_JUMP, 0);
}
m->marioObj->oMarioBurnTimer += 2;
- if (m->marioObj->oMarioBurnTimer > 160) {
+ if (m->marioObj->oMarioBurnTimer > 160)
+ {
return set_mario_action(m, ACT_WALKING, 0);
}
- if (m->waterLevel - m->floorHeight > 50.0f) {
+ if (m->waterLevel - m->floorHeight > 50.0f)
+ {
play_sound(SOUND_GENERAL_FLAME_OUT, m->marioObj->header.gfx.cameraToObject);
return set_mario_action(m, ACT_WALKING, 0);
}
- if (m->forwardVel < 8.0f) {
+ if (m->forwardVel < 8.0f)
+ {
m->forwardVel = 8.0f;
}
- if (m->forwardVel > 48.0f) {
+ if (m->forwardVel > 48.0f)
+ {
m->forwardVel = 48.0f;
}
m->forwardVel = approach_f32(m->forwardVel, 32.0f, 4.0f, 1.0f);
- if (m->input & INPUT_NONZERO_ANALOG) {
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
m->faceAngle[1] =
- m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x600, 0x600);
+ m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x600, 0x600);
}
apply_slope_accel(m);
- if (perform_ground_step(m) == GROUND_STEP_LEFT_GROUND) {
+ if (perform_ground_step(m) == GROUND_STEP_LEFT_GROUND)
+ {
set_mario_action(m, ACT_BURNING_FALL, 0);
}
@@ -1347,39 +1624,44 @@ s32 act_burning_ground(struct MarioState *m) {
play_sound(SOUND_MOVING_LAVA_BURN, m->marioObj->header.gfx.cameraToObject);
m->health -= 10;
- if (m->health < 0x100) {
+ if (m->health < 0x100)
+ {
set_mario_action(m, ACT_STANDING_DEATH, 0);
}
m->marioBodyState->eyeState = MARIO_EYES_DEAD;
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
reset_rumble_timers();
-#endif
+ #endif
return FALSE;
}
-void tilt_body_butt_slide(struct MarioState *m) {
+void tilt_body_butt_slide(struct MarioState *m)
+{
s16 intendedDYaw = m->intendedYaw - m->faceAngle[1];
m->marioBodyState->torsoAngle[0] = (s32)(5461.3335f * m->intendedMag / 32.0f * coss(intendedDYaw));
- m->marioBodyState->torsoAngle[2] = (s32)(-(5461.3335f * m->intendedMag / 32.0f * sins(intendedDYaw)));
+ m->marioBodyState->torsoAngle[2] = (s32) - (5461.3335f * m->intendedMag / 32.0f * sins(intendedDYaw));
}
-void common_slide_action(struct MarioState *m, u32 endAction, u32 airAction, s32 animation) {
+void common_slide_action(struct MarioState *m, u32 endAction, u32 airAction, s32 animation)
+{
Vec3f pos;
vec3f_copy(pos, m->pos);
play_sound(SOUND_MOVING_TERRAIN_SLIDE + m->terrainSoundAddend, m->marioObj->header.gfx.cameraToObject);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
reset_rumble_timers();
-#endif
+ #endif
adjust_sound_for_speed(m);
- switch (perform_ground_step(m)) {
+ switch (perform_ground_step(m))
+ {
case GROUND_STEP_LEFT_GROUND:
set_mario_action(m, airAction, 0);
- if (m->forwardVel < -50.0f || 50.0f < m->forwardVel) {
+ if (m->forwardVel < -50.0f || 50.0f < m->forwardVel)
+ {
play_sound(SOUND_MARIO_HOOHOO, m->marioObj->header.gfx.cameraToObject);
}
break;
@@ -1391,20 +1673,25 @@ void common_slide_action(struct MarioState *m, u32 endAction, u32 airAction, s32
break;
case GROUND_STEP_HIT_WALL:
- if (!mario_floor_is_slippery(m)) {
-#ifdef VERSION_JP
+ if (!mario_floor_is_slippery(m))
+ {
+ #ifdef VERSION_JP
m->particleFlags |= PARTICLE_VERTICAL_STAR;
-#else
- if (m->forwardVel > 16.0f) {
+ #else
+ if (m->forwardVel > 16.0f)
+ {
m->particleFlags |= PARTICLE_VERTICAL_STAR;
}
-#endif
+ #endif
slide_bonk(m, ACT_GROUND_BONK, endAction);
- } else if (m->wall != NULL) {
+ }
+ else if (m->wall != NULL)
+ {
s16 wallAngle = atan2s(m->wall->normal.z, m->wall->normal.x);
f32 slideSpeed = sqrtf(m->slideVelX * m->slideVelX + m->slideVelZ * m->slideVelZ);
- if ((slideSpeed *= 0.9) < 4.0f) {
+ if ((slideSpeed *= 0.9) < 4.0f)
+ {
slideSpeed = 4.0f;
}
@@ -1419,17 +1706,24 @@ void common_slide_action(struct MarioState *m, u32 endAction, u32 airAction, s32
}
}
-s32 common_slide_action_with_jump(struct MarioState *m, u32 stopAction, u32 jumpAction, u32 airAction,
- s32 animation) {
- if (m->actionTimer == 5) {
- if (m->input & INPUT_A_PRESSED) {
+s32 common_slide_action_with_jump(
+ struct MarioState *m, u32 stopAction, u32 jumpAction, u32 airAction,
+ s32 animation)
+{
+ if (m->actionTimer == 5)
+ {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_jumping_action(m, jumpAction, 0);
}
- } else {
+ }
+ else
+ {
m->actionTimer++;
}
- if (update_sliding(m, 4.0f)) {
+ if (update_sliding(m, 4.0f))
+ {
return set_mario_action(m, stopAction, 0);
}
@@ -1437,17 +1731,20 @@ s32 common_slide_action_with_jump(struct MarioState *m, u32 stopAction, u32 jump
return FALSE;
}
-s32 act_butt_slide(struct MarioState *m) {
+s32 act_butt_slide(struct MarioState *m)
+{
s32 cancel = common_slide_action_with_jump(m, ACT_BUTT_SLIDE_STOP, ACT_JUMP, ACT_BUTT_SLIDE_AIR,
MARIO_ANIM_SLIDE);
tilt_body_butt_slide(m);
return cancel;
}
-s32 act_hold_butt_slide(struct MarioState *m) {
+s32 act_hold_butt_slide(struct MarioState *m)
+{
s32 cancel;
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_BUTT_SLIDE, 0);
}
@@ -1457,35 +1754,46 @@ s32 act_hold_butt_slide(struct MarioState *m) {
return cancel;
}
-s32 act_crouch_slide(struct MarioState *m) {
+s32 act_crouch_slide(struct MarioState *m)
+{
s32 cancel;
- if (m->input & INPUT_ABOVE_SLIDE) {
+ if (m->input & INPUT_ABOVE_SLIDE)
+ {
return set_mario_action(m, ACT_BUTT_SLIDE, 0);
}
- if (m->actionTimer < 30) {
+ if (m->actionTimer < 30)
+ {
m->actionTimer++;
- if (m->input & INPUT_A_PRESSED) {
- if (m->forwardVel > 10.0f) {
+ if (m->input & INPUT_A_PRESSED)
+ {
+ if (m->forwardVel > 10.0f)
+ {
return set_jumping_action(m, ACT_LONG_JUMP, 0);
}
}
}
- if (m->input & INPUT_B_PRESSED) {
- if (m->forwardVel >= 10.0f) {
+ if (m->input & INPUT_B_PRESSED)
+ {
+ if (m->forwardVel >= 10.0f)
+ {
return set_mario_action(m, ACT_SLIDE_KICK, 0);
- } else {
+ }
+ else
+ {
return set_mario_action(m, ACT_MOVE_PUNCHING, 0x0009);
}
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_jumping_action(m, ACT_JUMP, 0);
}
- if (m->input & INPUT_FIRST_PERSON) {
+ if (m->input & INPUT_FIRST_PERSON)
+ {
return set_mario_action(m, ACT_BRAKING, 0);
}
@@ -1494,21 +1802,25 @@ s32 act_crouch_slide(struct MarioState *m) {
return cancel;
}
-s32 act_slide_kick_slide(struct MarioState *m) {
- if (m->input & INPUT_A_PRESSED) {
-#ifdef VERSION_SH
+s32 act_slide_kick_slide(struct MarioState *m)
+{
+ if (m->input & INPUT_A_PRESSED)
+ {
+ #ifdef VERSION_SH
queue_rumble_data(5, 80);
-#endif
+ #endif
return set_jumping_action(m, ACT_FORWARD_ROLLOUT, 0);
}
set_mario_animation(m, MARIO_ANIM_SLIDE_KICK);
- if (is_anim_at_end(m) && m->forwardVel < 1.0f) {
+ if (is_anim_at_end(m) && m->forwardVel < 1.0f)
+ {
return set_mario_action(m, ACT_SLIDE_KICK_SLIDE_STOP, 0);
}
update_sliding(m, 1.0f);
- switch (perform_ground_step(m)) {
+ switch (perform_ground_step(m))
+ {
case GROUND_STEP_LEFT_GROUND:
set_mario_action(m, ACT_FREEFALL, 2);
break;
@@ -1525,20 +1837,26 @@ s32 act_slide_kick_slide(struct MarioState *m) {
return FALSE;
}
-s32 stomach_slide_action(struct MarioState *m, u32 stopAction, u32 airAction, s32 animation) {
- if (m->actionTimer == 5) {
- if (!(m->input & INPUT_ABOVE_SLIDE) && (m->input & (INPUT_A_PRESSED | INPUT_B_PRESSED))) {
-#ifdef VERSION_SH
+s32 stomach_slide_action(struct MarioState *m, u32 stopAction, u32 airAction, s32 animation)
+{
+ if (m->actionTimer == 5)
+ {
+ if (!(m->input & INPUT_ABOVE_SLIDE) && m->input & (INPUT_A_PRESSED | INPUT_B_PRESSED))
+ {
+ #ifdef VERSION_SH
queue_rumble_data(5, 80);
-#endif
+ #endif
return drop_and_set_mario_action(
m, m->forwardVel >= 0.0f ? ACT_FORWARD_ROLLOUT : ACT_BACKWARD_ROLLOUT, 0);
}
- } else {
+ }
+ else
+ {
m->actionTimer++;
}
- if (update_sliding(m, 4.0f)) {
+ if (update_sliding(m, 4.0f))
+ {
return set_mario_action(m, stopAction, 0);
}
@@ -1546,15 +1864,18 @@ s32 stomach_slide_action(struct MarioState *m, u32 stopAction, u32 airAction, s3
return FALSE;
}
-s32 act_stomach_slide(struct MarioState *m) {
+s32 act_stomach_slide(struct MarioState *m)
+{
s32 cancel = stomach_slide_action(m, ACT_STOMACH_SLIDE_STOP, ACT_FREEFALL, MARIO_ANIM_SLIDE_DIVE);
return cancel;
}
-s32 act_hold_stomach_slide(struct MarioState *m) {
+s32 act_hold_stomach_slide(struct MarioState *m)
+{
s32 cancel;
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_STOMACH_SLIDE, 0);
}
@@ -1562,11 +1883,13 @@ s32 act_hold_stomach_slide(struct MarioState *m) {
return cancel;
}
-s32 act_dive_slide(struct MarioState *m) {
- if (!(m->input & INPUT_ABOVE_SLIDE) && (m->input & (INPUT_A_PRESSED | INPUT_B_PRESSED))) {
-#ifdef VERSION_SH
+s32 act_dive_slide(struct MarioState *m)
+{
+ if (!(m->input & INPUT_ABOVE_SLIDE) && m->input & (INPUT_A_PRESSED | INPUT_B_PRESSED))
+ {
+ #ifdef VERSION_SH
queue_rumble_data(5, 80);
-#endif
+ #endif
return set_mario_action(m, m->forwardVel > 0.0f ? ACT_FORWARD_ROLLOUT : ACT_BACKWARD_ROLLOUT,
0);
}
@@ -1578,12 +1901,14 @@ s32 act_dive_slide(struct MarioState *m) {
// mario_check_object_grab, and so will end up in the regular picking action,
// rather than the picking up after dive action.
- if (update_sliding(m, 8.0f) && is_anim_at_end(m)) {
+ if (update_sliding(m, 8.0f) && is_anim_at_end(m))
+ {
mario_set_forward_vel(m, 0.0f);
set_mario_action(m, ACT_STOMACH_SLIDE_STOP, 0);
}
- if (mario_check_object_grab(m)) {
+ if (mario_check_object_grab(m))
+ {
mario_grab_used_object(m);
m->marioBodyState->grabPos = GRAB_POS_LIGHT_OBJ;
return TRUE;
@@ -1593,50 +1918,72 @@ s32 act_dive_slide(struct MarioState *m) {
return FALSE;
}
-s32 common_ground_knockback_action(struct MarioState *m, s32 animation, s32 arg2, s32 arg3, s32 arg4) {
+s32 common_ground_knockback_action(struct MarioState *m, s32 animation, s32 arg2, s32 arg3, s32 arg4)
+{
s32 animFrame;
- if (arg3) {
+ if (arg3)
+ {
play_mario_heavy_landing_sound_once(m, SOUND_ACTION_TERRAIN_BODY_HIT_GROUND);
}
- if (arg4 > 0) {
+ if (arg4 > 0)
+ {
play_sound_if_no_flag(m, SOUND_MARIO_ATTACKED, MARIO_MARIO_SOUND_PLAYED);
- } else {
-#ifdef VERSION_JP
+ }
+ else
+ {
+ #ifdef VERSION_JP
play_sound_if_no_flag(m, SOUND_MARIO_OOOF, MARIO_MARIO_SOUND_PLAYED);
-#else
+ #else
play_sound_if_no_flag(m, SOUND_MARIO_OOOF2, MARIO_MARIO_SOUND_PLAYED);
-#endif
+ #endif
}
- if (m->forwardVel > 32.0f) {
+ if (m->forwardVel > 32.0f)
+ {
m->forwardVel = 32.0f;
}
- if (m->forwardVel < -32.0f) {
+ if (m->forwardVel < -32.0f)
+ {
m->forwardVel = -32.0f;
}
animFrame = set_mario_animation(m, animation);
- if (animFrame < arg2) {
+ if (animFrame < arg2)
+ {
apply_landing_accel(m, 0.9f);
- } else if (m->forwardVel >= 0.0f) {
+ }
+ else if (m->forwardVel >= 0.0f)
+ {
mario_set_forward_vel(m, 0.1f);
- } else {
+ }
+ else
+ {
mario_set_forward_vel(m, -0.1f);
}
- if (perform_ground_step(m) == GROUND_STEP_LEFT_GROUND) {
- if (m->forwardVel >= 0.0f) {
+ if (perform_ground_step(m) == GROUND_STEP_LEFT_GROUND)
+ {
+ if (m->forwardVel >= 0.0f)
+ {
set_mario_action(m, ACT_FORWARD_AIR_KB, arg4);
- } else {
+ }
+ else
+ {
set_mario_action(m, ACT_BACKWARD_AIR_KB, arg4);
}
- } else if (is_anim_at_end(m)) {
- if (m->health < 0x100) {
+ }
+ else if (is_anim_at_end(m))
+ {
+ if (m->health < 0x100)
+ {
set_mario_action(m, ACT_STANDING_DEATH, 0);
- } else {
- if (arg4 > 0) {
+ }
+ else
+ {
+ if (arg4 > 0)
+ {
m->invincTimer = 30;
}
set_mario_action(m, ACT_IDLE, 0);
@@ -1646,66 +1993,79 @@ s32 common_ground_knockback_action(struct MarioState *m, s32 animation, s32 arg2
return animFrame;
}
-s32 act_hard_backward_ground_kb(struct MarioState *m) {
+s32 act_hard_backward_ground_kb(struct MarioState *m)
+{
s32 animFrame =
- common_ground_knockback_action(m, MARIO_ANIM_FALL_OVER_BACKWARDS, 43, TRUE, m->actionArg);
- if (animFrame == 43 && m->health < 0x100) {
+ common_ground_knockback_action(m, MARIO_ANIM_FALL_OVER_BACKWARDS, 43, TRUE, m->actionArg);
+ if (animFrame == 43 && m->health < 0x100)
+ {
set_mario_action(m, ACT_DEATH_ON_BACK, 0);
}
-#ifndef VERSION_JP
- if (animFrame == 54 && m->prevAction == ACT_SPECIAL_DEATH_EXIT) {
+ #ifndef VERSION_JP
+ if (animFrame == 54 && m->prevAction == ACT_SPECIAL_DEATH_EXIT)
+ {
play_sound(SOUND_MARIO_MAMA_MIA, m->marioObj->header.gfx.cameraToObject);
}
-#endif
+ #endif
- if (animFrame == 69) {
+ if (animFrame == 69)
+ {
play_mario_landing_sound_once(m, SOUND_ACTION_TERRAIN_LANDING);
}
return FALSE;
}
-s32 act_hard_forward_ground_kb(struct MarioState *m) {
+s32 act_hard_forward_ground_kb(struct MarioState *m)
+{
s32 animFrame =
- common_ground_knockback_action(m, MARIO_ANIM_LAND_ON_STOMACH, 21, TRUE, m->actionArg);
- if (animFrame == 23 && m->health < 0x100) {
+ common_ground_knockback_action(m, MARIO_ANIM_LAND_ON_STOMACH, 21, TRUE, m->actionArg);
+ if (animFrame == 23 && m->health < 0x100)
+ {
set_mario_action(m, ACT_DEATH_ON_STOMACH, 0);
}
return FALSE;
}
-s32 act_backward_ground_kb(struct MarioState *m) {
+s32 act_backward_ground_kb(struct MarioState *m)
+{
common_ground_knockback_action(m, MARIO_ANIM_BACKWARD_KB, 22, TRUE, m->actionArg);
return FALSE;
}
-s32 act_forward_ground_kb(struct MarioState *m) {
+s32 act_forward_ground_kb(struct MarioState *m)
+{
common_ground_knockback_action(m, MARIO_ANIM_FORWARD_KB, 20, TRUE, m->actionArg);
return FALSE;
}
-s32 act_soft_backward_ground_kb(struct MarioState *m) {
+s32 act_soft_backward_ground_kb(struct MarioState *m)
+{
common_ground_knockback_action(m, MARIO_ANIM_SOFT_BACK_KB, 100, FALSE, m->actionArg);
return FALSE;
}
-s32 act_soft_forward_ground_kb(struct MarioState *m) {
+s32 act_soft_forward_ground_kb(struct MarioState *m)
+{
common_ground_knockback_action(m, MARIO_ANIM_SOFT_FRONT_KB, 100, FALSE, m->actionArg);
return FALSE;
}
-s32 act_ground_bonk(struct MarioState *m) {
+s32 act_ground_bonk(struct MarioState *m)
+{
s32 animFrame =
- common_ground_knockback_action(m, MARIO_ANIM_GROUND_BONK, 32, TRUE, m->actionArg);
- if (animFrame == 32) {
+ common_ground_knockback_action(m, MARIO_ANIM_GROUND_BONK, 32, TRUE, m->actionArg);
+ if (animFrame == 32)
+ {
play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
}
return FALSE;
}
-s32 act_death_exit_land(struct MarioState *m) {
+s32 act_death_exit_land(struct MarioState *m)
+{
s32 animFrame;
apply_landing_accel(m, 0.9f);
@@ -1713,33 +2073,43 @@ s32 act_death_exit_land(struct MarioState *m) {
animFrame = set_mario_animation(m, MARIO_ANIM_FALL_OVER_BACKWARDS);
- if (animFrame == 54) {
+ if (animFrame == 54)
+ {
play_sound(SOUND_MARIO_MAMA_MIA, m->marioObj->header.gfx.cameraToObject);
}
- if (animFrame == 68) {
+ if (animFrame == 68)
+ {
play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
}
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_action(m, ACT_IDLE, 0);
}
return FALSE;
}
-u32 common_landing_action(struct MarioState *m, s16 animation, u32 airAction) {
+u32 common_landing_action(struct MarioState *m, s16 animation, u32 airAction)
+{
u32 stepResult;
- if (m->input & INPUT_NONZERO_ANALOG) {
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
apply_landing_accel(m, 0.98f);
- } else if (m->forwardVel >= 16.0f) {
+ }
+ else if (m->forwardVel >= 16.0f)
+ {
apply_slope_decel(m, 2.0f);
- } else {
+ }
+ else
+ {
m->vel[1] = 0.0f;
}
stepResult = perform_ground_step(m);
- switch (stepResult) {
+ switch (stepResult)
+ {
case GROUND_STEP_LEFT_GROUND:
set_mario_action(m, airAction, 0);
break;
@@ -1749,56 +2119,68 @@ u32 common_landing_action(struct MarioState *m, s16 animation, u32 airAction) {
break;
}
- if (m->forwardVel > 16.0f) {
+ if (m->forwardVel > 16.0f)
+ {
m->particleFlags |= PARTICLE_DUST;
}
set_mario_animation(m, animation);
play_mario_landing_sound_once(m, SOUND_ACTION_TERRAIN_LANDING);
- if (m->floor->type >= SURFACE_SHALLOW_QUICKSAND && m->floor->type <= SURFACE_MOVING_QUICKSAND) {
+ if (m->floor->type >= SURFACE_SHALLOW_QUICKSAND && m->floor->type <= SURFACE_MOVING_QUICKSAND)
+ {
m->quicksandDepth += (4 - m->actionTimer) * 3.5f - 0.5f;
}
return stepResult;
}
-s32 common_landing_cancels(struct MarioState *m, struct LandingAction *landingAction,
- s32 (*setAPressAction)(struct MarioState *, u32, u32)) {
+s32 common_landing_cancels(
+ struct MarioState *m, struct LandingAction *landingAction,
+ s32 (*setAPressAction)(struct MarioState *, u32, u32))
+{
//! Everything here, including floor steepness, is checked before checking
// if Mario is actually on the floor. This leads to e.g. remote sliding.
- if (m->floor->normal.y < 0.2923717f) {
+ if (m->floor->normal.y < 0.2923717f)
+ {
return mario_push_off_steep_floor(m, landingAction->verySteepAction, 0);
}
m->doubleJumpTimer = landingAction->unk02;
- if (should_begin_sliding(m)) {
+ if (should_begin_sliding(m))
+ {
return set_mario_action(m, landingAction->slideAction, 0);
}
- if (m->input & INPUT_FIRST_PERSON) {
+ if (m->input & INPUT_FIRST_PERSON)
+ {
return set_mario_action(m, landingAction->endAction, 0);
}
- if (++m->actionTimer >= landingAction->numFrames) {
+ if (++m->actionTimer >= landingAction->numFrames)
+ {
return set_mario_action(m, landingAction->endAction, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return setAPressAction(m, landingAction->aPressedAction, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return set_mario_action(m, landingAction->offFloorAction, 0);
}
return FALSE;
}
-s32 act_jump_land(struct MarioState *m) {
- if (common_landing_cancels(m, &sJumpLandAction, set_jumping_action)) {
+s32 act_jump_land(struct MarioState *m)
+{
+ if (common_landing_cancels(m, &sJumpLandAction, set_jumping_action))
+ {
return TRUE;
}
@@ -1806,8 +2188,10 @@ s32 act_jump_land(struct MarioState *m) {
return FALSE;
}
-s32 act_freefall_land(struct MarioState *m) {
- if (common_landing_cancels(m, &sFreefallLandAction, set_jumping_action)) {
+s32 act_freefall_land(struct MarioState *m)
+{
+ if (common_landing_cancels(m, &sFreefallLandAction, set_jumping_action))
+ {
return TRUE;
}
@@ -1815,23 +2199,29 @@ s32 act_freefall_land(struct MarioState *m) {
return FALSE;
}
-s32 act_side_flip_land(struct MarioState *m) {
- if (common_landing_cancels(m, &sSideFlipLandAction, set_jumping_action)) {
+s32 act_side_flip_land(struct MarioState *m)
+{
+ if (common_landing_cancels(m, &sSideFlipLandAction, set_jumping_action))
+ {
return TRUE;
}
- if (common_landing_action(m, MARIO_ANIM_SLIDEFLIP_LAND, ACT_FREEFALL) != GROUND_STEP_HIT_WALL) {
+ if (common_landing_action(m, MARIO_ANIM_SLIDEFLIP_LAND, ACT_FREEFALL) != GROUND_STEP_HIT_WALL)
+ {
m->marioObj->header.gfx.angle[1] += 0x8000;
}
return FALSE;
}
-s32 act_hold_jump_land(struct MarioState *m) {
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+s32 act_hold_jump_land(struct MarioState *m)
+{
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_JUMP_LAND_STOP, 0);
}
- if (common_landing_cancels(m, &sHoldJumpLandAction, set_jumping_action)) {
+ if (common_landing_cancels(m, &sHoldJumpLandAction, set_jumping_action))
+ {
return TRUE;
}
@@ -1839,12 +2229,15 @@ s32 act_hold_jump_land(struct MarioState *m) {
return FALSE;
}
-s32 act_hold_freefall_land(struct MarioState *m) {
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+s32 act_hold_freefall_land(struct MarioState *m)
+{
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_FREEFALL_LAND_STOP, 0);
}
- if (common_landing_cancels(m, &sHoldFreefallLandAction, set_jumping_action)) {
+ if (common_landing_cancels(m, &sHoldFreefallLandAction, set_jumping_action))
+ {
return TRUE;
}
@@ -1852,49 +2245,60 @@ s32 act_hold_freefall_land(struct MarioState *m) {
return FALSE;
}
-s32 act_long_jump_land(struct MarioState *m) {
-#ifdef VERSION_SH
+s32 act_long_jump_land(struct MarioState *m)
+{
+ #ifdef VERSION_SH
// BLJ (Backwards Long Jump) speed build up fix, crushing SimpleFlips's dreams since July 1997
- if (m->forwardVel < 0.0f) {
+ if (m->forwardVel < 0.0f)
+ {
m->forwardVel = 0.0f;
}
-#endif
+ #endif
- if (!(m->input & INPUT_Z_DOWN)) {
+ if (!(m->input & INPUT_Z_DOWN))
+ {
m->input &= ~INPUT_A_PRESSED;
}
- if (common_landing_cancels(m, &sLongJumpLandAction, set_jumping_action)) {
+ if (common_landing_cancels(m, &sLongJumpLandAction, set_jumping_action))
+ {
return TRUE;
}
- if (!(m->input & INPUT_NONZERO_ANALOG)) {
+ if (!(m->input & INPUT_NONZERO_ANALOG))
+ {
play_sound_if_no_flag(m, SOUND_MARIO_UH2_2, MARIO_MARIO_SOUND_PLAYED);
}
common_landing_action(m,
- !m->marioObj->oMarioLongJumpIsSlow ? MARIO_ANIM_CROUCH_FROM_FAST_LONGJUMP
- : MARIO_ANIM_CROUCH_FROM_SLOW_LONGJUMP,
+ !m->marioObj->oMarioLongJumpIsSlow
+ ? MARIO_ANIM_CROUCH_FROM_FAST_LONGJUMP
+ : MARIO_ANIM_CROUCH_FROM_SLOW_LONGJUMP,
ACT_FREEFALL);
return FALSE;
}
-s32 act_double_jump_land(struct MarioState *m) {
- if (common_landing_cancels(m, &sDoubleJumpLandAction, set_triple_jump_action)) {
+s32 act_double_jump_land(struct MarioState *m)
+{
+ if (common_landing_cancels(m, &sDoubleJumpLandAction, set_triple_jump_action))
+ {
return TRUE;
}
common_landing_action(m, MARIO_ANIM_LAND_FROM_DOUBLE_JUMP, ACT_FREEFALL);
return FALSE;
}
-s32 act_triple_jump_land(struct MarioState *m) {
+s32 act_triple_jump_land(struct MarioState *m)
+{
m->input &= ~INPUT_A_PRESSED;
- if (common_landing_cancels(m, &sTripleJumpLandAction, set_jumping_action)) {
+ if (common_landing_cancels(m, &sTripleJumpLandAction, set_jumping_action))
+ {
return TRUE;
}
- if (!(m->input & INPUT_NONZERO_ANALOG)) {
+ if (!(m->input & INPUT_NONZERO_ANALOG))
+ {
play_sound_if_no_flag(m, SOUND_MARIO_HAHA, MARIO_MARIO_SOUND_PLAYED);
}
@@ -1902,16 +2306,20 @@ s32 act_triple_jump_land(struct MarioState *m) {
return FALSE;
}
-s32 act_backflip_land(struct MarioState *m) {
- if (!(m->input & INPUT_Z_DOWN)) {
+s32 act_backflip_land(struct MarioState *m)
+{
+ if (!(m->input & INPUT_Z_DOWN))
+ {
m->input &= ~INPUT_A_PRESSED;
}
- if (common_landing_cancels(m, &sBackflipLandAction, set_jumping_action)) {
+ if (common_landing_cancels(m, &sBackflipLandAction, set_jumping_action))
+ {
return TRUE;
}
- if (!(m->input & INPUT_NONZERO_ANALOG)) {
+ if (!(m->input & INPUT_NONZERO_ANALOG))
+ {
play_sound_if_no_flag(m, SOUND_MARIO_HAHA, MARIO_MARIO_SOUND_PLAYED);
}
@@ -1919,18 +2327,25 @@ s32 act_backflip_land(struct MarioState *m) {
return FALSE;
}
-s32 quicksand_jump_land_action(struct MarioState *m, s32 animation1, s32 animation2, u32 endAction,
- u32 airAction) {
- if (m->actionTimer++ < 6) {
+s32 quicksand_jump_land_action(
+ struct MarioState *m, s32 animation1, s32 animation2, u32 endAction,
+ u32 airAction)
+{
+ if (m->actionTimer++ < 6)
+ {
m->quicksandDepth -= (7 - m->actionTimer) * 0.8f;
- if (m->quicksandDepth < 1.0f) {
+ if (m->quicksandDepth < 1.0f)
+ {
m->quicksandDepth = 1.1f;
}
play_mario_jump_sound(m);
set_mario_animation(m, animation1);
- } else {
- if (m->actionTimer >= 13) {
+ }
+ else
+ {
+ if (m->actionTimer >= 13)
+ {
return set_mario_action(m, endAction, 0);
}
@@ -1938,41 +2353,50 @@ s32 quicksand_jump_land_action(struct MarioState *m, s32 animation1, s32 animati
}
apply_landing_accel(m, 0.95f);
- if (perform_ground_step(m) == GROUND_STEP_LEFT_GROUND) {
+ if (perform_ground_step(m) == GROUND_STEP_LEFT_GROUND)
+ {
set_mario_action(m, airAction, 0);
}
return FALSE;
}
-s32 act_quicksand_jump_land(struct MarioState *m) {
+s32 act_quicksand_jump_land(struct MarioState *m)
+{
s32 cancel = quicksand_jump_land_action(m, MARIO_ANIM_SINGLE_JUMP, MARIO_ANIM_LAND_FROM_SINGLE_JUMP,
ACT_JUMP_LAND_STOP, ACT_FREEFALL);
return cancel;
}
-s32 act_hold_quicksand_jump_land(struct MarioState *m) {
+s32 act_hold_quicksand_jump_land(struct MarioState *m)
+{
s32 cancel = quicksand_jump_land_action(m, MARIO_ANIM_JUMP_WITH_LIGHT_OBJ,
MARIO_ANIM_JUMP_LAND_WITH_LIGHT_OBJ, ACT_HOLD_JUMP_LAND_STOP,
ACT_HOLD_FREEFALL);
return cancel;
}
-s32 check_common_moving_cancels(struct MarioState *m) {
- if (m->pos[1] < m->waterLevel - 100) {
+s32 check_common_moving_cancels(struct MarioState *m)
+{
+ if (m->pos[1] < m->waterLevel - 100)
+ {
return set_water_plunge_action(m);
}
- if (!(m->action & ACT_FLAG_INVULNERABLE) && (m->input & INPUT_UNKNOWN_10)) {
+ if (!(m->action & ACT_FLAG_INVULNERABLE) && m->input & INPUT_UNKNOWN_10)
+ {
return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_SQUISHED) {
+ if (m->input & INPUT_SQUISHED)
+ {
return drop_and_set_mario_action(m, ACT_SQUISHED, 0);
}
- if (!(m->action & ACT_FLAG_INVULNERABLE)) {
- if (m->health < 0x100) {
+ if (!(m->action & ACT_FLAG_INVULNERABLE))
+ {
+ if (m->health < 0x100)
+ {
return drop_and_set_mario_action(m, ACT_STANDING_DEATH, 0);
}
}
@@ -1980,14 +2404,17 @@ s32 check_common_moving_cancels(struct MarioState *m) {
return FALSE;
}
-s32 mario_execute_moving_action(struct MarioState *m) {
+s32 mario_execute_moving_action(struct MarioState *m)
+{
s32 cancel;
- if (check_common_moving_cancels(m)) {
+ if (check_common_moving_cancels(m))
+ {
return TRUE;
}
- if (mario_update_quicksand(m, 0.25f)) {
+ if (mario_update_quicksand(m, 0.25f))
+ {
return TRUE;
}
@@ -2034,7 +2461,8 @@ s32 mario_execute_moving_action(struct MarioState *m) {
}
/* clang-format on */
- if (!cancel && (m->input & INPUT_IN_WATER)) {
+ if (!cancel && m->input & INPUT_IN_WATER)
+ {
m->particleFlags |= PARTICLE_WAVE_TRAIL;
m->particleFlags &= ~PARTICLE_DUST;
}
diff --git a/src/decomp/game/mario_actions_moving.h b/src/decomp/game/mario_actions_moving.h
index 3cdbf0b..a304b36 100644
--- a/src/decomp/game/mario_actions_moving.h
+++ b/src/decomp/game/mario_actions_moving.h
@@ -6,6 +6,7 @@
#include "../include/types.h"
void play_step_sound(struct MarioState *m, s16 frame1, s16 frame2);
+
s32 mario_execute_moving_action(struct MarioState *m);
#endif // MARIO_ACTIONS_MOVING
diff --git a/src/decomp/game/mario_actions_object.c b/src/decomp/game/mario_actions_object.c
index 638cb36..8cb3d04 100644
--- a/src/decomp/game/mario_actions_object.c
+++ b/src/decomp/game/mario_actions_object.c
@@ -21,98 +21,122 @@
* Used by act_punching() to determine Mario's forward velocity during each
* animation frame.
*/
-s8 sPunchingForwardVelocities[8] = { 0, 1, 1, 2, 3, 5, 7, 10 };
+s8 sPunchingForwardVelocities[8] = {0, 1, 1, 2, 3, 5, 7, 10};
-void animated_stationary_ground_step(struct MarioState *m, s32 animation, u32 endAction) {
+void animated_stationary_ground_step(struct MarioState *m, s32 animation, u32 endAction)
+{
stationary_ground_step(m);
set_mario_animation(m, animation);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_action(m, endAction, 0);
}
}
-s32 mario_update_punch_sequence(struct MarioState *m) {
+s32 mario_update_punch_sequence(struct MarioState *m)
+{
u32 endAction, crouchEndAction;
s32 animFrame;
- if (m->action & ACT_FLAG_MOVING) {
+ if (m->action & ACT_FLAG_MOVING)
+ {
endAction = ACT_WALKING, crouchEndAction = ACT_CROUCH_SLIDE;
- } else {
+ }
+ else
+ {
endAction = ACT_IDLE, crouchEndAction = ACT_CROUCHING;
}
- switch (m->actionArg) {
+ switch (m->actionArg)
+ {
case 0:
play_sound(SOUND_MARIO_PUNCH_YAH, m->marioObj->header.gfx.cameraToObject);
- // Fall-through:
+ // Fall-through:
case 1:
set_mario_animation(m, MARIO_ANIM_FIRST_PUNCH);
- if (is_anim_past_end(m)) {
+ if (is_anim_past_end(m))
+ {
m->actionArg = 2;
- } else {
+ }
+ else
+ {
m->actionArg = 1;
}
- if (m->marioObj->header.gfx.animInfo.animFrame >= 2) {
- if (mario_check_object_grab(m)) {
+ if (m->marioObj->header.gfx.animInfo.animFrame >= 2)
+ {
+ if (mario_check_object_grab(m))
+ {
return TRUE;
}
m->flags |= MARIO_PUNCHING;
}
- if (m->actionArg == 2) {
- m->marioBodyState->punchState = (0 << 6) | 4;
+ if (m->actionArg == 2)
+ {
+ m->marioBodyState->punchState = 0 << 6 | 4;
}
break;
case 2:
set_mario_animation(m, MARIO_ANIM_FIRST_PUNCH_FAST);
- if (m->marioObj->header.gfx.animInfo.animFrame <= 0) {
+ if (m->marioObj->header.gfx.animInfo.animFrame <= 0)
+ {
m->flags |= MARIO_PUNCHING;
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
m->actionArg = 3;
}
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_action(m, endAction, 0);
}
break;
case 3:
play_sound(SOUND_MARIO_PUNCH_WAH, m->marioObj->header.gfx.cameraToObject);
- // Fall-through:
+ // Fall-through:
case 4:
set_mario_animation(m, MARIO_ANIM_SECOND_PUNCH);
- if (is_anim_past_end(m)) {
+ if (is_anim_past_end(m))
+ {
m->actionArg = 5;
- } else {
+ }
+ else
+ {
m->actionArg = 4;
}
- if (m->marioObj->header.gfx.animInfo.animFrame > 0) {
+ if (m->marioObj->header.gfx.animInfo.animFrame > 0)
+ {
m->flags |= MARIO_PUNCHING;
}
- if (m->actionArg == 5) {
- m->marioBodyState->punchState = (1 << 6) | 4;
+ if (m->actionArg == 5)
+ {
+ m->marioBodyState->punchState = 1 << 6 | 4;
}
break;
case 5:
set_mario_animation(m, MARIO_ANIM_SECOND_PUNCH_FAST);
- if (m->marioObj->header.gfx.animInfo.animFrame <= 0) {
+ if (m->marioObj->header.gfx.animInfo.animFrame <= 0)
+ {
m->flags |= MARIO_PUNCHING;
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
m->actionArg = 6;
}
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_action(m, endAction, 0);
}
break;
@@ -120,15 +144,18 @@ s32 mario_update_punch_sequence(struct MarioState *m) {
case 6:
play_mario_action_sound(m, SOUND_MARIO_PUNCH_HOO, 1);
animFrame = set_mario_animation(m, MARIO_ANIM_GROUND_KICK);
- if (animFrame == 0) {
- m->marioBodyState->punchState = (2 << 6) | 6;
+ if (animFrame == 0)
+ {
+ m->marioBodyState->punchState = 2 << 6 | 6;
}
- if (animFrame >= 0 && animFrame < 8) {
+ if (animFrame >= 0 && animFrame < 8)
+ {
m->flags |= MARIO_KICKING;
}
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_action(m, endAction, 0);
}
break;
@@ -138,11 +165,13 @@ s32 mario_update_punch_sequence(struct MarioState *m) {
set_mario_animation(m, MARIO_ANIM_BREAKDANCE);
animFrame = m->marioObj->header.gfx.animInfo.animFrame;
- if (animFrame >= 2 && animFrame < 8) {
+ if (animFrame >= 2 && animFrame < 8)
+ {
m->flags |= MARIO_TRIPPING;
}
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_action(m, crouchEndAction, 0);
}
break;
@@ -151,26 +180,32 @@ s32 mario_update_punch_sequence(struct MarioState *m) {
return FALSE;
}
-s32 act_punching(struct MarioState *m) {
- if (m->input & INPUT_UNKNOWN_10) {
+s32 act_punching(struct MarioState *m)
+{
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE)) {
+ if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE))
+ {
return check_common_action_exits(m);
}
- if (m->actionState == 0 && (m->input & INPUT_A_DOWN)) {
+ if (m->actionState == 0 && m->input & INPUT_A_DOWN)
+ {
return set_mario_action(m, ACT_JUMP_KICK, 0);
}
m->actionState = 1;
- if (m->actionArg == 0) {
+ if (m->actionArg == 0)
+ {
m->actionTimer = 7;
}
mario_set_forward_vel(m, sPunchingForwardVelocities[m->actionTimer]);
- if (m->actionTimer > 0) {
+ if (m->actionTimer > 0)
+ {
m->actionTimer--;
}
@@ -179,16 +214,20 @@ s32 act_punching(struct MarioState *m) {
return FALSE;
}
-s32 act_picking_up(struct MarioState *m) {
- if (m->input & INPUT_UNKNOWN_10) {
+s32 act_picking_up(struct MarioState *m)
+{
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return drop_and_set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->actionState == 0 && is_anim_at_end(m)) {
+ if (m->actionState == 0 && is_anim_at_end(m))
+ {
//! While the animation is playing, it is possible for the used object
// to unload. This allows you to pick up a vacant or newly loaded object
// slot (cloning via fake object).
@@ -197,17 +236,23 @@ s32 act_picking_up(struct MarioState *m) {
m->actionState = 1;
}
- if (m->actionState == 1) {
- if (m->heldObj->oInteractionSubtype & INT_SUBTYPE_GRABS_MARIO) {
+ if (m->actionState == 1)
+ {
+ if (m->heldObj->oInteractionSubtype & INT_SUBTYPE_GRABS_MARIO)
+ {
m->marioBodyState->grabPos = GRAB_POS_HEAVY_OBJ;
set_mario_animation(m, MARIO_ANIM_GRAB_HEAVY_OBJECT);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_action(m, ACT_HOLD_HEAVY_IDLE, 0);
}
- } else {
+ }
+ else
+ {
m->marioBodyState->grabPos = GRAB_POS_LIGHT_OBJ;
set_mario_animation(m, MARIO_ANIM_PICK_UP_LIGHT_OBJ);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_action(m, ACT_HOLD_IDLE, 0);
}
}
@@ -217,19 +262,23 @@ s32 act_picking_up(struct MarioState *m) {
return FALSE;
}
-s32 act_dive_picking_up(struct MarioState *m) {
- if (m->input & INPUT_UNKNOWN_10) {
+s32 act_dive_picking_up(struct MarioState *m)
+{
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
//! Hands-free holding. Landing on a slope or being pushed off a ledge while
// landing from a dive grab sets Mario's action to a non-holding action
// without dropping the object, causing the hands-free holding glitch.
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->input & INPUT_ABOVE_SLIDE) {
+ if (m->input & INPUT_ABOVE_SLIDE)
+ {
return set_mario_action(m, ACT_BEGIN_SLIDING, 0);
}
@@ -237,16 +286,20 @@ s32 act_dive_picking_up(struct MarioState *m) {
return FALSE;
}
-s32 act_placing_down(struct MarioState *m) {
- if (m->input & INPUT_UNKNOWN_10) {
+s32 act_placing_down(struct MarioState *m)
+{
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return drop_and_set_mario_action(m, ACT_FREEFALL, 0);
}
- if (++m->actionTimer == 8) {
+ if (++m->actionTimer == 8)
+ {
mario_drop_held_object(m);
}
@@ -254,64 +307,77 @@ s32 act_placing_down(struct MarioState *m) {
return FALSE;
}
-s32 act_throwing(struct MarioState *m) {
- if (m->heldObj && (m->heldObj->oInteractionSubtype & INT_SUBTYPE_HOLDABLE_NPC)) {
+s32 act_throwing(struct MarioState *m)
+{
+ if (m->heldObj && m->heldObj->oInteractionSubtype & INT_SUBTYPE_HOLDABLE_NPC)
+ {
return set_mario_action(m, ACT_PLACING_DOWN, 0);
}
- if (m->input & INPUT_UNKNOWN_10) {
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return drop_and_set_mario_action(m, ACT_FREEFALL, 0);
}
- if (++m->actionTimer == 7) {
+ if (++m->actionTimer == 7)
+ {
mario_throw_held_object(m);
play_sound_if_no_flag(m, SOUND_MARIO_WAH2, MARIO_MARIO_SOUND_PLAYED);
play_sound_if_no_flag(m, SOUND_ACTION_THROW, MARIO_ACTION_SOUND_PLAYED);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
queue_rumble_data(3, 50);
-#endif
+ #endif
}
animated_stationary_ground_step(m, MARIO_ANIM_GROUND_THROW, ACT_IDLE);
return FALSE;
}
-s32 act_heavy_throw(struct MarioState *m) {
- if (m->input & INPUT_UNKNOWN_10) {
+s32 act_heavy_throw(struct MarioState *m)
+{
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return drop_and_set_mario_action(m, ACT_FREEFALL, 0);
}
- if (++m->actionTimer == 13) {
+ if (++m->actionTimer == 13)
+ {
mario_drop_held_object(m);
play_sound_if_no_flag(m, SOUND_MARIO_WAH2, MARIO_MARIO_SOUND_PLAYED);
play_sound_if_no_flag(m, SOUND_ACTION_THROW, MARIO_ACTION_SOUND_PLAYED);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
queue_rumble_data(3, 50);
-#endif
+ #endif
}
animated_stationary_ground_step(m, MARIO_ANIM_HEAVY_THROW, ACT_IDLE);
return FALSE;
}
-s32 act_stomach_slide_stop(struct MarioState *m) {
- if (m->input & INPUT_UNKNOWN_10) {
+s32 act_stomach_slide_stop(struct MarioState *m)
+{
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->input & INPUT_ABOVE_SLIDE) {
+ if (m->input & INPUT_ABOVE_SLIDE)
+ {
return set_mario_action(m, ACT_BEGIN_SLIDING, 0);
}
@@ -319,20 +385,23 @@ s32 act_stomach_slide_stop(struct MarioState *m) {
return FALSE;
}
-s32 act_picking_up_bowser(struct MarioState *m) {
- if (m->actionState == 0) {
+s32 act_picking_up_bowser(struct MarioState *m)
+{
+ if (m->actionState == 0)
+ {
m->actionState = 1;
m->angleVel[1] = 0;
m->marioBodyState->grabPos = GRAB_POS_BOWSER;
mario_grab_used_object(m);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
queue_rumble_data(5, 80);
-#endif
+ #endif
play_sound(SOUND_MARIO_HRMM, m->marioObj->header.gfx.cameraToObject);
}
set_mario_animation(m, MARIO_ANIM_GRAB_BOWSER);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_action(m, ACT_HOLDING_BOWSER, 0);
}
@@ -340,59 +409,78 @@ s32 act_picking_up_bowser(struct MarioState *m) {
return FALSE;
}
-s32 act_holding_bowser(struct MarioState *m) {
+s32 act_holding_bowser(struct MarioState *m)
+{
s16 spin;
- if (m->input & INPUT_B_PRESSED) {
-#ifndef VERSION_JP
- if (m->angleVel[1] <= -0xE00 || m->angleVel[1] >= 0xE00) {
+ if (m->input & INPUT_B_PRESSED)
+ {
+ #ifndef VERSION_JP
+ if (m->angleVel[1] <= -0xE00 || m->angleVel[1] >= 0xE00)
+ {
play_sound(SOUND_MARIO_SO_LONGA_BOWSER, m->marioObj->header.gfx.cameraToObject);
- } else {
+ }
+ else
+ {
play_sound(SOUND_MARIO_HERE_WE_GO, m->marioObj->header.gfx.cameraToObject);
}
-#else
+ #else
play_sound(SOUND_MARIO_HERE_WE_GO, m->marioObj->header.gfx.cameraToObject);
-#endif
+ #endif
return set_mario_action(m, ACT_RELEASING_BOWSER, 0);
}
- if (m->angleVel[1] == 0) {
- if (m->actionTimer++ > 120) {
+ if (m->angleVel[1] == 0)
+ {
+ if (m->actionTimer++ > 120)
+ {
return set_mario_action(m, ACT_RELEASING_BOWSER, 1);
}
set_mario_animation(m, MARIO_ANIM_HOLDING_BOWSER);
- } else {
+ }
+ else
+ {
m->actionTimer = 0;
set_mario_animation(m, MARIO_ANIM_SWINGING_BOWSER);
}
- if (m->intendedMag > 20.0f) {
- if (m->actionArg == 0) {
+ if (m->intendedMag > 20.0f)
+ {
+ if (m->actionArg == 0)
+ {
m->actionArg = 1;
m->twirlYaw = m->intendedYaw;
- } else {
+ }
+ else
+ {
// spin = acceleration
spin = (s16)(m->intendedYaw - m->twirlYaw) / 0x80;
- if (spin < -0x80) {
+ if (spin < -0x80)
+ {
spin = -0x80;
}
- if (spin > 0x80) {
+ if (spin > 0x80)
+ {
spin = 0x80;
}
m->twirlYaw = m->intendedYaw;
m->angleVel[1] += spin;
- if (m->angleVel[1] > 0x1000) {
+ if (m->angleVel[1] > 0x1000)
+ {
m->angleVel[1] = 0x1000;
}
- if (m->angleVel[1] < -0x1000) {
+ if (m->angleVel[1] < -0x1000)
+ {
m->angleVel[1] = -0x1000;
}
}
- } else {
+ }
+ else
+ {
m->actionArg = 0;
m->angleVel[1] = approach_s32(m->angleVel[1], 0, 64, 64);
}
@@ -402,40 +490,50 @@ s32 act_holding_bowser(struct MarioState *m) {
m->faceAngle[1] += m->angleVel[1];
// play sound on overflow
- if (m->angleVel[1] <= -0x100 && spin < m->faceAngle[1]) {
-#ifdef VERSION_SH
+ if (m->angleVel[1] <= -0x100 && spin < m->faceAngle[1])
+ {
+ #ifdef VERSION_SH
queue_rumble_data(4, 20);
-#endif
+ #endif
play_sound(SOUND_OBJ_BOWSER_SPINNING, m->marioObj->header.gfx.cameraToObject);
}
- if (m->angleVel[1] >= 0x100 && spin > m->faceAngle[1]) {
-#ifdef VERSION_SH
+ if (m->angleVel[1] >= 0x100 && spin > m->faceAngle[1])
+ {
+ #ifdef VERSION_SH
queue_rumble_data(4, 20);
-#endif
+ #endif
play_sound(SOUND_OBJ_BOWSER_SPINNING, m->marioObj->header.gfx.cameraToObject);
}
stationary_ground_step(m);
- if (m->angleVel[1] >= 0) {
+ if (m->angleVel[1] >= 0)
+ {
m->marioObj->header.gfx.angle[0] = -m->angleVel[1];
- } else {
+ }
+ else
+ {
m->marioObj->header.gfx.angle[0] = m->angleVel[1];
}
return FALSE;
}
-s32 act_releasing_bowser(struct MarioState *m) {
- if (++m->actionTimer == 1) {
- if (m->actionArg == 0) {
-#ifdef VERSION_SH
+s32 act_releasing_bowser(struct MarioState *m)
+{
+ if (++m->actionTimer == 1)
+ {
+ if (m->actionArg == 0)
+ {
+ #ifdef VERSION_SH
queue_rumble_data(4, 50);
-#endif
+ #endif
mario_throw_held_object(m);
- } else {
-#ifdef VERSION_SH
+ }
+ else
+ {
+ #ifdef VERSION_SH
queue_rumble_data(4, 50);
-#endif
+ #endif
mario_drop_held_object(m);
}
}
@@ -445,31 +543,38 @@ s32 act_releasing_bowser(struct MarioState *m) {
return FALSE;
}
-s32 check_common_object_cancels(struct MarioState *m) {
+s32 check_common_object_cancels(struct MarioState *m)
+{
f32 waterSurface = m->waterLevel - 100;
- if (m->pos[1] < waterSurface) {
+ if (m->pos[1] < waterSurface)
+ {
return set_water_plunge_action(m);
}
- if (m->input & INPUT_SQUISHED) {
+ if (m->input & INPUT_SQUISHED)
+ {
return drop_and_set_mario_action(m, ACT_SQUISHED, 0);
}
- if (m->health < 0x100) {
+ if (m->health < 0x100)
+ {
return drop_and_set_mario_action(m, ACT_STANDING_DEATH, 0);
}
return FALSE;
}
-s32 mario_execute_object_action(struct MarioState *m) {
+s32 mario_execute_object_action(struct MarioState *m)
+{
s32 cancel;
- if (check_common_object_cancels(m)) {
+ if (check_common_object_cancels(m))
+ {
return TRUE;
}
- if (mario_update_quicksand(m, 0.5f)) {
+ if (mario_update_quicksand(m, 0.5f))
+ {
return TRUE;
}
@@ -488,7 +593,8 @@ s32 mario_execute_object_action(struct MarioState *m) {
}
/* clang-format on */
- if (!cancel && (m->input & INPUT_IN_WATER)) {
+ if (!cancel && m->input & INPUT_IN_WATER)
+ {
m->particleFlags |= PARTICLE_IDLE_WATER_WAVE;
}
diff --git a/src/decomp/game/mario_actions_object.h b/src/decomp/game/mario_actions_object.h
index b626b73..224faf6 100644
--- a/src/decomp/game/mario_actions_object.h
+++ b/src/decomp/game/mario_actions_object.h
@@ -6,6 +6,7 @@
#include "../include/types.h"
s32 mario_update_punch_sequence(struct MarioState *m);
+
s32 mario_execute_object_action(struct MarioState *m);
#endif // MARIO_ACTIONS_OBJECT_H
diff --git a/src/decomp/game/mario_actions_stationary.c b/src/decomp/game/mario_actions_stationary.c
index f46cb04..9ce206a 100644
--- a/src/decomp/game/mario_actions_stationary.c
+++ b/src/decomp/game/mario_actions_stationary.c
@@ -24,120 +24,153 @@
#include "../include/mario_geo_switch_case_ids.h"
-s32 check_common_idle_cancels(struct MarioState *m) {
+s32 check_common_idle_cancels(struct MarioState *m)
+{
mario_drop_held_object(m);
- if (m->floor->normal.y < 0.29237169f) {
+ if (m->floor->normal.y < 0.29237169f)
+ {
return mario_push_off_steep_floor(m, ACT_FREEFALL, 0);
}
- if (m->input & INPUT_UNKNOWN_10) {
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_jumping_action(m, ACT_JUMP, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->input & INPUT_ABOVE_SLIDE) {
+ if (m->input & INPUT_ABOVE_SLIDE)
+ {
return set_mario_action(m, ACT_BEGIN_SLIDING, 0);
}
- if (m->input & INPUT_FIRST_PERSON) {
+ if (m->input & INPUT_FIRST_PERSON)
+ {
return set_mario_action(m, ACT_FIRST_PERSON, 0);
}
- if (m->input & INPUT_NONZERO_ANALOG) {
- m->faceAngle[1] = (s16) m->intendedYaw;
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
+ m->faceAngle[1] = m->intendedYaw;
return set_mario_action(m, ACT_WALKING, 0);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_PUNCHING, 0);
}
- if (m->input & INPUT_Z_DOWN) {
+ if (m->input & INPUT_Z_DOWN)
+ {
return set_mario_action(m, ACT_START_CROUCHING, 0);
}
return FALSE;
}
-s32 check_common_hold_idle_cancels(struct MarioState *m) {
- if (m->floor->normal.y < 0.29237169f) {
+s32 check_common_hold_idle_cancels(struct MarioState *m)
+{
+ if (m->floor->normal.y < 0.29237169f)
+ {
return mario_push_off_steep_floor(m, ACT_HOLD_FREEFALL, 0);
}
- if (m->heldObj->oInteractionSubtype & INT_SUBTYPE_DROP_IMMEDIATELY) {
+ if (m->heldObj->oInteractionSubtype & INT_SUBTYPE_DROP_IMMEDIATELY)
+ {
m->heldObj->oInteractionSubtype =
- (s32)(m->heldObj->oInteractionSubtype & ~INT_SUBTYPE_DROP_IMMEDIATELY);
+ (s32)(m->heldObj->oInteractionSubtype & ~INT_SUBTYPE_DROP_IMMEDIATELY);
return set_mario_action(m, ACT_PLACING_DOWN, 0);
}
- if (m->input & INPUT_UNKNOWN_10) {
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_jumping_action(m, ACT_HOLD_JUMP, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return set_mario_action(m, ACT_HOLD_FREEFALL, 0);
}
- if (m->input & INPUT_ABOVE_SLIDE) {
+ if (m->input & INPUT_ABOVE_SLIDE)
+ {
return set_mario_action(m, ACT_HOLD_BEGIN_SLIDING, 0);
}
- if (m->input & INPUT_NONZERO_ANALOG) {
- m->faceAngle[1] = (s16) m->intendedYaw;
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
+ m->faceAngle[1] = m->intendedYaw;
return set_mario_action(m, ACT_HOLD_WALKING, 0);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_THROWING, 0);
}
- if (m->input & INPUT_Z_DOWN) {
+ if (m->input & INPUT_Z_DOWN)
+ {
return drop_and_set_mario_action(m, ACT_START_CROUCHING, 0);
}
return FALSE;
}
-s32 act_idle(struct MarioState *m) {
- if (m->quicksandDepth > 30.0f) {
+s32 act_idle(struct MarioState *m)
+{
+ if (m->quicksandDepth > 30.0f)
+ {
return set_mario_action(m, ACT_IN_QUICKSAND, 0);
}
- if (m->input & INPUT_IN_POISON_GAS) {
+ if (m->input & INPUT_IN_POISON_GAS)
+ {
return set_mario_action(m, ACT_COUGHING, 0);
}
- if (!(m->actionArg & 1) && m->health < 0x300) {
+ if (!(m->actionArg & 1) && m->health < 0x300)
+ {
return set_mario_action(m, ACT_PANTING, 0);
}
- if (check_common_idle_cancels(m)) {
+ if (check_common_idle_cancels(m))
+ {
return TRUE;
}
- if (m->actionState == 3) {
- if (m->floor != NULL && m->curTerrain == TERRAIN_SNOW) {
+ if (m->actionState == 3)
+ {
+ if (m->floor != NULL && m->curTerrain == TERRAIN_SNOW)
+ {
return set_mario_action(m, ACT_SHIVERING, 0);
- } else {
+ }
+ else
+ {
return set_mario_action(m, ACT_START_SLEEPING, 0);
}
}
- if (m->actionArg & 1) {
+ if (m->actionArg & 1)
+ {
set_mario_animation(m, MARIO_ANIM_STAND_AGAINST_WALL);
- } else {
- switch (m->actionState) {
+ }
+ else
+ {
+ switch (m->actionState)
+ {
case 0:
set_mario_animation(m, MARIO_ANIM_IDLE_HEAD_LEFT);
break;
@@ -151,7 +184,8 @@ s32 act_idle(struct MarioState *m) {
break;
}
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
// Fall asleep after 10 head turning cycles.
// act_start_sleeping is triggered earlier in the function
// when actionState == 3. This happens when Mario's done
@@ -159,14 +193,19 @@ s32 act_idle(struct MarioState *m) {
// here to make sure that Mario would be able to sleep here,
// and that he's gone through 10 cycles before sleeping.
// actionTimer is used to track how many cycles have passed.
- if (++m->actionState == 3) {
+ if (++m->actionState == 3)
+ {
f32 deltaYOfFloorBehindMario = m->pos[1] - find_floor_height_relative_polar(m, -0x8000, 60.0f);
- if (deltaYOfFloorBehindMario < -24.0f || 24.0f < deltaYOfFloorBehindMario || m->floor->flags & SURFACE_FLAG_DYNAMIC) {
+ if (deltaYOfFloorBehindMario < -24.0f || 24.0f < deltaYOfFloorBehindMario || m->floor->flags & SURFACE_FLAG_DYNAMIC)
+ {
m->actionState = 0;
- } else {
+ }
+ else
+ {
// If Mario hasn't turned his head 10 times yet, stay idle instead of going to sleep.
m->actionTimer++;
- if (m->actionTimer < 10) {
+ if (m->actionTimer < 10)
+ {
m->actionState = 0;
}
}
@@ -179,57 +218,64 @@ s32 act_idle(struct MarioState *m) {
return FALSE;
}
-void play_anim_sound(struct MarioState *m, u32 actionState, s32 animFrame, u32 sound) {
- if (m->actionState == actionState && m->marioObj->header.gfx.animInfo.animFrame == animFrame) {
+void play_anim_sound(struct MarioState *m, u32 actionState, s32 animFrame, u32 sound)
+{
+ if (m->actionState == actionState && m->marioObj->header.gfx.animInfo.animFrame == animFrame)
+ {
play_sound(sound, m->marioObj->header.gfx.cameraToObject);
}
}
-s32 act_start_sleeping(struct MarioState *m) {
-#ifndef VERSION_JP
+s32 act_start_sleeping(struct MarioState *m)
+{
+ #ifndef VERSION_JP
s32 animFrame;
-#endif
+ #endif
- if (check_common_idle_cancels(m)) {
+ if (check_common_idle_cancels(m))
+ {
return TRUE;
}
- if (m->quicksandDepth > 30.0f) {
+ if (m->quicksandDepth > 30.0f)
+ {
return set_mario_action(m, ACT_IN_QUICKSAND, 0);
}
- if (m->actionState == 4) {
+ if (m->actionState == 4)
+ {
return set_mario_action(m, ACT_SLEEPING, 0);
}
- switch (m->actionState) {
+ switch (m->actionState)
+ {
case 0:
-#ifndef VERSION_JP
+ #ifndef VERSION_JP
animFrame =
-#endif
- set_mario_animation(m, MARIO_ANIM_START_SLEEP_IDLE);
+ #endif
+ set_mario_animation(m, MARIO_ANIM_START_SLEEP_IDLE);
break;
case 1:
-#ifndef VERSION_JP
+ #ifndef VERSION_JP
animFrame =
-#endif
- set_mario_animation(m, MARIO_ANIM_START_SLEEP_SCRATCH);
+ #endif
+ set_mario_animation(m, MARIO_ANIM_START_SLEEP_SCRATCH);
break;
case 2:
-#ifndef VERSION_JP
+ #ifndef VERSION_JP
animFrame =
-#endif
- set_mario_animation(m, MARIO_ANIM_START_SLEEP_YAWN);
+ #endif
+ set_mario_animation(m, MARIO_ANIM_START_SLEEP_YAWN);
m->marioBodyState->eyeState = MARIO_EYES_HALF_CLOSED;
break;
case 3:
-#ifndef VERSION_JP
+ #ifndef VERSION_JP
animFrame =
-#endif
- set_mario_animation(m, MARIO_ANIM_START_SLEEP_SITTING);
+ #endif
+ set_mario_animation(m, MARIO_ANIM_START_SLEEP_SITTING);
m->marioBodyState->eyeState = MARIO_EYES_HALF_CLOSED;
break;
}
@@ -238,123 +284,147 @@ s32 act_start_sleeping(struct MarioState *m) {
play_anim_sound(m, 1, 49, SOUND_ACTION_PAT_BACK);
play_anim_sound(m, 3, 15, m->terrainSoundAddend + SOUND_ACTION_TERRAIN_BODY_HIT_GROUND);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
m->actionState++;
}
-#ifndef VERSION_JP
- if (m->actionState == 2 && animFrame == -1) {
+ #ifndef VERSION_JP
+ if (m->actionState == 2 && animFrame == -1)
+ {
play_sound(SOUND_MARIO_YAWNING, m->marioObj->header.gfx.cameraToObject);
}
- if (m->actionState == 1 && animFrame == -1) {
+ if (m->actionState == 1 && animFrame == -1)
+ {
play_sound(SOUND_MARIO_IMA_TIRED, m->marioObj->header.gfx.cameraToObject);
}
-#else
- if (m->actionState == 2) {
+ #else
+ if (m->actionState == 2)
+ {
play_sound_if_no_flag(m, SOUND_MARIO_YAWNING, MARIO_MARIO_SOUND_PLAYED);
}
-#endif
+ #endif
stationary_ground_step(m);
return FALSE;
}
-s32 act_sleeping(struct MarioState *m) {
+s32 act_sleeping(struct MarioState *m)
+{
s32 animFrame;
if (m->input
& (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE
- | INPUT_FIRST_PERSON | INPUT_UNKNOWN_10 | INPUT_B_PRESSED | INPUT_Z_PRESSED)) {
+ | INPUT_FIRST_PERSON | INPUT_UNKNOWN_10 | INPUT_B_PRESSED | INPUT_Z_PRESSED))
+ {
return set_mario_action(m, ACT_WAKING_UP, m->actionState);
}
- if (m->quicksandDepth > 30.0f) {
+ if (m->quicksandDepth > 30.0f)
+ {
return set_mario_action(m, ACT_WAKING_UP, m->actionState);
}
- if (m->pos[1] - find_floor_height_relative_polar(m, -0x8000, 60.0f) > 24.0f) {
+ if (m->pos[1] - find_floor_height_relative_polar(m, -0x8000, 60.0f) > 24.0f)
+ {
return set_mario_action(m, ACT_WAKING_UP, m->actionState);
}
m->marioBodyState->eyeState = MARIO_EYES_CLOSED;
stationary_ground_step(m);
- switch (m->actionState) {
+ switch (m->actionState)
+ {
case 0:
animFrame = set_mario_animation(m, MARIO_ANIM_SLEEP_IDLE);
- if (animFrame == -1 && !m->actionTimer) {
+ if (animFrame == -1 && !m->actionTimer)
+ {
lower_background_noise(2);
}
- if (animFrame == 2) {
+ if (animFrame == 2)
+ {
play_sound(SOUND_MARIO_SNORING1, m->marioObj->header.gfx.cameraToObject);
}
- if (animFrame == 20) {
+ if (animFrame == 20)
+ {
play_sound(SOUND_MARIO_SNORING2, m->marioObj->header.gfx.cameraToObject);
}
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
m->actionTimer++;
- if (m->actionTimer > 45) {
+ if (m->actionTimer > 45)
+ {
m->actionState++;
}
}
break;
case 1:
- if (set_mario_animation(m, MARIO_ANIM_SLEEP_START_LYING) == 18) {
+ if (set_mario_animation(m, MARIO_ANIM_SLEEP_START_LYING) == 18)
+ {
play_mario_heavy_landing_sound(m, SOUND_ACTION_TERRAIN_BODY_HIT_GROUND);
}
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
m->actionState++;
}
break;
case 2:
animFrame = set_mario_animation(m, MARIO_ANIM_SLEEP_LYING);
-#ifndef VERSION_JP
+ #ifndef VERSION_JP
play_sound_if_no_flag(m, SOUND_MARIO_SNORING3, MARIO_ACTION_SOUND_PLAYED);
-#else
- if (animFrame == 2) {
+ #else
+ if (animFrame == 2)
+ {
play_sound(SOUND_MARIO_SNORING2, m->marioObj->header.gfx.cameraToObject);
}
- if (animFrame == 25) {
+ if (animFrame == 25)
+ {
play_sound(SOUND_MARIO_SNORING1, m->marioObj->header.gfx.cameraToObject);
}
-#endif
+ #endif
break;
}
return FALSE;
}
-s32 act_waking_up(struct MarioState *m) {
- if (!m->actionTimer) {
+s32 act_waking_up(struct MarioState *m)
+{
+ if (!m->actionTimer)
+ {
stop_sound(SOUND_MARIO_SNORING1, m->marioObj->header.gfx.cameraToObject);
stop_sound(SOUND_MARIO_SNORING2, m->marioObj->header.gfx.cameraToObject);
-#ifndef VERSION_JP
+ #ifndef VERSION_JP
stop_sound(SOUND_MARIO_SNORING3, m->marioObj->header.gfx.cameraToObject);
-#endif
+ #endif
raise_background_noise(2);
}
- if (m->input & INPUT_UNKNOWN_10) {
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->input & INPUT_ABOVE_SLIDE) {
+ if (m->input & INPUT_ABOVE_SLIDE)
+ {
return set_mario_action(m, ACT_BEGIN_SLIDING, 0);
}
m->actionTimer++;
- if (m->actionTimer > 20) {
+ if (m->actionTimer > 20)
+ {
return set_mario_action(m, ACT_IDLE, 0);
}
@@ -365,53 +435,64 @@ s32 act_waking_up(struct MarioState *m) {
return FALSE;
}
-s32 act_shivering(struct MarioState *m) {
+s32 act_shivering(struct MarioState *m)
+{
s32 animFrame;
- if (m->input & INPUT_UNKNOWN_10) {
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->input & INPUT_ABOVE_SLIDE) {
+ if (m->input & INPUT_ABOVE_SLIDE)
+ {
return set_mario_action(m, ACT_BEGIN_SLIDING, 0);
}
if (m->input
& (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE
- | INPUT_FIRST_PERSON | INPUT_UNKNOWN_10 | INPUT_B_PRESSED | INPUT_Z_PRESSED)) {
+ | INPUT_FIRST_PERSON | INPUT_UNKNOWN_10 | INPUT_B_PRESSED | INPUT_Z_PRESSED))
+ {
m->actionState = 2;
}
stationary_ground_step(m);
- switch (m->actionState) {
+ switch (m->actionState)
+ {
case 0:
animFrame = set_mario_animation(m, MARIO_ANIM_SHIVERING_WARMING_HAND);
- if (animFrame == 49) {
+ if (animFrame == 49)
+ {
m->particleFlags |= PARTICLE_BREATH;
play_sound(SOUND_MARIO_PANTING_COLD, m->marioObj->header.gfx.cameraToObject);
}
- if (animFrame == 7 || animFrame == 81) {
+ if (animFrame == 7 || animFrame == 81)
+ {
play_sound(SOUND_ACTION_CLAP_HANDS_COLD, m->marioObj->header.gfx.cameraToObject);
}
- if (is_anim_past_end(m)) {
+ if (is_anim_past_end(m))
+ {
m->actionState = 1;
}
break;
case 1:
animFrame = set_mario_animation(m, MARIO_ANIM_SHIVERING);
- if (animFrame == 9 || animFrame == 25 || animFrame == 44) {
+ if (animFrame == 9 || animFrame == 25 || animFrame == 44)
+ {
play_sound(SOUND_ACTION_CLAP_HANDS_COLD, m->marioObj->header.gfx.cameraToObject);
}
break;
case 2:
set_mario_animation(m, MARIO_ANIM_SHIVERING_RETURN_TO_IDLE);
- if (is_anim_past_end(m)) {
+ if (is_anim_past_end(m))
+ {
set_mario_action(m, ACT_IDLE, 0);
}
break;
@@ -419,44 +500,53 @@ s32 act_shivering(struct MarioState *m) {
return FALSE;
}
-s32 act_coughing(struct MarioState *m) {
+s32 act_coughing(struct MarioState *m)
+{
s32 animFrame;
- if (check_common_idle_cancels(m)) {
+ if (check_common_idle_cancels(m))
+ {
return TRUE;
}
stationary_ground_step(m);
animFrame = set_mario_animation(m, MARIO_ANIM_COUGHING);
- if (animFrame == 25 || animFrame == 35) {
+ if (animFrame == 25 || animFrame == 35)
+ {
play_sound(SOUND_MARIO_COUGHING3, m->marioObj->header.gfx.cameraToObject);
}
- if (animFrame == 50 || animFrame == 58) {
+ if (animFrame == 50 || animFrame == 58)
+ {
play_sound(SOUND_MARIO_COUGHING2, m->marioObj->header.gfx.cameraToObject);
}
- if (animFrame == 71 || animFrame == 80) {
+ if (animFrame == 71 || animFrame == 80)
+ {
play_sound(SOUND_MARIO_COUGHING1, m->marioObj->header.gfx.cameraToObject);
}
return FALSE;
}
-s32 act_hold_idle(struct MarioState *m) {
-// if (segmented_to_virtual(&bhvJumpingBox) == m->heldObj->behavior) {
-// return set_mario_action(m, ACT_CRAZY_BOX_BOUNCE, 0);
-// }
+s32 act_hold_idle(struct MarioState *m)
+{
+ // if (segmented_to_virtual(&bhvJumpingBox) == m->heldObj->behavior) {
+ // return set_mario_action(m, ACT_CRAZY_BOX_BOUNCE, 0);
+ // }
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_IDLE, 0);
}
- if (m->quicksandDepth > 30.0f) {
+ if (m->quicksandDepth > 30.0f)
+ {
return drop_and_set_mario_action(m, ACT_IN_QUICKSAND, 0);
}
- if (check_common_hold_idle_cancels(m)) {
+ if (check_common_hold_idle_cancels(m))
+ {
return TRUE;
}
@@ -465,24 +555,30 @@ s32 act_hold_idle(struct MarioState *m) {
return FALSE;
}
-s32 act_hold_heavy_idle(struct MarioState *m) {
- if (m->input & INPUT_UNKNOWN_10) {
+s32 act_hold_heavy_idle(struct MarioState *m)
+{
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return drop_and_set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->input & INPUT_ABOVE_SLIDE) {
+ if (m->input & INPUT_ABOVE_SLIDE)
+ {
return drop_and_set_mario_action(m, ACT_BEGIN_SLIDING, 0);
}
- if (m->input & INPUT_NONZERO_ANALOG) {
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
return set_mario_action(m, ACT_HOLD_HEAVY_WALKING, 0);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_HEAVY_THROW, 0);
}
@@ -491,20 +587,25 @@ s32 act_hold_heavy_idle(struct MarioState *m) {
return FALSE;
}
-s32 act_standing_against_wall(struct MarioState *m) {
- if (m->input & INPUT_UNKNOWN_10) {
+s32 act_standing_against_wall(struct MarioState *m)
+{
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE)) {
+ if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE))
+ {
return check_common_action_exits(m);
}
- if (m->input & INPUT_FIRST_PERSON) {
+ if (m->input & INPUT_FIRST_PERSON)
+ {
return set_mario_action(m, ACT_FIRST_PERSON, 0);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_PUNCHING, 0);
}
@@ -513,18 +614,24 @@ s32 act_standing_against_wall(struct MarioState *m) {
return FALSE;
}
-s32 act_in_quicksand(struct MarioState *m) {
- if (m->quicksandDepth < 30.0f) {
+s32 act_in_quicksand(struct MarioState *m)
+{
+ if (m->quicksandDepth < 30.0f)
+ {
return set_mario_action(m, ACT_IDLE, 0);
}
- if (check_common_idle_cancels(m)) {
+ if (check_common_idle_cancels(m))
+ {
return TRUE;
}
- if (m->quicksandDepth > 70.0f) {
+ if (m->quicksandDepth > 70.0f)
+ {
set_mario_animation(m, MARIO_ANIM_DYING_IN_QUICKSAND);
- } else {
+ }
+ else
+ {
set_mario_animation(m, MARIO_ANIM_IDLE_IN_QUICKSAND);
}
@@ -532,36 +639,45 @@ s32 act_in_quicksand(struct MarioState *m) {
return FALSE;
}
-s32 act_crouching(struct MarioState *m) {
- if (m->input & INPUT_UNKNOWN_10) {
+s32 act_crouching(struct MarioState *m)
+{
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_jumping_action(m, ACT_BACKFLIP, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->input & INPUT_ABOVE_SLIDE) {
+ if (m->input & INPUT_ABOVE_SLIDE)
+ {
return set_mario_action(m, ACT_BEGIN_SLIDING, 0);
}
- if (m->input & INPUT_FIRST_PERSON) {
+ if (m->input & INPUT_FIRST_PERSON)
+ {
return set_mario_action(m, ACT_STOP_CROUCHING, 0);
}
- if (!(m->input & INPUT_Z_DOWN)) {
+ if (!(m->input & INPUT_Z_DOWN))
+ {
return set_mario_action(m, ACT_STOP_CROUCHING, 0);
}
- if (m->input & INPUT_NONZERO_ANALOG) {
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
return set_mario_action(m, ACT_START_CRAWLING, 0);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_PUNCHING, 9);
}
@@ -570,20 +686,25 @@ s32 act_crouching(struct MarioState *m) {
return FALSE;
}
-s32 act_panting(struct MarioState *m) {
- if (m->input & INPUT_UNKNOWN_10) {
+s32 act_panting(struct MarioState *m)
+{
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->health >= 0x500) {
+ if (m->health >= 0x500)
+ {
return set_mario_action(m, ACT_IDLE, 0);
}
- if (check_common_idle_cancels(m)) {
+ if (check_common_idle_cancels(m))
+ {
return TRUE;
}
- if (set_mario_animation(m, MARIO_ANIM_WALK_PANTING) == 1) {
+ if (set_mario_animation(m, MARIO_ANIM_WALK_PANTING) == 1)
+ {
play_sound(SOUND_MARIO_PANTING + ((gAudioRandom % 3U) << 0x10),
m->marioObj->header.gfx.cameraToObject);
}
@@ -593,20 +714,25 @@ s32 act_panting(struct MarioState *m) {
return FALSE;
}
-s32 act_hold_panting_unused(struct MarioState *m) {
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+s32 act_hold_panting_unused(struct MarioState *m)
+{
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_PANTING, 0);
}
- if (m->input & INPUT_UNKNOWN_10) {
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->health >= 0x500) {
+ if (m->health >= 0x500)
+ {
return set_mario_action(m, ACT_HOLD_IDLE, 0);
}
- if (check_common_hold_idle_cancels(m)) {
+ if (check_common_hold_idle_cancels(m))
+ {
return TRUE;
}
@@ -616,29 +742,36 @@ s32 act_hold_panting_unused(struct MarioState *m) {
return FALSE;
}
-void stopping_step(struct MarioState *m, s32 animID, u32 action) {
+void stopping_step(struct MarioState *m, s32 animID, u32 action)
+{
stationary_ground_step(m);
set_mario_animation(m, animID);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_action(m, action, 0);
}
}
-s32 act_braking_stop(struct MarioState *m) {
- if (m->input & INPUT_UNKNOWN_10) {
+s32 act_braking_stop(struct MarioState *m)
+{
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_PUNCHING, 0);
}
if (!(m->input & INPUT_FIRST_PERSON)
- && m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE)) {
+ && m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE))
+ {
return check_common_action_exits(m);
}
@@ -646,37 +779,46 @@ s32 act_braking_stop(struct MarioState *m) {
return FALSE;
}
-s32 act_butt_slide_stop(struct MarioState *m) {
- if (m->input & INPUT_UNKNOWN_10) {
+s32 act_butt_slide_stop(struct MarioState *m)
+{
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE)) {
+ if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE))
+ {
return check_common_action_exits(m);
}
stopping_step(m, MARIO_ANIM_STOP_SLIDE, ACT_IDLE);
- if (m->marioObj->header.gfx.animInfo.animFrame == 6) {
+ if (m->marioObj->header.gfx.animInfo.animFrame == 6)
+ {
play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
}
return FALSE;
}
-s32 act_hold_butt_slide_stop(struct MarioState *m) {
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+s32 act_hold_butt_slide_stop(struct MarioState *m)
+{
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_IDLE, 0);
}
- if (m->input & INPUT_UNKNOWN_10) {
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE)) {
+ if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE))
+ {
return check_common_hold_action_exits(m);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_THROWING, 0);
}
@@ -684,12 +826,15 @@ s32 act_hold_butt_slide_stop(struct MarioState *m) {
return FALSE;
}
-s32 act_slide_kick_slide_stop(struct MarioState *m) {
- if (m->input & INPUT_UNKNOWN_10) {
+s32 act_slide_kick_slide_stop(struct MarioState *m)
+{
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return drop_and_set_mario_action(m, ACT_FREEFALL, 0);
}
@@ -697,134 +842,165 @@ s32 act_slide_kick_slide_stop(struct MarioState *m) {
return FALSE;
}
-s32 act_start_crouching(struct MarioState *m) {
- if (m->input & INPUT_UNKNOWN_10) {
+s32 act_start_crouching(struct MarioState *m)
+{
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_jumping_action(m, ACT_BACKFLIP, 0);
}
- if (m->input & INPUT_ABOVE_SLIDE) {
+ if (m->input & INPUT_ABOVE_SLIDE)
+ {
return set_mario_action(m, ACT_BEGIN_SLIDING, 0);
}
stationary_ground_step(m);
set_mario_animation(m, MARIO_ANIM_START_CROUCHING);
- if (is_anim_past_end(m)) {
+ if (is_anim_past_end(m))
+ {
set_mario_action(m, ACT_CROUCHING, 0);
}
return FALSE;
}
-s32 act_stop_crouching(struct MarioState *m) {
- if (m->input & INPUT_UNKNOWN_10) {
+s32 act_stop_crouching(struct MarioState *m)
+{
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_jumping_action(m, ACT_BACKFLIP, 0);
}
- if (m->input & INPUT_ABOVE_SLIDE) {
+ if (m->input & INPUT_ABOVE_SLIDE)
+ {
return set_mario_action(m, ACT_BEGIN_SLIDING, 0);
}
stationary_ground_step(m);
set_mario_animation(m, MARIO_ANIM_STOP_CROUCHING);
- if (is_anim_past_end(m)) {
+ if (is_anim_past_end(m))
+ {
set_mario_action(m, ACT_IDLE, 0);
}
return FALSE;
}
-s32 act_start_crawling(struct MarioState *m) {
- if (m->input & INPUT_FIRST_PERSON) {
+s32 act_start_crawling(struct MarioState *m)
+{
+ if (m->input & INPUT_FIRST_PERSON)
+ {
return set_mario_action(m, ACT_STOP_CROUCHING, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->input & INPUT_UNKNOWN_10) {
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_ABOVE_SLIDE) {
+ if (m->input & INPUT_ABOVE_SLIDE)
+ {
return set_mario_action(m, ACT_BEGIN_SLIDING, 0);
}
stationary_ground_step(m);
set_mario_animation(m, MARIO_ANIM_START_CRAWLING);
- if (is_anim_past_end(m)) {
+ if (is_anim_past_end(m))
+ {
set_mario_action(m, ACT_CRAWLING, 0);
}
return FALSE;
}
-s32 act_stop_crawling(struct MarioState *m) {
- if (m->input & INPUT_UNKNOWN_10) {
+s32 act_stop_crawling(struct MarioState *m)
+{
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->input & INPUT_ABOVE_SLIDE) {
+ if (m->input & INPUT_ABOVE_SLIDE)
+ {
return set_mario_action(m, ACT_BEGIN_SLIDING, 0);
}
stationary_ground_step(m);
set_mario_animation(m, MARIO_ANIM_STOP_CRAWLING);
- if (is_anim_past_end(m)) {
+ if (is_anim_past_end(m))
+ {
set_mario_action(m, ACT_CROUCHING, 0);
}
return FALSE;
}
-s32 act_shockwave_bounce(struct MarioState *m) {
+s32 act_shockwave_bounce(struct MarioState *m)
+{
s16 sp1E;
f32 sp18;
- if (m->marioObj->oInteractStatus & INT_STATUS_HIT_BY_SHOCKWAVE) {
-#ifdef VERSION_SH
+ if (m->marioObj->oInteractStatus & INT_STATUS_HIT_BY_SHOCKWAVE)
+ {
+ #ifdef VERSION_SH
queue_rumble_data(70, 40);
-#endif
+ #endif
return hurt_and_set_mario_action(m, ACT_SHOCKED, 0, 4);
}
- if (m->actionTimer == 0) {
-#ifdef VERSION_SH
+ if (m->actionTimer == 0)
+ {
+ #ifdef VERSION_SH
queue_rumble_data(70, 40);
-#endif
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_UNK1) {
+ #endif
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_UNK1)
+ {
return hurt_and_set_mario_action(m, ACT_BACKWARD_GROUND_KB, 0, 0xc);
}
}
- if (++m->actionTimer == 48) {
+ if (++m->actionTimer == 48)
+ {
return set_mario_action(m, ACT_IDLE, 0);
}
sp1E = (m->actionTimer % 16) << 12;
- sp18 = (f32)(((f32)(6 - m->actionTimer / 8) * 8.0f) + 4.0f);
+ sp18 = (f32)(6 - m->actionTimer / 8) * 8.0f + 4.0f;
mario_set_forward_vel(m, 0);
vec3f_set(m->vel, 0.0f, 0.0f, 0.0f);
- if (sins(sp1E) >= 0.0f) {
+ if (sins(sp1E) >= 0.0f)
+ {
m->pos[1] = sins(sp1E) * sp18 + m->floorHeight;
- } else {
+ }
+ else
+ {
m->pos[1] = m->floorHeight - sins(sp1E) * sp18;
}
@@ -834,45 +1010,58 @@ s32 act_shockwave_bounce(struct MarioState *m) {
return FALSE;
}
-s32 landing_step(struct MarioState *m, s32 arg1, u32 action) {
+s32 landing_step(struct MarioState *m, s32 arg1, u32 action)
+{
stationary_ground_step(m);
set_mario_animation(m, arg1);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
return set_mario_action(m, action, 0);
}
return FALSE;
}
-s32 check_common_landing_cancels(struct MarioState *m, u32 action) {
- if (m->input & INPUT_UNKNOWN_10) {
+s32 check_common_landing_cancels(struct MarioState *m, u32 action)
+{
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_FIRST_PERSON) {
+ if (m->input & INPUT_FIRST_PERSON)
+ {
return set_mario_action(m, ACT_IDLE, 0);
}
- if (m->input & INPUT_A_PRESSED) {
- if (!action) {
+ if (m->input & INPUT_A_PRESSED)
+ {
+ if (!action)
+ {
return set_jump_from_landing(m);
- } else {
+ }
+ else
+ {
return set_jumping_action(m, action, 0);
}
}
- if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE)) {
+ if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE))
+ {
return check_common_action_exits(m);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_PUNCHING, 0);
}
return FALSE;
}
-s32 act_jump_land_stop(struct MarioState *m) {
- if (check_common_landing_cancels(m, 0)) {
+s32 act_jump_land_stop(struct MarioState *m)
+{
+ if (check_common_landing_cancels(m, 0))
+ {
return TRUE;
}
@@ -880,8 +1069,10 @@ s32 act_jump_land_stop(struct MarioState *m) {
return FALSE;
}
-s32 act_double_jump_land_stop(struct MarioState *m) {
- if (check_common_landing_cancels(m, 0)) {
+s32 act_double_jump_land_stop(struct MarioState *m)
+{
+ if (check_common_landing_cancels(m, 0))
+ {
return TRUE;
}
@@ -889,8 +1080,10 @@ s32 act_double_jump_land_stop(struct MarioState *m) {
return FALSE;
}
-s32 act_side_flip_land_stop(struct MarioState *m) {
- if (check_common_landing_cancels(m, 0)) {
+s32 act_side_flip_land_stop(struct MarioState *m)
+{
+ if (check_common_landing_cancels(m, 0))
+ {
return TRUE;
}
@@ -899,8 +1092,10 @@ s32 act_side_flip_land_stop(struct MarioState *m) {
return FALSE;
}
-s32 act_freefall_land_stop(struct MarioState *m) {
- if (check_common_landing_cancels(m, 0)) {
+s32 act_freefall_land_stop(struct MarioState *m)
+{
+ if (check_common_landing_cancels(m, 0))
+ {
return TRUE;
}
@@ -908,8 +1103,10 @@ s32 act_freefall_land_stop(struct MarioState *m) {
return FALSE;
}
-s32 act_triple_jump_land_stop(struct MarioState *m) {
- if (check_common_landing_cancels(m, ACT_JUMP)) {
+s32 act_triple_jump_land_stop(struct MarioState *m)
+{
+ if (check_common_landing_cancels(m, ACT_JUMP))
+ {
return TRUE;
}
@@ -917,12 +1114,15 @@ s32 act_triple_jump_land_stop(struct MarioState *m) {
return FALSE;
}
-s32 act_backflip_land_stop(struct MarioState *m) {
- if (!(m->input & INPUT_Z_DOWN) || m->marioObj->header.gfx.animInfo.animFrame >= 6) {
+s32 act_backflip_land_stop(struct MarioState *m)
+{
+ if (!(m->input & INPUT_Z_DOWN) || m->marioObj->header.gfx.animInfo.animFrame >= 6)
+ {
m->input &= ~INPUT_A_PRESSED;
}
- if (check_common_landing_cancels(m, ACT_BACKFLIP)) {
+ if (check_common_landing_cancels(m, ACT_BACKFLIP))
+ {
return TRUE;
}
@@ -930,10 +1130,12 @@ s32 act_backflip_land_stop(struct MarioState *m) {
return FALSE;
}
-s32 act_lava_boost_land(struct MarioState *m) {
+s32 act_lava_boost_land(struct MarioState *m)
+{
m->input &= ~(INPUT_FIRST_PERSON | INPUT_B_PRESSED);
- if (check_common_landing_cancels(m, 0)) {
+ if (check_common_landing_cancels(m, 0))
+ {
return TRUE;
}
@@ -941,32 +1143,40 @@ s32 act_lava_boost_land(struct MarioState *m) {
return FALSE;
}
-s32 act_long_jump_land_stop(struct MarioState *m) {
+s32 act_long_jump_land_stop(struct MarioState *m)
+{
m->input &= ~INPUT_B_PRESSED;
- if (check_common_landing_cancels(m, ACT_JUMP)) {
+ if (check_common_landing_cancels(m, ACT_JUMP))
+ {
return TRUE;
}
- landing_step(m, !m->marioObj->oMarioLongJumpIsSlow ? MARIO_ANIM_CROUCH_FROM_FAST_LONGJUMP
- : MARIO_ANIM_CROUCH_FROM_SLOW_LONGJUMP,
+ landing_step(m, !m->marioObj->oMarioLongJumpIsSlow
+ ? MARIO_ANIM_CROUCH_FROM_FAST_LONGJUMP
+ : MARIO_ANIM_CROUCH_FROM_SLOW_LONGJUMP,
ACT_CROUCHING);
return FALSE;
}
-s32 act_hold_jump_land_stop(struct MarioState *m) {
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+s32 act_hold_jump_land_stop(struct MarioState *m)
+{
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_IDLE, 0);
}
- if (m->input & INPUT_UNKNOWN_10) {
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE)) {
+ if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE))
+ {
return check_common_hold_action_exits(m);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_THROWING, 0);
}
@@ -974,36 +1184,45 @@ s32 act_hold_jump_land_stop(struct MarioState *m) {
return FALSE;
}
-s32 act_hold_freefall_land_stop(struct MarioState *m) {
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+s32 act_hold_freefall_land_stop(struct MarioState *m)
+{
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_IDLE, 0);
}
- if (m->input & INPUT_UNKNOWN_10) {
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE)) {
+ if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE))
+ {
return check_common_hold_action_exits(m);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_THROWING, 0);
}
landing_step(m, MARIO_ANIM_FALL_LAND_WITH_LIGHT_OBJ, ACT_HOLD_IDLE);
return FALSE;
}
-s32 act_air_throw_land(struct MarioState *m) {
- if (m->input & INPUT_UNKNOWN_10) {
+s32 act_air_throw_land(struct MarioState *m)
+{
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
- if (++m->actionTimer == 4) {
+ if (++m->actionTimer == 4)
+ {
mario_throw_held_object(m);
}
@@ -1011,21 +1230,26 @@ s32 act_air_throw_land(struct MarioState *m) {
return FALSE;
}
-s32 act_twirl_land(struct MarioState *m) {
+s32 act_twirl_land(struct MarioState *m)
+{
m->actionState = 1;
- if (m->input & INPUT_UNKNOWN_10) {
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
stationary_ground_step(m);
set_mario_animation(m, MARIO_ANIM_TWIRL_LAND);
- if (m->angleVel[1] > 0) {
+ if (m->angleVel[1] > 0)
+ {
m->angleVel[1] -= 0x400;
- if (m->angleVel[1] < 0) {
+ if (m->angleVel[1] < 0)
+ {
m->angleVel[1] = 0;
}
@@ -1033,7 +1257,8 @@ s32 act_twirl_land(struct MarioState *m) {
}
m->marioObj->header.gfx.angle[1] += m->twirlYaw;
- if (is_anim_at_end(m) && m->angleVel[1] == 0) {
+ if (is_anim_at_end(m) && m->angleVel[1] == 0)
+ {
m->faceAngle[1] += m->twirlYaw;
set_mario_action(m, ACT_IDLE, 0);
}
@@ -1041,17 +1266,21 @@ s32 act_twirl_land(struct MarioState *m) {
return FALSE;
}
-s32 act_ground_pound_land(struct MarioState *m) {
+s32 act_ground_pound_land(struct MarioState *m)
+{
m->actionState = 1;
- if (m->input & INPUT_UNKNOWN_10) {
+ if (m->input & INPUT_UNKNOWN_10)
+ {
return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);
}
- if (m->input & INPUT_OFF_FLOOR) {
+ if (m->input & INPUT_OFF_FLOOR)
+ {
return set_mario_action(m, ACT_FREEFALL, 0);
}
- if (m->input & INPUT_ABOVE_SLIDE) {
+ if (m->input & INPUT_ABOVE_SLIDE)
+ {
return set_mario_action(m, ACT_BUTT_SLIDE, 0);
}
@@ -1059,50 +1288,60 @@ s32 act_ground_pound_land(struct MarioState *m) {
return FALSE;
}
-s32 act_first_person(struct MarioState *m) {
+s32 act_first_person(struct MarioState *m)
+{
s32 sp1C = (m->input & (INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE | INPUT_UNKNOWN_10)) != 0;
- if (m->actionState == 0) {
+ if (m->actionState == 0)
+ {
lower_background_noise(2);
set_camera_mode(m->area->camera, CAMERA_MODE_C_UP, 0x10);
m->actionState = 1;
- } else if (!(m->input & INPUT_FIRST_PERSON) || sp1C) {
+ }
+ else if (!(m->input & INPUT_FIRST_PERSON) || sp1C)
+ {
raise_background_noise(2);
// Go back to the last camera mode
set_camera_mode(m->area->camera, -1, 1);
return set_mario_action(m, ACT_IDLE, 0);
}
-// if (m->floor->type == SURFACE_LOOK_UP_WARP
-// && save_file_get_total_star_count(gCurrSaveFileNum - 1, COURSE_MIN - 1, COURSE_MAX - 1) >= 10) {
-// s16 sp1A = m->statusForCamera->headRotation[0];
-// s16 sp18 = ((m->statusForCamera->headRotation[1] * 4) / 3) + m->faceAngle[1];
-// if (sp1A == -0x1800 && (sp18 < -0x6FFF || sp18 >= 0x7000)) {
-// level_trigger_warp(m, WARP_OP_UNKNOWN_01);
-// }
-// }
+ // if (m->floor->type == SURFACE_LOOK_UP_WARP
+ // && save_file_get_total_star_count(gCurrSaveFileNum - 1, COURSE_MIN - 1, COURSE_MAX - 1) >= 10) {
+ // s16 sp1A = m->statusForCamera->headRotation[0];
+ // s16 sp18 = ((m->statusForCamera->headRotation[1] * 4) / 3) + m->faceAngle[1];
+ // if (sp1A == -0x1800 && (sp18 < -0x6FFF || sp18 >= 0x7000)) {
+ // level_trigger_warp(m, WARP_OP_UNKNOWN_01);
+ // }
+ // }
stationary_ground_step(m);
set_mario_animation(m, MARIO_ANIM_FIRST_PERSON);
return FALSE;
}
-s32 check_common_stationary_cancels(struct MarioState *m) {
- if (m->pos[1] < m->waterLevel - 100) {
- if (m->action == ACT_SPAWN_SPIN_LANDING) {
+s32 check_common_stationary_cancels(struct MarioState *m)
+{
+ if (m->pos[1] < m->waterLevel - 100)
+ {
+ if (m->action == ACT_SPAWN_SPIN_LANDING)
+ {
load_level_init_text(0);
}
update_mario_sound_and_camera(m);
return set_water_plunge_action(m);
}
- if (m->input & INPUT_SQUISHED) {
+ if (m->input & INPUT_SQUISHED)
+ {
update_mario_sound_and_camera(m);
return drop_and_set_mario_action(m, ACT_SQUISHED, 0);
}
- if (m->action != ACT_UNKNOWN_0002020E) {
- if (m->health < 0x100) {
+ if (m->action != ACT_UNKNOWN_0002020E)
+ {
+ if (m->health < 0x100)
+ {
update_mario_sound_and_camera(m);
return drop_and_set_mario_action(m, ACT_STANDING_DEATH, 0);
}
@@ -1110,14 +1349,17 @@ s32 check_common_stationary_cancels(struct MarioState *m) {
return FALSE;
}
-s32 mario_execute_stationary_action(struct MarioState *m) {
+s32 mario_execute_stationary_action(struct MarioState *m)
+{
s32 cancel;
- if (check_common_stationary_cancels(m)) {
+ if (check_common_stationary_cancels(m))
+ {
return TRUE;
}
- if (mario_update_quicksand(m, 0.5f)) {
+ if (mario_update_quicksand(m, 0.5f))
+ {
return TRUE;
}
@@ -1162,7 +1404,8 @@ s32 mario_execute_stationary_action(struct MarioState *m) {
}
/* clang-format on */
- if (!cancel && (m->input & INPUT_IN_WATER)) {
+ if (!cancel && m->input & INPUT_IN_WATER)
+ {
m->particleFlags |= PARTICLE_IDLE_WATER_WAVE;
}
diff --git a/src/decomp/game/mario_actions_stationary.h b/src/decomp/game/mario_actions_stationary.h
index ccc1e00..e33ecc0 100644
--- a/src/decomp/game/mario_actions_stationary.h
+++ b/src/decomp/game/mario_actions_stationary.h
@@ -6,45 +6,85 @@
#include "../include/types.h"
s32 check_common_idle_cancels(struct MarioState *m);
+
s32 check_common_hold_idle_cancels(struct MarioState *m);
+
s32 act_idle(struct MarioState *m);
+
void play_anim_sound(struct MarioState *m, u32 actionState, s32 animFrame, u32 sound);
+
s32 act_start_sleeping(struct MarioState *m);
+
s32 act_sleeping(struct MarioState *m);
+
s32 act_waking_up(struct MarioState *m);
+
s32 act_shivering(struct MarioState *m);
+
s32 act_coughing(struct MarioState *m);
+
s32 act_standing_against_wall(struct MarioState *m);
+
s32 act_in_quicksand(struct MarioState *m);
+
s32 act_crouching(struct MarioState *m);
+
s32 act_panting(struct MarioState *m);
+
void stopping_step(struct MarioState *m, s32 animID, u32 action);
+
s32 act_braking_stop(struct MarioState *m);
+
s32 act_butt_slide_stop(struct MarioState *m);
+
s32 act_hold_butt_slide_stop(struct MarioState *m);
+
s32 act_slide_kick_slide_stop(struct MarioState *m);
+
s32 act_start_crouching(struct MarioState *m);
+
s32 act_stop_crouching(struct MarioState *m);
+
s32 act_start_crawling(struct MarioState *m);
+
s32 act_stop_crawling(struct MarioState *m);
+
s32 act_shockwave_bounce(struct MarioState *m);
+
s32 landing_step(struct MarioState *m, s32 arg1, u32 action);
+
s32 check_common_landing_cancels(struct MarioState *m, u32 action);
+
s32 act_jump_land_stop(struct MarioState *m);
+
s32 act_double_jump_land_stop(struct MarioState *m);
+
s32 act_side_flip_land_stop(struct MarioState *m);
+
s32 act_freefall_land_stop(struct MarioState *m);
+
s32 act_triple_jump_land_stop(struct MarioState *m);
+
s32 act_backflip_land_stop(struct MarioState *m);
+
s32 act_lava_boost_land(struct MarioState *m);
+
s32 act_long_jump_land_stop(struct MarioState *m);
+
s32 act_hold_jump_land_stop(struct MarioState *m);
+
s32 act_hold_freefall_land_stop(struct MarioState *m);
+
s32 act_air_throw_land(struct MarioState *m);
+
s32 act_twirl_land(struct MarioState *m);
+
s32 act_ground_pound_land(struct MarioState *m);
+
s32 act_first_person(struct MarioState *m);
+
s32 check_common_stationary_cancels(struct MarioState *m);
+
s32 mario_execute_stationary_action(struct MarioState *m);
#endif // MARIO_ACTIONS_STATIONARY
diff --git a/src/decomp/game/mario_actions_submerged.c b/src/decomp/game/mario_actions_submerged.c
index 742f452..424245a 100644
--- a/src/decomp/game/mario_actions_submerged.c
+++ b/src/decomp/game/mario_actions_submerged.c
@@ -34,18 +34,21 @@
//static s16 sWasAtSurface = FALSE;
//static s16 sSwimStrength = MIN_SWIM_STRENGTH;
-static s16 sWaterCurrentSpeeds[] = { 28, 12, 8, 4 };
+static s16 sWaterCurrentSpeeds[] = {28, 12, 8, 4};
//static s16 D_80339FD0;
//static s16 D_80339FD2;
//static f32 D_80339FD4;
-
-static void set_swimming_at_surface_particles(struct MarioState *m, u32 particleFlag) {
+
+static void set_swimming_at_surface_particles(struct MarioState *m, u32 particleFlag)
+{
s16 atSurface = m->pos[1] >= m->waterLevel - 130;
- if (atSurface) {
+ if (atSurface)
+ {
m->particleFlags |= particleFlag;
- if (atSurface ^ sWasAtSurface) {
+ if (atSurface ^ sWasAtSurface)
+ {
play_sound(SOUND_ACTION_UNKNOWN431, m->marioObj->header.gfx.cameraToObject);
}
}
@@ -53,33 +56,45 @@ static void set_swimming_at_surface_particles(struct MarioState *m, u32 particle
sWasAtSurface = atSurface;
}
-static s32 swimming_near_surface(struct MarioState *m) {
- if (m->flags & MARIO_METAL_CAP) {
+static s32 swimming_near_surface(struct MarioState *m)
+{
+ if (m->flags & MARIO_METAL_CAP)
+ {
return FALSE;
}
- return (m->waterLevel - 80) - m->pos[1] < 400.0f;
+ return m->waterLevel - 80 - m->pos[1] < 400.0f;
}
-static f32 get_buoyancy(struct MarioState *m) {
+static f32 get_buoyancy(struct MarioState *m)
+{
f32 buoyancy = 0.0f;
- if (m->flags & MARIO_METAL_CAP) {
- if (m->action & ACT_FLAG_INVULNERABLE) {
+ if (m->flags & MARIO_METAL_CAP)
+ {
+ if (m->action & ACT_FLAG_INVULNERABLE)
+ {
buoyancy = -2.0f;
- } else {
+ }
+ else
+ {
buoyancy = -18.0f;
}
- } else if (swimming_near_surface(m)) {
+ }
+ else if (swimming_near_surface(m))
+ {
buoyancy = 1.25f;
- } else if (!(m->action & ACT_FLAG_MOVING)) {
+ }
+ else if (!(m->action & ACT_FLAG_MOVING))
+ {
buoyancy = -2.0f;
}
return buoyancy;
}
-static u32 perform_water_full_step(struct MarioState *m, Vec3f nextPos) {
+static u32 perform_water_full_step(struct MarioState *m, Vec3f nextPos)
+{
struct SM64SurfaceCollisionData *wall;
struct SM64SurfaceCollisionData *ceil;
struct SM64SurfaceCollisionData *floor;
@@ -90,24 +105,31 @@ static u32 perform_water_full_step(struct MarioState *m, Vec3f nextPos) {
floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor);
ceilHeight = vec3f_find_ceil(nextPos, floorHeight, &ceil);
- if (floor == NULL) {
+ if (floor == NULL)
+ {
return WATER_STEP_CANCELLED;
}
- if (nextPos[1] >= floorHeight) {
- if (ceilHeight - nextPos[1] >= 160.0f) {
+ if (nextPos[1] >= floorHeight)
+ {
+ if (ceilHeight - nextPos[1] >= 160.0f)
+ {
vec3f_copy(m->pos, nextPos);
m->floor = floor;
m->floorHeight = floorHeight;
- if (wall != NULL) {
+ if (wall != NULL)
+ {
return WATER_STEP_HIT_WALL;
- } else {
+ }
+ else
+ {
return WATER_STEP_NONE;
}
}
- if (ceilHeight - floorHeight < 160.0f) {
+ if (ceilHeight - floorHeight < 160.0f)
+ {
return WATER_STEP_CANCELLED;
}
@@ -116,8 +138,11 @@ static u32 perform_water_full_step(struct MarioState *m, Vec3f nextPos) {
m->floor = floor;
m->floorHeight = floorHeight;
return WATER_STEP_HIT_CEILING;
- } else {
- if (ceilHeight - floorHeight < 160.0f) {
+ }
+ else
+ {
+ if (ceilHeight - floorHeight < 160.0f)
+ {
return WATER_STEP_CANCELLED;
}
@@ -128,11 +153,13 @@ static u32 perform_water_full_step(struct MarioState *m, Vec3f nextPos) {
}
}
-static void apply_water_current(struct MarioState *m, Vec3f step) {
+static void apply_water_current(struct MarioState *m, Vec3f step)
+{
s32 i;
f32 whirlpoolRadius = 2000.0f;
- if (m->floor->type == SURFACE_FLOWING_WATER) {
+ if (m->floor->type == SURFACE_FLOWING_WATER)
+ {
s16 currentAngle = m->floor->force << 8;
f32 currentSpeed = sWaterCurrentSpeeds[m->floor->force >> 8];
@@ -140,9 +167,11 @@ static void apply_water_current(struct MarioState *m, Vec3f step) {
step[2] += currentSpeed * coss(currentAngle);
}
- for (i = 0; i < 2; i++) {
+ for (i = 0; i < 2; i++)
+ {
struct Whirlpool *whirlpool = gCurrentArea->whirlpools[i];
- if (whirlpool != NULL) {
+ if (whirlpool != NULL)
+ {
f32 strength = 0.0f;
f32 dx = whirlpool->pos[0] - m->pos[0];
@@ -157,15 +186,19 @@ static void apply_water_current(struct MarioState *m, Vec3f step) {
yawToWhirlpool -= (s16)(0x2000 * 1000.0f / (distance + 1000.0f));
- if (whirlpool->strength >= 0) {
-// if (gCurrLevelNum == LEVEL_DDD && gCurrAreaIndex == 2) {
-// whirlpoolRadius = 4000.0f;
-// }
+ if (whirlpool->strength >= 0)
+ {
+ // if (gCurrLevelNum == LEVEL_DDD && gCurrAreaIndex == 2) {
+ // whirlpoolRadius = 4000.0f;
+ // }
- if (distance >= 26.0f && distance < whirlpoolRadius) {
+ if (distance >= 26.0f && distance < whirlpoolRadius)
+ {
strength = whirlpool->strength * (1.0f - distance / whirlpoolRadius);
}
- } else if (distance < 2000.0f) {
+ }
+ else if (distance < 2000.0f)
+ {
strength = whirlpool->strength * (1.0f - distance / 2000.0f);
}
@@ -176,7 +209,8 @@ static void apply_water_current(struct MarioState *m, Vec3f step) {
}
}
-static u32 perform_water_step(struct MarioState *m) {
+static u32 perform_water_step(struct MarioState *m)
+{
UNUSED u32 unused;
u32 stepResult;
Vec3f nextPos;
@@ -185,7 +219,8 @@ static u32 perform_water_step(struct MarioState *m) {
vec3f_copy(step, m->vel);
- if (m->action & ACT_FLAG_SWIMMING) {
+ if (m->action & ACT_FLAG_SWIMMING)
+ {
apply_water_current(m, step);
}
@@ -193,7 +228,8 @@ static u32 perform_water_step(struct MarioState *m) {
nextPos[1] = m->pos[1] + step[1];
nextPos[2] = m->pos[2] + step[2];
- if (nextPos[1] > m->waterLevel - 80) {
+ if (nextPos[1] > m->waterLevel - 80)
+ {
nextPos[1] = m->waterLevel - 80;
m->vel[1] = 0.0f;
}
@@ -206,24 +242,29 @@ static u32 perform_water_step(struct MarioState *m) {
return stepResult;
}
-static BAD_RETURN(u32) update_water_pitch(struct MarioState *m) {
+static BAD_RETURN (u32) update_water_pitch(struct MarioState *m)
+{
struct Object *marioObj = m->marioObj;
- if (marioObj->header.gfx.angle[0] > 0) {
+ if (marioObj->header.gfx.angle[0] > 0)
+ {
marioObj->header.gfx.pos[1] +=
- 60.0f * sins(marioObj->header.gfx.angle[0]) * sins(marioObj->header.gfx.angle[0]);
+ 60.0f * sins(marioObj->header.gfx.angle[0]) * sins(marioObj->header.gfx.angle[0]);
}
- if (marioObj->header.gfx.angle[0] < 0) {
+ if (marioObj->header.gfx.angle[0] < 0)
+ {
marioObj->header.gfx.angle[0] = marioObj->header.gfx.angle[0] * 6 / 10;
}
- if (marioObj->header.gfx.angle[0] > 0) {
+ if (marioObj->header.gfx.angle[0] > 0)
+ {
marioObj->header.gfx.angle[0] = marioObj->header.gfx.angle[0] * 10 / 8;
}
}
-static void stationary_slow_down(struct MarioState *m) {
+static void stationary_slow_down(struct MarioState *m)
+{
f32 buoyancy = get_buoyancy(m);
m->angleVel[0] = 0;
@@ -239,23 +280,28 @@ static void stationary_slow_down(struct MarioState *m) {
m->vel[2] = m->forwardVel * coss(m->faceAngle[0]) * coss(m->faceAngle[1]);
}
-static void update_swimming_speed(struct MarioState *m, f32 decelThreshold) {
+static void update_swimming_speed(struct MarioState *m, f32 decelThreshold)
+{
f32 buoyancy = get_buoyancy(m);
f32 maxSpeed = 28.0f;
- if (m->action & ACT_FLAG_STATIONARY) {
+ if (m->action & ACT_FLAG_STATIONARY)
+ {
m->forwardVel -= 2.0f;
}
- if (m->forwardVel < 0.0f) {
+ if (m->forwardVel < 0.0f)
+ {
m->forwardVel = 0.0f;
}
- if (m->forwardVel > maxSpeed) {
+ if (m->forwardVel > maxSpeed)
+ {
m->forwardVel = maxSpeed;
}
- if (m->forwardVel > decelThreshold) {
+ if (m->forwardVel > decelThreshold)
+ {
m->forwardVel -= 0.5f;
}
@@ -264,28 +310,42 @@ static void update_swimming_speed(struct MarioState *m, f32 decelThreshold) {
m->vel[2] = m->forwardVel * coss(m->faceAngle[0]) * coss(m->faceAngle[1]);
}
-static void update_swimming_yaw(struct MarioState *m) {
+static void update_swimming_yaw(struct MarioState *m)
+{
s16 targetYawVel = (s16)(10.0f * m->controller->stickX);
- if (targetYawVel > 0) {
- if (m->angleVel[1] < 0) {
+ if (targetYawVel > 0)
+ {
+ if (m->angleVel[1] < 0)
+ {
m->angleVel[1] += 0x40;
- if (m->angleVel[1] > 0x10) {
+ if (m->angleVel[1] > 0x10)
+ {
m->angleVel[1] = 0x10;
}
- } else {
+ }
+ else
+ {
m->angleVel[1] = approach_s32(m->angleVel[1], targetYawVel, 0x10, 0x20);
}
- } else if (targetYawVel < 0) {
- if (m->angleVel[1] > 0) {
+ }
+ else if (targetYawVel < 0)
+ {
+ if (m->angleVel[1] > 0)
+ {
m->angleVel[1] -= 0x40;
- if (m->angleVel[1] < -0x10) {
+ if (m->angleVel[1] < -0x10)
+ {
m->angleVel[1] = -0x10;
}
- } else {
+ }
+ else
+ {
m->angleVel[1] = approach_s32(m->angleVel[1], targetYawVel, 0x20, 0x10);
}
- } else {
+ }
+ else
+ {
m->angleVel[1] = approach_s32(m->angleVel[1], 0, 0x40, 0x40);
}
@@ -293,28 +353,38 @@ static void update_swimming_yaw(struct MarioState *m) {
m->faceAngle[2] = -m->angleVel[1] * 8;
}
-static void update_swimming_pitch(struct MarioState *m) {
+static void update_swimming_pitch(struct MarioState *m)
+{
s16 targetPitch = (s16)(252.0f * m->controller->stickY);
s16 pitchVel;
- if (m->faceAngle[0] < 0) {
+ if (m->faceAngle[0] < 0)
+ {
pitchVel = 0x100;
- } else {
+ }
+ else
+ {
pitchVel = 0x200;
}
- if (m->faceAngle[0] < targetPitch) {
- if ((m->faceAngle[0] += pitchVel) > targetPitch) {
+ if (m->faceAngle[0] < targetPitch)
+ {
+ if ((m->faceAngle[0] += pitchVel) > targetPitch)
+ {
m->faceAngle[0] = targetPitch;
}
- } else if (m->faceAngle[0] > targetPitch) {
- if ((m->faceAngle[0] -= pitchVel) < targetPitch) {
+ }
+ else if (m->faceAngle[0] > targetPitch)
+ {
+ if ((m->faceAngle[0] -= pitchVel) < targetPitch)
+ {
m->faceAngle[0] = targetPitch;
}
}
}
-static void common_idle_step(struct MarioState *m, s32 animation, s32 arg) {
+static void common_idle_step(struct MarioState *m, s32 animation, s32 arg)
+{
s16 *val = &m->marioBodyState->headAngle[0];
update_swimming_yaw(m);
@@ -323,37 +393,48 @@ static void common_idle_step(struct MarioState *m, s32 animation, s32 arg) {
perform_water_step(m);
update_water_pitch(m);
- if (m->faceAngle[0] > 0) {
+ if (m->faceAngle[0] > 0)
+ {
*val = approach_s32(*val, m->faceAngle[0] / 2, 0x80, 0x200);
- } else {
+ }
+ else
+ {
*val = approach_s32(*val, 0, 0x200, 0x200);
}
- if (arg == 0) {
+ if (arg == 0)
+ {
set_mario_animation(m, animation);
- } else {
+ }
+ else
+ {
set_mario_anim_with_accel(m, animation, arg);
}
set_swimming_at_surface_particles(m, PARTICLE_IDLE_WATER_WAVE);
}
-static s32 act_water_idle(struct MarioState *m) {
+static s32 act_water_idle(struct MarioState *m)
+{
u32 val = 0x10000;
- if (m->flags & MARIO_METAL_CAP) {
+ if (m->flags & MARIO_METAL_CAP)
+ {
return set_mario_action(m, ACT_METAL_WATER_FALLING, 1);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_WATER_PUNCH, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_mario_action(m, ACT_BREASTSTROKE, 0);
}
- if (m->faceAngle[0] < -0x1000) {
+ if (m->faceAngle[0] < -0x1000)
+ {
val = 0x30000;
}
@@ -361,20 +442,25 @@ static s32 act_water_idle(struct MarioState *m) {
return FALSE;
}
-static s32 act_hold_water_idle(struct MarioState *m) {
- if (m->flags & MARIO_METAL_CAP) {
+static s32 act_hold_water_idle(struct MarioState *m)
+{
+ if (m->flags & MARIO_METAL_CAP)
+ {
return set_mario_action(m, ACT_HOLD_METAL_WATER_FALLING, 0);
}
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_WATER_IDLE, 0);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_WATER_THROW, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_mario_action(m, ACT_HOLD_BREASTSTROKE, 0);
}
@@ -382,61 +468,76 @@ static s32 act_hold_water_idle(struct MarioState *m) {
return FALSE;
}
-static s32 act_water_action_end(struct MarioState *m) {
- if (m->flags & MARIO_METAL_CAP) {
+static s32 act_water_action_end(struct MarioState *m)
+{
+ if (m->flags & MARIO_METAL_CAP)
+ {
return set_mario_action(m, ACT_METAL_WATER_FALLING, 1);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_WATER_PUNCH, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_mario_action(m, ACT_BREASTSTROKE, 0);
}
common_idle_step(m, MARIO_ANIM_WATER_ACTION_END, 0);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_action(m, ACT_WATER_IDLE, 0);
}
return FALSE;
}
-static s32 act_hold_water_action_end(struct MarioState *m) {
- if (m->flags & MARIO_METAL_CAP) {
+static s32 act_hold_water_action_end(struct MarioState *m)
+{
+ if (m->flags & MARIO_METAL_CAP)
+ {
return set_mario_action(m, ACT_HOLD_METAL_WATER_FALLING, 0);
}
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_WATER_IDLE, 0);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_WATER_THROW, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_mario_action(m, ACT_HOLD_BREASTSTROKE, 0);
}
common_idle_step(
m, m->actionArg == 0 ? MARIO_ANIM_WATER_ACTION_END_WITH_OBJ : MARIO_ANIM_STOP_GRAB_OBJ_WATER,
0);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_action(m, ACT_HOLD_WATER_IDLE, 0);
}
return FALSE;
}
-static void reset_float_globals(struct MarioState *m) {
+static void reset_float_globals(struct MarioState *m)
+{
D_80339FD0 = 0;
D_80339FD2 = 0x800;
D_80339FD4 = m->faceAngle[0] / 256.0f + 20.0f;
}
-static void float_surface_gfx(struct MarioState *m) {
- if (D_80339FD2 != 0 && m->pos[1] > m->waterLevel - 85 && m->faceAngle[0] >= 0) {
- if ((D_80339FD0 += D_80339FD2) >= 0) {
+static void float_surface_gfx(struct MarioState *m)
+{
+ if (D_80339FD2 != 0 && m->pos[1] > m->waterLevel - 85 && m->faceAngle[0] >= 0)
+ {
+ if ((D_80339FD0 += D_80339FD2) >= 0)
+ {
m->marioObj->header.gfx.pos[1] += D_80339FD4 * sins(D_80339FD0);
return;
}
@@ -445,38 +546,49 @@ static void float_surface_gfx(struct MarioState *m) {
D_80339FD2 = 0;
}
-static void common_swimming_step(struct MarioState *m, s16 swimStrength) {
+static void common_swimming_step(struct MarioState *m, s16 swimStrength)
+{
s16 floorPitch;
- UNUSED struct Object *marioObj = m->marioObj;
+ UNUSED
+ struct Object *marioObj = m->marioObj;
update_swimming_yaw(m);
update_swimming_pitch(m);
update_swimming_speed(m, swimStrength / 10.0f);
- switch (perform_water_step(m)) {
+ switch (perform_water_step(m))
+ {
case WATER_STEP_HIT_FLOOR:
floorPitch = -find_floor_slope(m, -0x8000);
- if (m->faceAngle[0] < floorPitch) {
+ if (m->faceAngle[0] < floorPitch)
+ {
m->faceAngle[0] = floorPitch;
}
break;
case WATER_STEP_HIT_CEILING:
- if (m->faceAngle[0] > -0x3000) {
+ if (m->faceAngle[0] > -0x3000)
+ {
m->faceAngle[0] -= 0x100;
}
break;
case WATER_STEP_HIT_WALL:
- if (m->controller->stickY == 0.0f) {
- if (m->faceAngle[0] > 0.0f) {
+ if (m->controller->stickY == 0.0f)
+ {
+ if (m->faceAngle[0] > 0.0f)
+ {
m->faceAngle[0] += 0x200;
- if (m->faceAngle[0] > 0x3F00) {
+ if (m->faceAngle[0] > 0x3F00)
+ {
m->faceAngle[0] = 0x3F00;
}
- } else {
+ }
+ else
+ {
m->faceAngle[0] -= 0x200;
- if (m->faceAngle[0] < -0x3F00) {
+ if (m->faceAngle[0] < -0x3F00)
+ {
m->faceAngle[0] = -0x3F00;
}
}
@@ -491,25 +603,32 @@ static void common_swimming_step(struct MarioState *m, s16 swimStrength) {
set_swimming_at_surface_particles(m, PARTICLE_WAVE_TRAIL);
}
-static void play_swimming_noise(struct MarioState *m) {
+static void play_swimming_noise(struct MarioState *m)
+{
s16 animFrame = m->marioObj->header.gfx.animInfo.animFrame;
// This must be one line to match on -O2
if (animFrame == 0 || animFrame == 12) play_sound(SOUND_ACTION_UNKNOWN434, m->marioObj->header.gfx.cameraToObject);
}
-static s32 check_water_jump(struct MarioState *m) {
+static s32 check_water_jump(struct MarioState *m)
+{
s32 probe = (s32)(m->pos[1] + 1.5f);
- if (m->input & INPUT_A_PRESSED) {
- if (probe >= m->waterLevel - 80 && m->faceAngle[0] >= 0 && m->controller->stickY > 60.0f) {
+ if (m->input & INPUT_A_PRESSED)
+ {
+ if (probe >= m->waterLevel - 80 && m->faceAngle[0] >= 0 && m->controller->stickY > 60.0f)
+ {
vec3s_set(m->angleVel, 0, 0, 0);
m->vel[1] = 62.0f;
- if (m->heldObj == NULL) {
+ if (m->heldObj == NULL)
+ {
return set_mario_action(m, ACT_WATER_JUMP, 0);
- } else {
+ }
+ else
+ {
return set_mario_action(m, ACT_HOLD_WATER_JUMP, 0);
}
}
@@ -518,41 +637,52 @@ static s32 check_water_jump(struct MarioState *m) {
return FALSE;
}
-static s32 act_breaststroke(struct MarioState *m) {
- if (m->actionArg == 0) {
+static s32 act_breaststroke(struct MarioState *m)
+{
+ if (m->actionArg == 0)
+ {
sSwimStrength = MIN_SWIM_STRENGTH;
}
- if (m->flags & MARIO_METAL_CAP) {
+ if (m->flags & MARIO_METAL_CAP)
+ {
return set_mario_action(m, ACT_METAL_WATER_FALLING, 1);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_WATER_PUNCH, 0);
}
- if (++m->actionTimer == 14) {
+ if (++m->actionTimer == 14)
+ {
return set_mario_action(m, ACT_FLUTTER_KICK, 0);
}
- if (check_water_jump(m)) {
+ if (check_water_jump(m))
+ {
return TRUE;
}
- if (m->actionTimer < 6) {
+ if (m->actionTimer < 6)
+ {
m->forwardVel += 0.5f;
}
- if (m->actionTimer >= 9) {
+ if (m->actionTimer >= 9)
+ {
m->forwardVel += 1.5f;
}
- if (m->actionTimer >= 2) {
- if (m->actionTimer < 6 && (m->input & INPUT_A_PRESSED)) {
+ if (m->actionTimer >= 2)
+ {
+ if (m->actionTimer < 6 && m->input & INPUT_A_PRESSED)
+ {
m->actionState = 1;
}
- if (m->actionTimer == 9 && m->actionState == 1) {
+ if (m->actionTimer == 9 && m->actionState == 1)
+ {
set_anim_to_frame(m, 0);
m->actionState = 0;
m->actionTimer = 1;
@@ -560,17 +690,19 @@ static s32 act_breaststroke(struct MarioState *m) {
}
}
- if (m->actionTimer == 1) {
+ if (m->actionTimer == 1)
+ {
play_sound(sSwimStrength == MIN_SWIM_STRENGTH ? SOUND_ACTION_SWIM : SOUND_ACTION_SWIM_FAST,
m->marioObj->header.gfx.cameraToObject);
reset_float_globals(m);
}
-#ifdef VERSION_SH
- if (m->actionTimer < 6) {
+ #ifdef VERSION_SH
+ if (m->actionTimer < 6)
+ {
func_sh_8024CA04();
}
-#endif
+ #endif
set_mario_animation(m, MARIO_ANIM_SWIM_PART1);
common_swimming_step(m, sSwimStrength);
@@ -578,31 +710,39 @@ static s32 act_breaststroke(struct MarioState *m) {
return FALSE;
}
-static s32 act_swimming_end(struct MarioState *m) {
- if (m->flags & MARIO_METAL_CAP) {
+static s32 act_swimming_end(struct MarioState *m)
+{
+ if (m->flags & MARIO_METAL_CAP)
+ {
return set_mario_action(m, ACT_METAL_WATER_FALLING, 1);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_WATER_PUNCH, 0);
}
- if (m->actionTimer >= 15) {
+ if (m->actionTimer >= 15)
+ {
return set_mario_action(m, ACT_WATER_ACTION_END, 0);
}
- if (check_water_jump(m)) {
+ if (check_water_jump(m))
+ {
return TRUE;
}
- if ((m->input & INPUT_A_DOWN) && m->actionTimer >= 7) {
- if (m->actionTimer == 7 && sSwimStrength < 280) {
+ if (m->input & INPUT_A_DOWN && m->actionTimer >= 7)
+ {
+ if (m->actionTimer == 7 && sSwimStrength < 280)
+ {
sSwimStrength += 10;
}
return set_mario_action(m, ACT_BREASTSTROKE, 1);
}
- if (m->actionTimer >= 7) {
+ if (m->actionTimer >= 7)
+ {
sSwimStrength = MIN_SWIM_STRENGTH;
}
@@ -615,17 +755,22 @@ static s32 act_swimming_end(struct MarioState *m) {
return FALSE;
}
-static s32 act_flutter_kick(struct MarioState *m) {
- if (m->flags & MARIO_METAL_CAP) {
+static s32 act_flutter_kick(struct MarioState *m)
+{
+ if (m->flags & MARIO_METAL_CAP)
+ {
return set_mario_action(m, ACT_METAL_WATER_FALLING, 1);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_WATER_PUNCH, 0);
}
- if (!(m->input & INPUT_A_DOWN)) {
- if (m->actionTimer == 0 && sSwimStrength < 280) {
+ if (!(m->input & INPUT_A_DOWN))
+ {
+ if (m->actionTimer == 0 && sSwimStrength < 280)
+ {
sSwimStrength += 10;
}
return set_mario_action(m, ACT_SWIMMING_END, 0);
@@ -635,7 +780,8 @@ static s32 act_flutter_kick(struct MarioState *m) {
m->actionTimer = 1;
sSwimStrength = MIN_SWIM_STRENGTH;
- if (m->forwardVel < 14.0f) {
+ if (m->forwardVel < 14.0f)
+ {
play_swimming_noise(m);
set_mario_animation(m, MARIO_ANIM_FLUTTERKICK);
}
@@ -644,48 +790,60 @@ static s32 act_flutter_kick(struct MarioState *m) {
return FALSE;
}
-static s32 act_hold_breaststroke(struct MarioState *m) {
- if (m->flags & MARIO_METAL_CAP) {
+static s32 act_hold_breaststroke(struct MarioState *m)
+{
+ if (m->flags & MARIO_METAL_CAP)
+ {
return set_mario_action(m, ACT_HOLD_METAL_WATER_FALLING, 0);
}
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_WATER_IDLE, 0);
}
- if (++m->actionTimer == 17) {
+ if (++m->actionTimer == 17)
+ {
return set_mario_action(m, ACT_HOLD_FLUTTER_KICK, 0);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_WATER_THROW, 0);
}
- if (check_water_jump(m)) {
+ if (check_water_jump(m))
+ {
return TRUE;
}
- if (m->actionTimer < 6) {
+ if (m->actionTimer < 6)
+ {
m->forwardVel += 0.5f;
}
- if (m->actionTimer >= 9) {
+ if (m->actionTimer >= 9)
+ {
m->forwardVel += 1.5f;
}
- if (m->actionTimer >= 2) {
- if (m->actionTimer < 6 && (m->input & INPUT_A_PRESSED)) {
+ if (m->actionTimer >= 2)
+ {
+ if (m->actionTimer < 6 && m->input & INPUT_A_PRESSED)
+ {
m->actionState = 1;
}
- if (m->actionTimer == 9 && m->actionState == 1) {
+ if (m->actionTimer == 9 && m->actionState == 1)
+ {
set_anim_to_frame(m, 0);
m->actionState = 0;
m->actionTimer = 1;
}
}
- if (m->actionTimer == 1) {
+ if (m->actionTimer == 1)
+ {
play_sound(SOUND_ACTION_SWIM, m->marioObj->header.gfx.cameraToObject);
reset_float_globals(m);
}
@@ -695,28 +853,35 @@ static s32 act_hold_breaststroke(struct MarioState *m) {
return FALSE;
}
-static s32 act_hold_swimming_end(struct MarioState *m) {
- if (m->flags & MARIO_METAL_CAP) {
+static s32 act_hold_swimming_end(struct MarioState *m)
+{
+ if (m->flags & MARIO_METAL_CAP)
+ {
return set_mario_action(m, ACT_HOLD_METAL_WATER_FALLING, 0);
}
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_WATER_IDLE, 0);
}
- if (m->actionTimer >= 15) {
+ if (m->actionTimer >= 15)
+ {
return set_mario_action(m, ACT_HOLD_WATER_ACTION_END, 0);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_WATER_THROW, 0);
}
- if (check_water_jump(m)) {
+ if (check_water_jump(m))
+ {
return TRUE;
}
- if ((m->input & INPUT_A_DOWN) && m->actionTimer >= 7) {
+ if (m->input & INPUT_A_DOWN && m->actionTimer >= 7)
+ {
return set_mario_action(m, ACT_HOLD_BREASTSTROKE, 0);
}
@@ -728,25 +893,31 @@ static s32 act_hold_swimming_end(struct MarioState *m) {
return FALSE;
}
-static s32 act_hold_flutter_kick(struct MarioState *m) {
- if (m->flags & MARIO_METAL_CAP) {
+static s32 act_hold_flutter_kick(struct MarioState *m)
+{
+ if (m->flags & MARIO_METAL_CAP)
+ {
return set_mario_action(m, ACT_HOLD_METAL_WATER_FALLING, 0);
}
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_WATER_IDLE, 0);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_WATER_THROW, 0);
}
- if (!(m->input & INPUT_A_DOWN)) {
+ if (!(m->input & INPUT_A_DOWN))
+ {
return set_mario_action(m, ACT_HOLD_SWIMMING_END, 0);
}
m->forwardVel = approach_f32(m->forwardVel, 12.0f, 0.1f, 0.15f);
- if (m->forwardVel < 14.0f) {
+ if (m->forwardVel < 14.0f)
+ {
play_swimming_noise(m);
set_mario_animation(m, MARIO_ANIM_FLUTTERKICK_WITH_OBJ);
}
@@ -754,16 +925,20 @@ static s32 act_hold_flutter_kick(struct MarioState *m) {
return FALSE;
}
-static s32 act_water_shell_swimming(struct MarioState *m) {
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+static s32 act_water_shell_swimming(struct MarioState *m)
+{
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_WATER_IDLE, 0);
}
- if (m->input & INPUT_B_PRESSED) {
+ if (m->input & INPUT_B_PRESSED)
+ {
return set_mario_action(m, ACT_WATER_THROW, 0);
}
- if (m->actionTimer++ == 240) {
+ if (m->actionTimer++ == 240)
+ {
m->heldObj->oInteractStatus = INT_STATUS_STOP_RIDING;
m->heldObj = NULL;
stop_shell_music();
@@ -779,17 +954,20 @@ static s32 act_water_shell_swimming(struct MarioState *m) {
return FALSE;
}
-static s32 check_water_grab(struct MarioState *m) {
+static s32 check_water_grab(struct MarioState *m)
+{
//! Heave hos have the grabbable interaction type but are not normally
// grabbable. Since water grabbing doesn't check the appropriate input flag,
// you can use water grab to pick up heave ho.
- if (m->marioObj->collidedObjInteractTypes & INTERACT_GRABBABLE) {
+ if (m->marioObj->collidedObjInteractTypes & INTERACT_GRABBABLE)
+ {
struct Object *object = mario_get_collided_object(m, INTERACT_GRABBABLE);
f32 dx = object->oPosX - m->pos[0];
f32 dz = object->oPosZ - m->pos[2];
s16 dAngleToObject = atan2s(dz, dx) - m->faceAngle[1];
- if (dAngleToObject >= -0x2AAA && dAngleToObject <= 0x2AAA) {
+ if (dAngleToObject >= -0x2AAA && dAngleToObject <= 0x2AAA)
+ {
m->usedObj = object;
mario_grab_used_object(m);
m->marioBodyState->grabPos = GRAB_POS_LIGHT_OBJ;
@@ -800,7 +978,8 @@ static s32 check_water_grab(struct MarioState *m) {
return FALSE;
}
-static s32 act_water_throw(struct MarioState *m) {
+static s32 act_water_throw(struct MarioState *m)
+{
update_swimming_yaw(m);
update_swimming_pitch(m);
update_swimming_speed(m, MIN_SWIM_SPEED);
@@ -812,22 +991,26 @@ static s32 act_water_throw(struct MarioState *m) {
m->marioBodyState->headAngle[0] = approach_s32(m->marioBodyState->headAngle[0], 0, 0x200, 0x200);
- if (m->actionTimer++ == 5) {
+ if (m->actionTimer++ == 5)
+ {
mario_throw_held_object(m);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
queue_rumble_data(3, 50);
-#endif
+ #endif
}
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_action(m, ACT_WATER_IDLE, 0);
}
return FALSE;
}
-static s32 act_water_punch(struct MarioState *m) {
- if (m->forwardVel < 7.0f) {
+static s32 act_water_punch(struct MarioState *m)
+{
+ if (m->forwardVel < 7.0f)
+ {
m->forwardVel += 1.0f;
}
@@ -841,30 +1024,34 @@ static s32 act_water_punch(struct MarioState *m) {
play_sound_if_no_flag(m, SOUND_ACTION_SWIM, MARIO_ACTION_SOUND_PLAYED);
- switch (m->actionState) {
+ switch (m->actionState)
+ {
case 0:
set_mario_animation(m, MARIO_ANIM_WATER_GRAB_OBJ_PART1);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
m->actionState = check_water_grab(m) + 1;
}
break;
case 1:
set_mario_animation(m, MARIO_ANIM_WATER_GRAB_OBJ_PART2);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
set_mario_action(m, ACT_WATER_ACTION_END, 0);
}
break;
case 2:
set_mario_animation(m, MARIO_ANIM_WATER_PICK_UP_OBJ);
- if (is_anim_at_end(m)) {
-// if (m->heldObj->behavior == segmented_to_virtual(bhvKoopaShellUnderwater)) {
-// play_shell_music();
-// set_mario_action(m, ACT_WATER_SHELL_SWIMMING, 0);
-// } else {
- set_mario_action(m, ACT_HOLD_WATER_ACTION_END, 1);
-// }
+ if (is_anim_at_end(m))
+ {
+ // if (m->heldObj->behavior == segmented_to_virtual(bhvKoopaShellUnderwater)) {
+ // play_shell_music();
+ // set_mario_action(m, ACT_WATER_SHELL_SWIMMING, 0);
+ // } else {
+ set_mario_action(m, ACT_HOLD_WATER_ACTION_END, 1);
+ // }
}
break;
}
@@ -872,15 +1059,18 @@ static s32 act_water_punch(struct MarioState *m) {
return FALSE;
}
-static void common_water_knockback_step(struct MarioState *m, s32 animation, u32 endAction, s32 arg3) {
+static void common_water_knockback_step(struct MarioState *m, s32 animation, u32 endAction, s32 arg3)
+{
stationary_slow_down(m);
perform_water_step(m);
set_mario_animation(m, animation);
m->marioBodyState->headAngle[0] = 0;
- if (is_anim_at_end(m)) {
- if (arg3 > 0) {
+ if (is_anim_at_end(m))
+ {
+ if (arg3 > 0)
+ {
m->invincTimer = 30;
}
@@ -888,27 +1078,32 @@ static void common_water_knockback_step(struct MarioState *m, s32 animation, u32
}
}
-static s32 act_backward_water_kb(struct MarioState *m) {
+static s32 act_backward_water_kb(struct MarioState *m)
+{
common_water_knockback_step(m, MARIO_ANIM_BACKWARDS_WATER_KB, ACT_WATER_IDLE, m->actionArg);
return FALSE;
}
-static s32 act_forward_water_kb(struct MarioState *m) {
+static s32 act_forward_water_kb(struct MarioState *m)
+{
common_water_knockback_step(m, MARIO_ANIM_WATER_FORWARD_KB, ACT_WATER_IDLE, m->actionArg);
return FALSE;
}
-static s32 act_water_shocked(struct MarioState *m) {
+static s32 act_water_shocked(struct MarioState *m)
+{
play_sound_if_no_flag(m, SOUND_MARIO_WAAAOOOW, MARIO_ACTION_SOUND_PLAYED);
play_sound(SOUND_MOVING_SHOCKED, m->marioObj->header.gfx.cameraToObject);
set_camera_shake_from_hit(SHAKE_SHOCK);
- if (set_mario_animation(m, MARIO_ANIM_SHOCKED) == 0) {
+ if (set_mario_animation(m, MARIO_ANIM_SHOCKED) == 0)
+ {
m->actionTimer++;
m->flags |= MARIO_METAL_SHOCK;
}
- if (m->actionTimer >= 6) {
+ if (m->actionTimer >= 6)
+ {
m->invincTimer = 30;
set_mario_action(m, m->health < 0x100 ? ACT_WATER_DEATH : ACT_WATER_IDLE, 0);
}
@@ -919,12 +1114,15 @@ static s32 act_water_shocked(struct MarioState *m) {
return FALSE;
}
-static s32 act_drowning(struct MarioState *m) {
- switch (m->actionState) {
+static s32 act_drowning(struct MarioState *m)
+{
+ switch (m->actionState)
+ {
case 0:
set_mario_animation(m, MARIO_ANIM_DROWNING_PART1);
m->marioBodyState->eyeState = MARIO_EYES_HALF_CLOSED;
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
m->actionState = 1;
}
break;
@@ -932,7 +1130,8 @@ static s32 act_drowning(struct MarioState *m) {
case 1:
set_mario_animation(m, MARIO_ANIM_DROWNING_PART2);
m->marioBodyState->eyeState = MARIO_EYES_DEAD;
- if (m->marioObj->header.gfx.animInfo.animFrame == 30) {
+ if (m->marioObj->header.gfx.animInfo.animFrame == 30)
+ {
level_trigger_warp(m, WARP_OP_DEATH);
}
break;
@@ -945,34 +1144,43 @@ static s32 act_drowning(struct MarioState *m) {
return FALSE;
}
-static s32 act_water_death(struct MarioState *m) {
+static s32 act_water_death(struct MarioState *m)
+{
stationary_slow_down(m);
perform_water_step(m);
m->marioBodyState->eyeState = MARIO_EYES_DEAD;
set_mario_animation(m, MARIO_ANIM_WATER_DYING);
- if (set_mario_animation(m, MARIO_ANIM_WATER_DYING) == 35) {
+ if (set_mario_animation(m, MARIO_ANIM_WATER_DYING) == 35)
+ {
level_trigger_warp(m, WARP_OP_DEATH);
}
return FALSE;
}
-static s32 act_water_plunge(struct MarioState *m) {
+static s32 act_water_plunge(struct MarioState *m)
+{
u32 stepResult;
s32 stateFlags = m->heldObj != NULL;
f32 endVSpeed;
- if (swimming_near_surface(m)) {
+ if (swimming_near_surface(m))
+ {
endVSpeed = 0.0f;
- } else {
+ }
+ else
+ {
endVSpeed = -5.0f;
}
- if (m->flags & MARIO_METAL_CAP) {
+ if (m->flags & MARIO_METAL_CAP)
+ {
stateFlags |= 4;
- } else if ((m->prevAction & ACT_FLAG_DIVING) || (m->input & INPUT_A_DOWN)) {
+ }
+ else if (m->prevAction & ACT_FLAG_DIVING || m->input & INPUT_A_DOWN)
+ {
stateFlags |= 2;
}
@@ -982,23 +1190,28 @@ static s32 act_water_plunge(struct MarioState *m) {
stepResult = perform_water_step(m);
- if (m->actionState == 0) {
+ if (m->actionState == 0)
+ {
play_sound(SOUND_ACTION_UNKNOWN430, m->marioObj->header.gfx.cameraToObject);
- if (m->peakHeight - m->pos[1] > 1150.0f) {
+ if (m->peakHeight - m->pos[1] > 1150.0f)
+ {
play_sound(SOUND_MARIO_HAHA_2, m->marioObj->header.gfx.cameraToObject);
}
m->particleFlags |= PARTICLE_WATER_SPLASH;
m->actionState = 1;
-#ifdef VERSION_SH
- if (m->prevAction & ACT_FLAG_AIR) {
+ #ifdef VERSION_SH
+ if (m->prevAction & ACT_FLAG_AIR)
+ {
queue_rumble_data(5, 80);
}
-#endif
+ #endif
}
- if (stepResult == WATER_STEP_HIT_FLOOR || m->vel[1] >= endVSpeed || m->actionTimer > 20) {
- switch (stateFlags) {
+ if (stepResult == WATER_STEP_HIT_FLOOR || m->vel[1] >= endVSpeed || m->actionTimer > 20)
+ {
+ switch (stateFlags)
+ {
case 0:
set_mario_action(m, ACT_WATER_ACTION_END, 0);
break;
@@ -1021,7 +1234,8 @@ static s32 act_water_plunge(struct MarioState *m) {
D_80339FD2 = 0;
}
- switch (stateFlags) {
+ switch (stateFlags)
+ {
case 0:
set_mario_animation(m, MARIO_ANIM_WATER_ACTION_END);
break;
@@ -1046,7 +1260,8 @@ static s32 act_water_plunge(struct MarioState *m) {
return FALSE;
}
-static s32 act_caught_in_whirlpool(struct MarioState *m) {
+static s32 act_caught_in_whirlpool(struct MarioState *m)
+{
f32 sinAngleChange;
f32 cosAngleChange;
f32 newDistance;
@@ -1059,20 +1274,27 @@ static s32 act_caught_in_whirlpool(struct MarioState *m) {
f32 dz = m->pos[2] - whirlpool->oPosZ;
f32 distance = sqrtf(dx * dx + dz * dz);
- if ((marioObj->oMarioWhirlpoolPosY += m->vel[1]) < 0.0f) {
+ if ((marioObj->oMarioWhirlpoolPosY += m->vel[1]) < 0.0f)
+ {
marioObj->oMarioWhirlpoolPosY = 0.0f;
- if (distance < 16.1f && m->actionTimer++ == 16) {
+ if (distance < 16.1f && m->actionTimer++ == 16)
+ {
level_trigger_warp(m, WARP_OP_DEATH);
}
}
- if (distance <= 28.0f) {
+ if (distance <= 28.0f)
+ {
newDistance = 16.0f;
angleChange = 0x1800;
- } else if (distance < 256.0f) {
+ }
+ else if (distance < 256.0f)
+ {
newDistance = distance - (12.0f - distance / 32.0f);
angleChange = (s16)(0x1C00 - distance * 20.0f);
- } else {
+ }
+ else
+ {
newDistance = distance - 4.0f;
angleChange = 0x800;
}
@@ -1082,10 +1304,13 @@ static s32 act_caught_in_whirlpool(struct MarioState *m) {
sinAngleChange = sins(angleChange);
cosAngleChange = coss(angleChange);
- if (distance < 1.0f) {
+ if (distance < 1.0f)
+ {
dx = newDistance * sins(m->faceAngle[1]);
dz = newDistance * coss(m->faceAngle[1]);
- } else {
+ }
+ else
+ {
dx *= newDistance / distance;
dz *= newDistance / distance;
}
@@ -1099,15 +1324,17 @@ static s32 act_caught_in_whirlpool(struct MarioState *m) {
set_mario_animation(m, MARIO_ANIM_GENERAL_FALL);
vec3f_copy(m->marioObj->header.gfx.pos, m->pos);
vec3s_set(m->marioObj->header.gfx.angle, 0, m->faceAngle[1], 0);
-#ifdef VERSION_SH
+ #ifdef VERSION_SH
reset_rumble_timers();
-#endif
+ #endif
return FALSE;
}
-static void play_metal_water_jumping_sound(struct MarioState *m, u32 landing) {
- if (!(m->flags & MARIO_ACTION_SOUND_PLAYED)) {
+static void play_metal_water_jumping_sound(struct MarioState *m, u32 landing)
+{
+ if (!(m->flags & MARIO_ACTION_SOUND_PLAYED))
+ {
m->particleFlags |= PARTICLE_MIST_CIRCLE;
}
@@ -1115,30 +1342,39 @@ static void play_metal_water_jumping_sound(struct MarioState *m, u32 landing) {
MARIO_ACTION_SOUND_PLAYED);
}
-static void play_metal_water_walking_sound(struct MarioState *m) {
- if (is_anim_past_frame(m, 10) || is_anim_past_frame(m, 49)) {
+static void play_metal_water_walking_sound(struct MarioState *m)
+{
+ if (is_anim_past_frame(m, 10) || is_anim_past_frame(m, 49))
+ {
play_sound(SOUND_ACTION_METAL_STEP_WATER, m->marioObj->header.gfx.cameraToObject);
m->particleFlags |= PARTICLE_DUST;
}
}
-static void update_metal_water_walking_speed(struct MarioState *m) {
+static void update_metal_water_walking_speed(struct MarioState *m)
+{
f32 val = m->intendedMag / 1.5f;
- if (m->forwardVel <= 0.0f) {
+ if (m->forwardVel <= 0.0f)
+ {
m->forwardVel += 1.1f;
- } else if (m->forwardVel <= val) {
+ }
+ else if (m->forwardVel <= val)
+ {
m->forwardVel += 1.1f - m->forwardVel / 43.0f;
- } else if (m->floor->normal.y >= 0.95f) {
+ }
+ else if (m->floor->normal.y >= 0.95f)
+ {
m->forwardVel -= 1.0f;
}
- if (m->forwardVel > 32.0f) {
+ if (m->forwardVel > 32.0f)
+ {
m->forwardVel = 32.0f;
}
m->faceAngle[1] =
- m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x800, 0x800);
+ m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x800, 0x800);
m->slideVelX = m->forwardVel * sins(m->faceAngle[1]);
m->slideVelZ = m->forwardVel * coss(m->faceAngle[1]);
@@ -1148,27 +1384,34 @@ static void update_metal_water_walking_speed(struct MarioState *m) {
m->vel[2] = m->slideVelZ;
}
-static s32 update_metal_water_jump_speed(struct MarioState *m) {
+static s32 update_metal_water_jump_speed(struct MarioState *m)
+{
UNUSED f32 nextY = m->pos[1] + m->vel[1];
f32 waterSurface = m->waterLevel - 100;
- if (m->vel[1] > 0.0f && m->pos[1] > waterSurface) {
+ if (m->vel[1] > 0.0f && m->pos[1] > waterSurface)
+ {
return TRUE;
}
- if (m->input & INPUT_NONZERO_ANALOG) {
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
s16 intendedDYaw = m->intendedYaw - m->faceAngle[1];
m->forwardVel += 0.8f * coss(intendedDYaw);
m->faceAngle[1] += 0x200 * sins(intendedDYaw);
- } else {
+ }
+ else
+ {
m->forwardVel = approach_f32(m->forwardVel, 0.0f, 0.25f, 0.25f);
}
- if (m->forwardVel > 16.0f) {
+ if (m->forwardVel > 16.0f)
+ {
m->forwardVel -= 1.0f;
}
- if (m->forwardVel < 0.0f) {
+ if (m->forwardVel < 0.0f)
+ {
m->forwardVel += 2.0f;
}
@@ -1177,20 +1420,25 @@ static s32 update_metal_water_jump_speed(struct MarioState *m) {
return FALSE;
}
-static s32 act_metal_water_standing(struct MarioState *m) {
- if (!(m->flags & MARIO_METAL_CAP)) {
+static s32 act_metal_water_standing(struct MarioState *m)
+{
+ if (!(m->flags & MARIO_METAL_CAP))
+ {
return set_mario_action(m, ACT_WATER_IDLE, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_mario_action(m, ACT_METAL_WATER_JUMP, 0);
}
- if (m->input & INPUT_NONZERO_ANALOG) {
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
return set_mario_action(m, ACT_METAL_WATER_WALKING, 0);
}
- switch (m->actionState) {
+ switch (m->actionState)
+ {
case 0:
set_mario_animation(m, MARIO_ANIM_IDLE_HEAD_LEFT);
break;
@@ -1202,32 +1450,39 @@ static s32 act_metal_water_standing(struct MarioState *m) {
break;
}
- if (is_anim_at_end(m) && ++m->actionState == 3) {
+ if (is_anim_at_end(m) && ++m->actionState == 3)
+ {
m->actionState = 0;
}
stop_and_set_height_to_floor(m);
- if (m->pos[1] >= m->waterLevel - 150) {
+ if (m->pos[1] >= m->waterLevel - 150)
+ {
m->particleFlags |= PARTICLE_IDLE_WATER_WAVE;
}
return FALSE;
}
-static s32 act_hold_metal_water_standing(struct MarioState *m) {
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+static s32 act_hold_metal_water_standing(struct MarioState *m)
+{
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_METAL_WATER_STANDING, 0);
}
- if (!(m->flags & MARIO_METAL_CAP)) {
+ if (!(m->flags & MARIO_METAL_CAP))
+ {
return set_mario_action(m, ACT_HOLD_WATER_IDLE, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_mario_action(m, ACT_HOLD_METAL_WATER_JUMP, 0);
}
- if (m->input & INPUT_NONZERO_ANALOG) {
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
return set_mario_action(m, ACT_HOLD_METAL_WATER_WALKING, 0);
}
@@ -1236,26 +1491,32 @@ static s32 act_hold_metal_water_standing(struct MarioState *m) {
return FALSE;
}
-static s32 act_metal_water_walking(struct MarioState *m) {
+static s32 act_metal_water_walking(struct MarioState *m)
+{
s32 val04;
- if (!(m->flags & MARIO_METAL_CAP)) {
+ if (!(m->flags & MARIO_METAL_CAP))
+ {
return set_mario_action(m, ACT_WATER_IDLE, 0);
}
- if (m->input & INPUT_FIRST_PERSON) {
+ if (m->input & INPUT_FIRST_PERSON)
+ {
return set_mario_action(m, ACT_METAL_WATER_STANDING, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_mario_action(m, ACT_METAL_WATER_JUMP, 0);
}
- if (m->input & INPUT_UNKNOWN_5) {
+ if (m->input & INPUT_UNKNOWN_5)
+ {
return set_mario_action(m, ACT_METAL_WATER_STANDING, 0);
}
- if ((val04 = (s32)(m->forwardVel / 4.0f * 0x10000)) < 0x1000) {
+ if ((val04 = (s32)(m->forwardVel / 4.0f * 0x10000)) < 0x1000)
+ {
val04 = 0x1000;
}
@@ -1263,7 +1524,8 @@ static s32 act_metal_water_walking(struct MarioState *m) {
play_metal_water_walking_sound(m);
update_metal_water_walking_speed(m);
- switch (perform_ground_step(m)) {
+ switch (perform_ground_step(m))
+ {
case GROUND_STEP_LEFT_GROUND:
set_mario_action(m, ACT_METAL_WATER_FALLING, 1);
break;
@@ -1276,28 +1538,34 @@ static s32 act_metal_water_walking(struct MarioState *m) {
return FALSE;
}
-static s32 act_hold_metal_water_walking(struct MarioState *m) {
+static s32 act_hold_metal_water_walking(struct MarioState *m)
+{
s32 val04;
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_METAL_WATER_WALKING, 0);
}
- if (!(m->flags & MARIO_METAL_CAP)) {
+ if (!(m->flags & MARIO_METAL_CAP))
+ {
return set_mario_action(m, ACT_HOLD_WATER_IDLE, 0);
}
- if (m->input & INPUT_A_PRESSED) {
+ if (m->input & INPUT_A_PRESSED)
+ {
return set_mario_action(m, ACT_HOLD_METAL_WATER_JUMP, 0);
}
- if (m->input & INPUT_UNKNOWN_5) {
+ if (m->input & INPUT_UNKNOWN_5)
+ {
return set_mario_action(m, ACT_HOLD_METAL_WATER_STANDING, 0);
}
m->intendedMag *= 0.4f;
- if ((val04 = (s32)(m->forwardVel / 2.0f * 0x10000)) < 0x1000) {
+ if ((val04 = (s32)(m->forwardVel / 2.0f * 0x10000)) < 0x1000)
+ {
val04 = 0x1000;
}
@@ -1305,7 +1573,8 @@ static s32 act_hold_metal_water_walking(struct MarioState *m) {
play_metal_water_walking_sound(m);
update_metal_water_walking_speed(m);
- switch (perform_ground_step(m)) {
+ switch (perform_ground_step(m))
+ {
case GROUND_STEP_LEFT_GROUND:
set_mario_action(m, ACT_HOLD_METAL_WATER_FALLING, 1);
break;
@@ -1318,19 +1587,23 @@ static s32 act_hold_metal_water_walking(struct MarioState *m) {
return FALSE;
}
-static s32 act_metal_water_jump(struct MarioState *m) {
- if (!(m->flags & MARIO_METAL_CAP)) {
+static s32 act_metal_water_jump(struct MarioState *m)
+{
+ if (!(m->flags & MARIO_METAL_CAP))
+ {
return set_mario_action(m, ACT_WATER_IDLE, 0);
}
- if (update_metal_water_jump_speed(m)) {
+ if (update_metal_water_jump_speed(m))
+ {
return set_mario_action(m, ACT_WATER_JUMP, 1);
}
play_metal_water_jumping_sound(m, FALSE);
set_mario_animation(m, MARIO_ANIM_SINGLE_JUMP);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_LANDED:
set_mario_action(m, ACT_METAL_WATER_JUMP_LAND, 0);
break;
@@ -1343,23 +1616,28 @@ static s32 act_metal_water_jump(struct MarioState *m) {
return FALSE;
}
-static s32 act_hold_metal_water_jump(struct MarioState *m) {
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+static s32 act_hold_metal_water_jump(struct MarioState *m)
+{
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_METAL_WATER_FALLING, 0);
}
- if (!(m->flags & MARIO_METAL_CAP)) {
+ if (!(m->flags & MARIO_METAL_CAP))
+ {
return set_mario_action(m, ACT_HOLD_WATER_IDLE, 0);
}
- if (update_metal_water_jump_speed(m)) {
+ if (update_metal_water_jump_speed(m))
+ {
return set_mario_action(m, ACT_HOLD_WATER_JUMP, 1);
}
play_metal_water_jumping_sound(m, FALSE);
set_mario_animation(m, MARIO_ANIM_JUMP_WITH_LIGHT_OBJ);
- switch (perform_air_step(m, 0)) {
+ switch (perform_air_step(m, 0))
+ {
case AIR_STEP_LANDED:
set_mario_action(m, ACT_HOLD_METAL_WATER_JUMP_LAND, 0);
break;
@@ -1372,150 +1650,183 @@ static s32 act_hold_metal_water_jump(struct MarioState *m) {
return FALSE;
}
-static s32 act_metal_water_falling(struct MarioState *m) {
- if (!(m->flags & MARIO_METAL_CAP)) {
+static s32 act_metal_water_falling(struct MarioState *m)
+{
+ if (!(m->flags & MARIO_METAL_CAP))
+ {
return set_mario_action(m, ACT_WATER_IDLE, 0);
}
- if (m->input & INPUT_NONZERO_ANALOG) {
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
m->faceAngle[1] += 0x400 * sins(m->intendedYaw - m->faceAngle[1]);
}
set_mario_animation(m, m->actionArg == 0 ? MARIO_ANIM_GENERAL_FALL : MARIO_ANIM_FALL_FROM_WATER);
stationary_slow_down(m);
- if (perform_water_step(m) & WATER_STEP_HIT_FLOOR) { // hit floor or cancelled
+ if (perform_water_step(m) & WATER_STEP_HIT_FLOOR)
+ { // hit floor or cancelled
set_mario_action(m, ACT_METAL_WATER_FALL_LAND, 0);
}
return FALSE;
}
-static s32 act_hold_metal_water_falling(struct MarioState *m) {
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+static s32 act_hold_metal_water_falling(struct MarioState *m)
+{
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_METAL_WATER_FALLING, 0);
}
- if (!(m->flags & MARIO_METAL_CAP)) {
+ if (!(m->flags & MARIO_METAL_CAP))
+ {
return set_mario_action(m, ACT_HOLD_WATER_IDLE, 0);
}
- if (m->input & INPUT_NONZERO_ANALOG) {
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
m->faceAngle[1] += 0x400 * sins(m->intendedYaw - m->faceAngle[1]);
}
set_mario_animation(m, MARIO_ANIM_FALL_WITH_LIGHT_OBJ);
stationary_slow_down(m);
- if (perform_water_step(m) & WATER_STEP_HIT_FLOOR) { // hit floor or cancelled
+ if (perform_water_step(m) & WATER_STEP_HIT_FLOOR)
+ { // hit floor or cancelled
set_mario_action(m, ACT_HOLD_METAL_WATER_FALL_LAND, 0);
}
return FALSE;
}
-static s32 act_metal_water_jump_land(struct MarioState *m) {
+static s32 act_metal_water_jump_land(struct MarioState *m)
+{
play_metal_water_jumping_sound(m, TRUE);
- if (!(m->flags & MARIO_METAL_CAP)) {
+ if (!(m->flags & MARIO_METAL_CAP))
+ {
return set_mario_action(m, ACT_WATER_IDLE, 0);
}
- if (m->input & INPUT_NONZERO_ANALOG) {
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
return set_mario_action(m, ACT_METAL_WATER_WALKING, 0);
}
stop_and_set_height_to_floor(m);
set_mario_animation(m, MARIO_ANIM_LAND_FROM_SINGLE_JUMP);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
return set_mario_action(m, ACT_METAL_WATER_STANDING, 0);
}
return FALSE;
}
-static s32 act_hold_metal_water_jump_land(struct MarioState *m) {
+static s32 act_hold_metal_water_jump_land(struct MarioState *m)
+{
play_metal_water_jumping_sound(m, TRUE);
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_METAL_WATER_STANDING, 0);
}
- if (!(m->flags & MARIO_METAL_CAP)) {
+ if (!(m->flags & MARIO_METAL_CAP))
+ {
return set_mario_action(m, ACT_HOLD_WATER_IDLE, 0);
}
- if (m->input & INPUT_NONZERO_ANALOG) {
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
return set_mario_action(m, ACT_HOLD_METAL_WATER_WALKING, 0);
}
stop_and_set_height_to_floor(m);
set_mario_animation(m, MARIO_ANIM_JUMP_LAND_WITH_LIGHT_OBJ);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
return set_mario_action(m, ACT_HOLD_METAL_WATER_STANDING, 0);
}
return FALSE;
}
-static s32 act_metal_water_fall_land(struct MarioState *m) {
+static s32 act_metal_water_fall_land(struct MarioState *m)
+{
play_metal_water_jumping_sound(m, TRUE);
- if (!(m->flags & MARIO_METAL_CAP)) {
+ if (!(m->flags & MARIO_METAL_CAP))
+ {
return set_mario_action(m, ACT_WATER_IDLE, 0);
}
- if (m->input & INPUT_NONZERO_ANALOG) {
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
return set_mario_action(m, ACT_METAL_WATER_WALKING, 0);
}
stop_and_set_height_to_floor(m);
set_mario_animation(m, MARIO_ANIM_GENERAL_LAND);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
return set_mario_action(m, ACT_METAL_WATER_STANDING, 0);
}
return FALSE;
}
-static s32 act_hold_metal_water_fall_land(struct MarioState *m) {
+static s32 act_hold_metal_water_fall_land(struct MarioState *m)
+{
play_metal_water_jumping_sound(m, TRUE);
- if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {
+ if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT)
+ {
return drop_and_set_mario_action(m, ACT_METAL_WATER_STANDING, 0);
}
- if (!(m->flags & MARIO_METAL_CAP)) {
+ if (!(m->flags & MARIO_METAL_CAP))
+ {
return set_mario_action(m, ACT_HOLD_WATER_IDLE, 0);
}
- if (m->input & INPUT_NONZERO_ANALOG) {
+ if (m->input & INPUT_NONZERO_ANALOG)
+ {
return set_mario_action(m, ACT_HOLD_METAL_WATER_WALKING, 0);
}
stop_and_set_height_to_floor(m);
set_mario_animation(m, MARIO_ANIM_FALL_LAND_WITH_LIGHT_OBJ);
- if (is_anim_at_end(m)) {
+ if (is_anim_at_end(m))
+ {
return set_mario_action(m, ACT_HOLD_METAL_WATER_STANDING, 0);
}
return FALSE;
}
-static s32 check_common_submerged_cancels(struct MarioState *m) {
- if (m->pos[1] > m->waterLevel - 80) {
- if (m->waterLevel - 80 > m->floorHeight) {
+static s32 check_common_submerged_cancels(struct MarioState *m)
+{
+ if (m->pos[1] > m->waterLevel - 80)
+ {
+ if (m->waterLevel - 80 > m->floorHeight)
+ {
m->pos[1] = m->waterLevel - 80;
- } else {
+ }
+ else
+ {
//! If you press B to throw the shell, there is a ~5 frame window
// where your held object is the shell, but you are not in the
// water shell swimming action. This allows you to hold the water
// shell on land (used for cloning in DDD).
- if (m->action == ACT_WATER_SHELL_SWIMMING && m->heldObj != NULL) {
+ if (m->action == ACT_WATER_SHELL_SWIMMING && m->heldObj != NULL)
+ {
m->heldObj->oInteractStatus = INT_STATUS_STOP_RIDING;
m->heldObj = NULL;
stop_shell_music();
@@ -1525,17 +1836,20 @@ static s32 check_common_submerged_cancels(struct MarioState *m) {
}
}
- if (m->health < 0x100 && !(m->action & (ACT_FLAG_INTANGIBLE | ACT_FLAG_INVULNERABLE))) {
+ if (m->health < 0x100 && !(m->action & (ACT_FLAG_INTANGIBLE | ACT_FLAG_INVULNERABLE)))
+ {
set_mario_action(m, ACT_DROWNING, 0);
}
return FALSE;
}
-s32 mario_execute_submerged_action(struct MarioState *m) {
+s32 mario_execute_submerged_action(struct MarioState *m)
+{
s32 cancel;
- if (check_common_submerged_cancels(m)) {
+ if (check_common_submerged_cancels(m))
+ {
return TRUE;
}
diff --git a/src/decomp/game/mario_misc.c b/src/decomp/game/mario_misc.c
index d2bc962..d350380 100644
--- a/src/decomp/game/mario_misc.c
+++ b/src/decomp/game/mario_misc.c
@@ -28,7 +28,7 @@
#include "../include/object_fields.h"
#include "../include/mario_geo_switch_case_ids.h"
-static Vec3s gVec3sZero = {0,0,0};
+static Vec3s gVec3sZero = {0, 0, 0};
#define TOAD_STAR_1_REQUIREMENT 12
#define TOAD_STAR_2_REQUIREMENT 25
@@ -42,7 +42,8 @@ static Vec3s gVec3sZero = {0,0,0};
#define TOAD_STAR_2_DIALOG_AFTER 91 // DIALOG_155
#define TOAD_STAR_3_DIALOG_AFTER 92 // DIALOG_156
-enum ToadMessageStates {
+enum ToadMessageStates
+{
TOAD_MESSAGE_FADED,
TOAD_MESSAGE_OPAQUE,
TOAD_MESSAGE_OPACIFYING,
@@ -50,7 +51,8 @@ enum ToadMessageStates {
TOAD_MESSAGE_TALKING
};
-enum UnlockDoorStarStates {
+enum UnlockDoorStarStates
+{
UNLOCK_DOOR_STAR_RISING,
UNLOCK_DOOR_STAR_WAITING,
UNLOCK_DOOR_STAR_SPAWNING_PARTICLES,
@@ -61,7 +63,7 @@ enum UnlockDoorStarStates {
* The eye texture on succesive frames of Mario's blink animation.
* He intentionally blinks twice each time.
*/
-static s8 gMarioBlinkAnimation[7] = { 1, 2, 1, 0, 1, 2, 1 };
+static s8 gMarioBlinkAnimation[7] = {1, 2, 1, 0, 1, 2, 1};
/**
* The scale values per frame for Mario's foot/hand for his attack animation
@@ -93,7 +95,7 @@ static s8 gMarioAttackScaleAnimation[3 * 6] = {
// s16 sfx = 0;
// struct GraphNodeGenerated *asGenerated = (struct GraphNodeGenerated *) node;
// UNUSED Mat4 *transform = c;
-//
+//
// if (callContext == GEO_CONTEXT_RENDER) {
// if (gPlayerController->controllerData != NULL && !gWarpTransition.isActive) {
// gd_copy_p1_contpad(gPlayer1Controller->controllerData);
@@ -106,66 +108,76 @@ static s8 gMarioAttackScaleAnimation[3 * 6] = {
// return gfx;
// }
-static void toad_message_faded(void) {
-// if (gCurrentObject->oDistanceToMario > 700.0f) {
-// gCurrentObject->oToadMessageRecentlyTalked = FALSE;
-// }
-// if (!gCurrentObject->oToadMessageRecentlyTalked && gCurrentObject->oDistanceToMario < 600.0f) {
-// gCurrentObject->oToadMessageState = TOAD_MESSAGE_OPACIFYING;
-// }
+static void toad_message_faded(void)
+{
+ // if (gCurrentObject->oDistanceToMario > 700.0f) {
+ // gCurrentObject->oToadMessageRecentlyTalked = FALSE;
+ // }
+ // if (!gCurrentObject->oToadMessageRecentlyTalked && gCurrentObject->oDistanceToMario < 600.0f) {
+ // gCurrentObject->oToadMessageState = TOAD_MESSAGE_OPACIFYING;
+ // }
}
-static void toad_message_opaque(void) {
-// if (gCurrentObject->oDistanceToMario > 700.0f) {
-// gCurrentObject->oToadMessageState = TOAD_MESSAGE_FADING;
-// } else if (!gCurrentObject->oToadMessageRecentlyTalked) {
-// gCurrentObject->oInteractionSubtype = INT_SUBTYPE_NPC;
-// if (gCurrentObject->oInteractStatus & INT_STATUS_INTERACTED) {
-// gCurrentObject->oInteractStatus = 0;
-// gCurrentObject->oToadMessageState = TOAD_MESSAGE_TALKING;
-// play_toads_jingle();
-// }
-// }
+static void toad_message_opaque(void)
+{
+ // if (gCurrentObject->oDistanceToMario > 700.0f) {
+ // gCurrentObject->oToadMessageState = TOAD_MESSAGE_FADING;
+ // } else if (!gCurrentObject->oToadMessageRecentlyTalked) {
+ // gCurrentObject->oInteractionSubtype = INT_SUBTYPE_NPC;
+ // if (gCurrentObject->oInteractStatus & INT_STATUS_INTERACTED) {
+ // gCurrentObject->oInteractStatus = 0;
+ // gCurrentObject->oToadMessageState = TOAD_MESSAGE_TALKING;
+ // play_toads_jingle();
+ // }
+ // }
}
-static void toad_message_talking(void) {
-// if (cur_obj_update_dialog_with_cutscene(3, 1, CUTSCENE_DIALOG, gCurrentObject->oToadMessageDialogId)
-// != 0) {
-// gCurrentObject->oToadMessageRecentlyTalked = TRUE;
-// gCurrentObject->oToadMessageState = TOAD_MESSAGE_FADING;
-// switch (gCurrentObject->oToadMessageDialogId) {
-// case TOAD_STAR_1_DIALOG:
-// gCurrentObject->oToadMessageDialogId = TOAD_STAR_1_DIALOG_AFTER;
-// bhv_spawn_star_no_level_exit(0);
-// break;
-// case TOAD_STAR_2_DIALOG:
-// gCurrentObject->oToadMessageDialogId = TOAD_STAR_2_DIALOG_AFTER;
-// bhv_spawn_star_no_level_exit(1);
-// break;
-// case TOAD_STAR_3_DIALOG:
-// gCurrentObject->oToadMessageDialogId = TOAD_STAR_3_DIALOG_AFTER;
-// bhv_spawn_star_no_level_exit(2);
-// break;
-// }
-// }
+static void toad_message_talking(void)
+{
+ // if (cur_obj_update_dialog_with_cutscene(3, 1, CUTSCENE_DIALOG, gCurrentObject->oToadMessageDialogId)
+ // != 0) {
+ // gCurrentObject->oToadMessageRecentlyTalked = TRUE;
+ // gCurrentObject->oToadMessageState = TOAD_MESSAGE_FADING;
+ // switch (gCurrentObject->oToadMessageDialogId) {
+ // case TOAD_STAR_1_DIALOG:
+ // gCurrentObject->oToadMessageDialogId = TOAD_STAR_1_DIALOG_AFTER;
+ // bhv_spawn_star_no_level_exit(0);
+ // break;
+ // case TOAD_STAR_2_DIALOG:
+ // gCurrentObject->oToadMessageDialogId = TOAD_STAR_2_DIALOG_AFTER;
+ // bhv_spawn_star_no_level_exit(1);
+ // break;
+ // case TOAD_STAR_3_DIALOG:
+ // gCurrentObject->oToadMessageDialogId = TOAD_STAR_3_DIALOG_AFTER;
+ // bhv_spawn_star_no_level_exit(2);
+ // break;
+ // }
+ // }
}
-static void toad_message_opacifying(void) {
- if ((gCurrentObject->oOpacity += 6) == 255) {
+static void toad_message_opacifying(void)
+{
+ if ((gCurrentObject->oOpacity += 6) == 255)
+ {
gCurrentObject->oToadMessageState = TOAD_MESSAGE_OPAQUE;
}
}
-static void toad_message_fading(void) {
- if ((gCurrentObject->oOpacity -= 6) == 81) {
+static void toad_message_fading(void)
+{
+ if ((gCurrentObject->oOpacity -= 6) == 81)
+ {
gCurrentObject->oToadMessageState = TOAD_MESSAGE_FADED;
}
}
-void bhv_toad_message_loop(void) {
- if (gCurrentObject->header.gfx.node.flags & GRAPH_RENDER_ACTIVE) {
+void bhv_toad_message_loop(void)
+{
+ if (gCurrentObject->header.gfx.node.flags & GRAPH_RENDER_ACTIVE)
+ {
gCurrentObject->oInteractionSubtype = 0;
- switch (gCurrentObject->oToadMessageState) {
+ switch (gCurrentObject->oToadMessageState)
+ {
case TOAD_MESSAGE_FADED:
toad_message_faded();
break;
@@ -185,40 +197,41 @@ void bhv_toad_message_loop(void) {
}
}
-void bhv_toad_message_init(void) {
-// s32 saveFlags = save_file_get_flags();
-// s32 starCount = save_file_get_total_star_count(gCurrSaveFileNum - 1, COURSE_MIN - 1, COURSE_MAX - 1);
-// s32 dialogId = (gCurrentObject->oBehParams >> 24) & 0xFF;
-// s32 enoughStars = TRUE;
-//
-// switch (dialogId) {
-// case TOAD_STAR_1_DIALOG:
-// enoughStars = (starCount >= TOAD_STAR_1_REQUIREMENT);
-// if (saveFlags & SAVE_FLAG_COLLECTED_TOAD_STAR_1) {
-// dialogId = TOAD_STAR_1_DIALOG_AFTER;
-// }
-// break;
-// case TOAD_STAR_2_DIALOG:
-// enoughStars = (starCount >= TOAD_STAR_2_REQUIREMENT);
-// if (saveFlags & SAVE_FLAG_COLLECTED_TOAD_STAR_2) {
-// dialogId = TOAD_STAR_2_DIALOG_AFTER;
-// }
-// break;
-// case TOAD_STAR_3_DIALOG:
-// enoughStars = (starCount >= TOAD_STAR_3_REQUIREMENT);
-// if (saveFlags & SAVE_FLAG_COLLECTED_TOAD_STAR_3) {
-// dialogId = TOAD_STAR_3_DIALOG_AFTER;
-// }
-// break;
-// }
-// if (enoughStars) {
-// gCurrentObject->oToadMessageDialogId = dialogId;
-// gCurrentObject->oToadMessageRecentlyTalked = FALSE;
-// gCurrentObject->oToadMessageState = TOAD_MESSAGE_FADED;
-// gCurrentObject->oOpacity = 81;
-// } else {
-// obj_mark_for_deletion(gCurrentObject);
-// }
+void bhv_toad_message_init(void)
+{
+ // s32 saveFlags = save_file_get_flags();
+ // s32 starCount = save_file_get_total_star_count(gCurrSaveFileNum - 1, COURSE_MIN - 1, COURSE_MAX - 1);
+ // s32 dialogId = (gCurrentObject->oBehParams >> 24) & 0xFF;
+ // s32 enoughStars = TRUE;
+ //
+ // switch (dialogId) {
+ // case TOAD_STAR_1_DIALOG:
+ // enoughStars = (starCount >= TOAD_STAR_1_REQUIREMENT);
+ // if (saveFlags & SAVE_FLAG_COLLECTED_TOAD_STAR_1) {
+ // dialogId = TOAD_STAR_1_DIALOG_AFTER;
+ // }
+ // break;
+ // case TOAD_STAR_2_DIALOG:
+ // enoughStars = (starCount >= TOAD_STAR_2_REQUIREMENT);
+ // if (saveFlags & SAVE_FLAG_COLLECTED_TOAD_STAR_2) {
+ // dialogId = TOAD_STAR_2_DIALOG_AFTER;
+ // }
+ // break;
+ // case TOAD_STAR_3_DIALOG:
+ // enoughStars = (starCount >= TOAD_STAR_3_REQUIREMENT);
+ // if (saveFlags & SAVE_FLAG_COLLECTED_TOAD_STAR_3) {
+ // dialogId = TOAD_STAR_3_DIALOG_AFTER;
+ // }
+ // break;
+ // }
+ // if (enoughStars) {
+ // gCurrentObject->oToadMessageDialogId = dialogId;
+ // gCurrentObject->oToadMessageRecentlyTalked = FALSE;
+ // gCurrentObject->oToadMessageState = TOAD_MESSAGE_FADED;
+ // gCurrentObject->oOpacity = 81;
+ // } else {
+ // obj_mark_for_deletion(gCurrentObject);
+ // }
}
//static void star_door_unlock_spawn_particles(s16 angleOffset) {
@@ -232,88 +245,94 @@ void bhv_toad_message_init(void) {
// sparkleParticle->oPosY -= gCurrentObject->oUnlockDoorStarTimer * 10.0f;
//}
-void bhv_unlock_door_star_init(void) {
-// gCurrentObject->oUnlockDoorStarState = UNLOCK_DOOR_STAR_RISING;
-// gCurrentObject->oUnlockDoorStarTimer = 0;
-// gCurrentObject->oUnlockDoorStarYawVel = 0x1000;
-// gCurrentObject->oPosX += 30.0f * sins(gMarioState->faceAngle[1] - 0x4000);
-// gCurrentObject->oPosY += 160.0f;
-// gCurrentObject->oPosZ += 30.0f * coss(gMarioState->faceAngle[1] - 0x4000);
-// gCurrentObject->oMoveAngleYaw = 0x7800;
-// obj_scale(gCurrentObject, 0.5f);
+void bhv_unlock_door_star_init(void)
+{
+ // gCurrentObject->oUnlockDoorStarState = UNLOCK_DOOR_STAR_RISING;
+ // gCurrentObject->oUnlockDoorStarTimer = 0;
+ // gCurrentObject->oUnlockDoorStarYawVel = 0x1000;
+ // gCurrentObject->oPosX += 30.0f * sins(gMarioState->faceAngle[1] - 0x4000);
+ // gCurrentObject->oPosY += 160.0f;
+ // gCurrentObject->oPosZ += 30.0f * coss(gMarioState->faceAngle[1] - 0x4000);
+ // gCurrentObject->oMoveAngleYaw = 0x7800;
+ // obj_scale(gCurrentObject, 0.5f);
}
-void bhv_unlock_door_star_loop(void) {
-// UNUSED u8 unused1[4];
-// s16 prevYaw = gCurrentObject->oMoveAngleYaw;
-// UNUSED u8 unused2[4];
-//
-// // Speed up the star every frame
-// if (gCurrentObject->oUnlockDoorStarYawVel < 0x2400) {
-// gCurrentObject->oUnlockDoorStarYawVel += 0x60;
-// }
-// switch (gCurrentObject->oUnlockDoorStarState) {
-// case UNLOCK_DOOR_STAR_RISING:
-// gCurrentObject->oPosY += 3.4f; // Raise the star up in the air
-// gCurrentObject->oMoveAngleYaw +=
-// gCurrentObject->oUnlockDoorStarYawVel; // Apply yaw velocity
-// obj_scale(gCurrentObject, gCurrentObject->oUnlockDoorStarTimer / 50.0f
-// + 0.5f); // Scale the star to be bigger
-// if (++gCurrentObject->oUnlockDoorStarTimer == 30) {
-// gCurrentObject->oUnlockDoorStarTimer = 0;
-// gCurrentObject->oUnlockDoorStarState++; // Sets state to UNLOCK_DOOR_STAR_WAITING
-// }
-// break;
-// case UNLOCK_DOOR_STAR_WAITING:
-// gCurrentObject->oMoveAngleYaw +=
-// gCurrentObject->oUnlockDoorStarYawVel; // Apply yaw velocity
-// if (++gCurrentObject->oUnlockDoorStarTimer == 30) {
-// play_sound(SOUND_MENU_STAR_SOUND,
-// gCurrentObject->header.gfx.cameraToObject); // Play final sound
-// cur_obj_hide(); // Hide the object
-// gCurrentObject->oUnlockDoorStarTimer = 0;
-// gCurrentObject
-// ->oUnlockDoorStarState++; // Sets state to UNLOCK_DOOR_STAR_SPAWNING_PARTICLES
-// }
-// break;
-// case UNLOCK_DOOR_STAR_SPAWNING_PARTICLES:
-// // Spawn two particles, opposite sides of the star.
-// star_door_unlock_spawn_particles(0);
-// star_door_unlock_spawn_particles(0x8000);
-// if (gCurrentObject->oUnlockDoorStarTimer++ == 20) {
-// gCurrentObject->oUnlockDoorStarTimer = 0;
-// gCurrentObject->oUnlockDoorStarState++; // Sets state to UNLOCK_DOOR_STAR_DONE
-// }
-// break;
-// case UNLOCK_DOOR_STAR_DONE: // The object stays loaded for an additional 50 frames so that the
-// // sound doesn't immediately stop.
-// if (gCurrentObject->oUnlockDoorStarTimer++ == 50) {
-// obj_mark_for_deletion(gCurrentObject);
-// }
-// break;
-// }
-// // Checks if the angle has cycled back to 0.
-// // This means that the code will execute when the star completes a full revolution.
-// if (prevYaw > (s16) gCurrentObject->oMoveAngleYaw) {
-// play_sound(
-// SOUND_GENERAL_SHORT_STAR,
-// gCurrentObject->header.gfx.cameraToObject); // Play a sound every time the star spins once
-// }
+void bhv_unlock_door_star_loop(void)
+{
+ // UNUSED u8 unused1[4];
+ // s16 prevYaw = gCurrentObject->oMoveAngleYaw;
+ // UNUSED u8 unused2[4];
+ //
+ // // Speed up the star every frame
+ // if (gCurrentObject->oUnlockDoorStarYawVel < 0x2400) {
+ // gCurrentObject->oUnlockDoorStarYawVel += 0x60;
+ // }
+ // switch (gCurrentObject->oUnlockDoorStarState) {
+ // case UNLOCK_DOOR_STAR_RISING:
+ // gCurrentObject->oPosY += 3.4f; // Raise the star up in the air
+ // gCurrentObject->oMoveAngleYaw +=
+ // gCurrentObject->oUnlockDoorStarYawVel; // Apply yaw velocity
+ // obj_scale(gCurrentObject, gCurrentObject->oUnlockDoorStarTimer / 50.0f
+ // + 0.5f); // Scale the star to be bigger
+ // if (++gCurrentObject->oUnlockDoorStarTimer == 30) {
+ // gCurrentObject->oUnlockDoorStarTimer = 0;
+ // gCurrentObject->oUnlockDoorStarState++; // Sets state to UNLOCK_DOOR_STAR_WAITING
+ // }
+ // break;
+ // case UNLOCK_DOOR_STAR_WAITING:
+ // gCurrentObject->oMoveAngleYaw +=
+ // gCurrentObject->oUnlockDoorStarYawVel; // Apply yaw velocity
+ // if (++gCurrentObject->oUnlockDoorStarTimer == 30) {
+ // play_sound(SOUND_MENU_STAR_SOUND,
+ // gCurrentObject->header.gfx.cameraToObject); // Play final sound
+ // cur_obj_hide(); // Hide the object
+ // gCurrentObject->oUnlockDoorStarTimer = 0;
+ // gCurrentObject
+ // ->oUnlockDoorStarState++; // Sets state to UNLOCK_DOOR_STAR_SPAWNING_PARTICLES
+ // }
+ // break;
+ // case UNLOCK_DOOR_STAR_SPAWNING_PARTICLES:
+ // // Spawn two particles, opposite sides of the star.
+ // star_door_unlock_spawn_particles(0);
+ // star_door_unlock_spawn_particles(0x8000);
+ // if (gCurrentObject->oUnlockDoorStarTimer++ == 20) {
+ // gCurrentObject->oUnlockDoorStarTimer = 0;
+ // gCurrentObject->oUnlockDoorStarState++; // Sets state to UNLOCK_DOOR_STAR_DONE
+ // }
+ // break;
+ // case UNLOCK_DOOR_STAR_DONE: // The object stays loaded for an additional 50 frames so that the
+ // // sound doesn't immediately stop.
+ // if (gCurrentObject->oUnlockDoorStarTimer++ == 50) {
+ // obj_mark_for_deletion(gCurrentObject);
+ // }
+ // break;
+ // }
+ // // Checks if the angle has cycled back to 0.
+ // // This means that the code will execute when the star completes a full revolution.
+ // if (prevYaw > (s16) gCurrentObject->oMoveAngleYaw) {
+ // play_sound(
+ // SOUND_GENERAL_SHORT_STAR,
+ // gCurrentObject->header.gfx.cameraToObject); // Play a sound every time the star spins once
+ // }
}
/**
* Generate a display list that sets the correct blend mode and color for mirror Mario.
*/
-static Gfx *make_gfx_mario_alpha(struct GraphNodeGenerated *node, s16 alpha) {
+static Gfx *make_gfx_mario_alpha(struct GraphNodeGenerated *node, s16 alpha)
+{
Gfx *gfx;
Gfx *gfxHead = NULL;
- if (alpha == 255) {
- node->fnNode.node.flags = (node->fnNode.node.flags & 0xFF) | (LAYER_OPAQUE << 8);
+ if (alpha == 255)
+ {
+ node->fnNode.node.flags = node->fnNode.node.flags & 0xFF | LAYER_OPAQUE << 8;
gfxHead = alloc_display_list(2 * sizeof(*gfxHead));
gfx = gfxHead;
- } else {
- node->fnNode.node.flags = (node->fnNode.node.flags & 0xFF) | (LAYER_TRANSPARENT << 8);
+ }
+ else
+ {
+ node->fnNode.node.flags = node->fnNode.node.flags & 0xFF | LAYER_TRANSPARENT << 8;
gfxHead = alloc_display_list(3 * sizeof(*gfxHead));
gfx = gfxHead;
gDPSetAlphaCompare(gfx++, G_AC_DITHER);
@@ -326,16 +345,18 @@ static Gfx *make_gfx_mario_alpha(struct GraphNodeGenerated *node, s16 alpha) {
/**
* Sets the correct blend mode and color for mirror Mario.
*/
-Gfx *geo_mirror_mario_set_alpha(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c) {
+Gfx *geo_mirror_mario_set_alpha(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c)
+{
UNUSED u8 unused1[4];
Gfx *gfx = NULL;
- struct GraphNodeGenerated *asGenerated = (struct GraphNodeGenerated *) node;
+ struct GraphNodeGenerated *asGenerated = (struct GraphNodeGenerated *)node;
struct MarioBodyState *bodyState = &gBodyStates[asGenerated->parameter];
s16 alpha;
UNUSED u8 unused2[4];
- if (callContext == GEO_CONTEXT_RENDER) {
- alpha = (bodyState->modelState & 0x100) ? (bodyState->modelState & 0xFF) : 255;
+ if (callContext == GEO_CONTEXT_RENDER)
+ {
+ alpha = bodyState->modelState & 0x100 ? bodyState->modelState & 0xFF : 255;
gfx = make_gfx_mario_alpha(asGenerated, alpha);
}
return gfx;
@@ -346,13 +367,15 @@ Gfx *geo_mirror_mario_set_alpha(s32 callContext, struct GraphNode *node, UNUSED
* If Mario is standing still, he is always high poly. If he is running,
* his level of detail depends on the distance to the camera.
*/
-Gfx *geo_switch_mario_stand_run(s32 callContext, struct GraphNode *node, UNUSED Mat4 *mtx) {
- struct GraphNodeSwitchCase *switchCase = (struct GraphNodeSwitchCase *) node;
+Gfx *geo_switch_mario_stand_run(s32 callContext, struct GraphNode *node, UNUSED Mat4 *mtx)
+{
+ struct GraphNodeSwitchCase *switchCase = (struct GraphNodeSwitchCase *)node;
struct MarioBodyState *bodyState = &gBodyStates[switchCase->numCases];
- if (callContext == GEO_CONTEXT_RENDER) {
+ if (callContext == GEO_CONTEXT_RENDER)
+ {
// assign result. 0 if moving, 1 if stationary.
- switchCase->selectedCase = ((bodyState->action & ACT_FLAG_STATIONARY) == 0);
+ switchCase->selectedCase = (bodyState->action & ACT_FLAG_STATIONARY) == 0;
}
return NULL;
}
@@ -360,20 +383,28 @@ Gfx *geo_switch_mario_stand_run(s32 callContext, struct GraphNode *node, UNUSED
/**
* Geo node script that makes Mario blink
*/
-Gfx *geo_switch_mario_eyes(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c) {
- struct GraphNodeSwitchCase *switchCase = (struct GraphNodeSwitchCase *) node;
+Gfx *geo_switch_mario_eyes(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c)
+{
+ struct GraphNodeSwitchCase *switchCase = (struct GraphNodeSwitchCase *)node;
struct MarioBodyState *bodyState = &gBodyStates[switchCase->numCases];
s16 blinkFrame;
- if (callContext == GEO_CONTEXT_RENDER) {
- if (bodyState->eyeState == 0) {
- blinkFrame = ((switchCase->numCases * 32 + gAreaUpdateCounter) >> 1) & 0x1F;
- if (blinkFrame < 7) {
+ if (callContext == GEO_CONTEXT_RENDER)
+ {
+ if (bodyState->eyeState == 0)
+ {
+ blinkFrame = (switchCase->numCases * 32 + gAreaUpdateCounter) >> 1 & 0x1F;
+ if (blinkFrame < 7)
+ {
switchCase->selectedCase = gMarioBlinkAnimation[blinkFrame];
- } else {
+ }
+ else
+ {
switchCase->selectedCase = 0;
}
- } else {
+ }
+ else
+ {
switchCase->selectedCase = bodyState->eyeState - 1;
}
}
@@ -383,16 +414,19 @@ Gfx *geo_switch_mario_eyes(s32 callContext, struct GraphNode *node, UNUSED Mat4
/**
* Makes Mario's upper body tilt depending on the rotation stored in his bodyState
*/
-Gfx *geo_mario_tilt_torso(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c) {
- struct GraphNodeGenerated *asGenerated = (struct GraphNodeGenerated *) node;
+Gfx *geo_mario_tilt_torso(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c)
+{
+ struct GraphNodeGenerated *asGenerated = (struct GraphNodeGenerated *)node;
struct MarioBodyState *bodyState = &gBodyStates[asGenerated->parameter];
s32 action = bodyState->action;
- if (callContext == GEO_CONTEXT_RENDER) {
- struct GraphNodeRotation *rotNode = (struct GraphNodeRotation *) node->next;
+ if (callContext == GEO_CONTEXT_RENDER)
+ {
+ struct GraphNodeRotation *rotNode = (struct GraphNodeRotation *)node->next;
if (action != ACT_BUTT_SLIDE && action != ACT_HOLD_BUTT_SLIDE && action != ACT_WALKING
- && action != ACT_RIDING_SHELL_GROUND) {
+ && action != ACT_RIDING_SHELL_GROUND)
+ {
vec3s_copy(bodyState->torsoAngle, gVec3sZero);
}
rotNode->rotation[0] = bodyState->torsoAngle[1];
@@ -405,26 +439,28 @@ Gfx *geo_mario_tilt_torso(s32 callContext, struct GraphNode *node, UNUSED Mat4 *
/**
* Makes Mario's head rotate with the camera angle when in C-up mode
*/
-Gfx *geo_mario_head_rotation(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c) {
- struct GraphNodeGenerated *asGenerated = (struct GraphNodeGenerated *) node;
+Gfx *geo_mario_head_rotation(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c)
+{
+ struct GraphNodeGenerated *asGenerated = (struct GraphNodeGenerated *)node;
struct MarioBodyState *bodyState = &gBodyStates[asGenerated->parameter];
// s32 action = bodyState->action;
- if (callContext == GEO_CONTEXT_RENDER) {
- struct GraphNodeRotation *rotNode = (struct GraphNodeRotation *) node->next;
- // struct Camera *camera = gCurGraphNodeCamera->config.camera;
+ if (callContext == GEO_CONTEXT_RENDER)
+ {
+ struct GraphNodeRotation *rotNode = (struct GraphNodeRotation *)node->next;
+ // struct Camera *camera = gCurGraphNodeCamera->config.camera;
- // if (camera->mode == CAMERA_MODE_C_UP) {
- // rotNode->rotation[0] = 0; // gPlayerCameraState->headRotation[1]; // PATCH
- // rotNode->rotation[2] = 0; // gPlayerCameraState->headRotation[0];
- // } else if (action & ACT_FLAG_WATER_OR_TEXT) {
- // rotNode->rotation[0] = bodyState->headAngle[1];
- // rotNode->rotation[1] = bodyState->headAngle[2];
- // rotNode->rotation[2] = bodyState->headAngle[0];
- // } else {
- vec3s_set(bodyState->headAngle, 0, 0, 0);
- vec3s_set(rotNode->rotation, 0, 0, 0);
- // }
+ // if (camera->mode == CAMERA_MODE_C_UP) {
+ // rotNode->rotation[0] = 0; // gPlayerCameraState->headRotation[1]; // PATCH
+ // rotNode->rotation[2] = 0; // gPlayerCameraState->headRotation[0];
+ // } else if (action & ACT_FLAG_WATER_OR_TEXT) {
+ // rotNode->rotation[0] = bodyState->headAngle[1];
+ // rotNode->rotation[1] = bodyState->headAngle[2];
+ // rotNode->rotation[2] = bodyState->headAngle[0];
+ // } else {
+ vec3s_set(bodyState->headAngle, 0, 0, 0);
+ vec3s_set(rotNode->rotation, 0, 0, 0);
+ // }
}
return NULL;
}
@@ -433,21 +469,29 @@ Gfx *geo_mario_head_rotation(s32 callContext, struct GraphNode *node, UNUSED Mat
* Switch between hand models.
* Possible options are described in the MarioHandGSCId enum.
*/
-Gfx *geo_switch_mario_hand(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c) {
- struct GraphNodeSwitchCase *switchCase = (struct GraphNodeSwitchCase *) node;
+Gfx *geo_switch_mario_hand(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c)
+{
+ struct GraphNodeSwitchCase *switchCase = (struct GraphNodeSwitchCase *)node;
struct MarioBodyState *bodyState = &gBodyStates[0];
- if (callContext == GEO_CONTEXT_RENDER) {
- if (bodyState->handState == MARIO_HAND_FISTS) {
+ if (callContext == GEO_CONTEXT_RENDER)
+ {
+ if (bodyState->handState == MARIO_HAND_FISTS)
+ {
// switch between fists (0) and open (1)
- switchCase->selectedCase = ((bodyState->action & ACT_FLAG_SWIMMING_OR_FLYING) != 0);
- } else {
- if (switchCase->numCases == 0) {
+ switchCase->selectedCase = (bodyState->action & ACT_FLAG_SWIMMING_OR_FLYING) != 0;
+ }
+ else
+ {
+ if (switchCase->numCases == 0)
+ {
switchCase->selectedCase =
- (bodyState->handState < 5) ? bodyState->handState : MARIO_HAND_OPEN;
- } else {
+ bodyState->handState < 5 ? bodyState->handState : MARIO_HAND_OPEN;
+ }
+ else
+ {
switchCase->selectedCase =
- (bodyState->handState < 2) ? bodyState->handState : MARIO_HAND_FISTS;
+ bodyState->handState < 2 ? bodyState->handState : MARIO_HAND_FISTS;
}
}
}
@@ -462,21 +506,25 @@ Gfx *geo_switch_mario_hand(s32 callContext, struct GraphNode *node, UNUSED Mat4
* ! Since the animation gets updated in GEO_CONTEXT_RENDER, drawing Mario multiple times
* (such as in the mirror room) results in a faster and desynced punch / kick animation.
*/
-Gfx *geo_mario_hand_foot_scaler(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c) {
- struct GraphNodeGenerated *asGenerated = (struct GraphNodeGenerated *) node;
- struct GraphNodeScale *scaleNode = (struct GraphNodeScale *) node->next;
+Gfx *geo_mario_hand_foot_scaler(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c)
+{
+ struct GraphNodeGenerated *asGenerated = (struct GraphNodeGenerated *)node;
+ struct GraphNodeScale *scaleNode = (struct GraphNodeScale *)node->next;
struct MarioBodyState *bodyState = &gBodyStates[0];
- if (callContext == GEO_CONTEXT_RENDER) {
+ if (callContext == GEO_CONTEXT_RENDER)
+ {
scaleNode->scale = 1.0f;
- if (asGenerated->parameter == bodyState->punchState >> 6) {
- if (g_state->msMarioAttackAnimCounter != gAreaUpdateCounter && (bodyState->punchState & 0x3F) > 0) {
+ if (asGenerated->parameter == bodyState->punchState >> 6)
+ {
+ if (g_state->msMarioAttackAnimCounter != gAreaUpdateCounter && (bodyState->punchState & 0x3F) > 0)
+ {
bodyState->punchState -= 1;
g_state->msMarioAttackAnimCounter = gAreaUpdateCounter;
}
scaleNode->scale =
- gMarioAttackScaleAnimation[asGenerated->parameter * 6 + (bodyState->punchState & 0x3F)]
- / 10.0f;
+ gMarioAttackScaleAnimation[asGenerated->parameter * 6 + (bodyState->punchState & 0x3F)]
+ / 10.0f;
}
}
return NULL;
@@ -485,15 +533,20 @@ Gfx *geo_mario_hand_foot_scaler(s32 callContext, struct GraphNode *node, UNUSED
/**
* Switch between normal cap, wing cap, vanish cap and metal cap.
*/
-Gfx *geo_switch_mario_cap_effect(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c) {
- struct GraphNodeSwitchCase *switchCase = (struct GraphNodeSwitchCase *) node;
+Gfx *geo_switch_mario_cap_effect(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c)
+{
+ struct GraphNodeSwitchCase *switchCase = (struct GraphNodeSwitchCase *)node;
struct MarioBodyState *bodyState = &gBodyStates[switchCase->numCases];
- if (callContext == GEO_CONTEXT_RENDER) {
+ if (callContext == GEO_CONTEXT_RENDER)
+ {
// switchCase->selectedCase = bodyState->modelState >> 8;
- if (bodyState->modelState >> 8 >= 2){ // temporarily disables metal cap
+ if (bodyState->modelState >> 8 >= 2)
+ { // temporarily disables metal cap
switchCase->selectedCase = 0;
- } else {
+ }
+ else
+ {
switchCase->selectedCase = bodyState->modelState >> 8;
}
}
@@ -504,18 +557,25 @@ Gfx *geo_switch_mario_cap_effect(s32 callContext, struct GraphNode *node, UNUSED
* Determine whether Mario's head is drawn with or without a cap on.
* Also sets the visibility of the wing cap wings on or off.
*/
-Gfx *geo_switch_mario_cap_on_off(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c) {
+Gfx *geo_switch_mario_cap_on_off(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c)
+{
struct GraphNode *next = node->next;
- struct GraphNodeSwitchCase *switchCase = (struct GraphNodeSwitchCase *) node;
+ struct GraphNodeSwitchCase *switchCase = (struct GraphNodeSwitchCase *)node;
struct MarioBodyState *bodyState = &gBodyStates[switchCase->numCases];
- if (callContext == GEO_CONTEXT_RENDER) {
+ if (callContext == GEO_CONTEXT_RENDER)
+ {
switchCase->selectedCase = bodyState->capState & 1;
- while (next != node) {
- if (next->type == GRAPH_NODE_TYPE_TRANSLATION_ROTATION) {
- if (bodyState->capState & 2) {
+ while (next != node)
+ {
+ if (next->type == GRAPH_NODE_TYPE_TRANSLATION_ROTATION)
+ {
+ if (bodyState->capState & 2)
+ {
next->flags |= GRAPH_RENDER_ACTIVE;
- } else {
+ }
+ else
+ {
next->flags &= ~GRAPH_RENDER_ACTIVE;
}
}
@@ -529,21 +589,29 @@ Gfx *geo_switch_mario_cap_on_off(s32 callContext, struct GraphNode *node, UNUSED
* Geo node script that makes the wings on Mario's wing cap flap.
* Should be placed before a rotation node.
*/
-Gfx *geo_mario_rotate_wing_cap_wings(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c) {
+Gfx *geo_mario_rotate_wing_cap_wings(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c)
+{
s16 rotX;
- struct GraphNodeGenerated *asGenerated = (struct GraphNodeGenerated *) node;
+ struct GraphNodeGenerated *asGenerated = (struct GraphNodeGenerated *)node;
- if (callContext == GEO_CONTEXT_RENDER) {
- struct GraphNodeRotation *rotNode = (struct GraphNodeRotation *) node->next;
+ if (callContext == GEO_CONTEXT_RENDER)
+ {
+ struct GraphNodeRotation *rotNode = (struct GraphNodeRotation *)node->next;
- if (!gBodyStates[asGenerated->parameter >> 1].wingFlutter) {
+ if (!gBodyStates[asGenerated->parameter >> 1].wingFlutter)
+ {
rotX = (coss((gAreaUpdateCounter & 0xF) << 12) + 1.0f) * 4096.0f;
- } else {
+ }
+ else
+ {
rotX = (coss((gAreaUpdateCounter & 7) << 13) + 1.0f) * 6144.0f;
}
- if (!(asGenerated->parameter & 1)) {
+ if (!(asGenerated->parameter & 1))
+ {
rotNode->rotation[0] = -rotX;
- } else {
+ }
+ else
+ {
rotNode->rotation[0] = rotX;
}
}
@@ -553,20 +621,27 @@ Gfx *geo_mario_rotate_wing_cap_wings(s32 callContext, struct GraphNode *node, UN
/**
* Geo node that updates the held object node and the HOLP.
*/
-Gfx *geo_switch_mario_hand_grab_pos(s32 callContext, struct GraphNode *b, Mat4 *mtx) {
- struct GraphNodeHeldObject *asHeldObj = (struct GraphNodeHeldObject *) b;
+Gfx *geo_switch_mario_hand_grab_pos(s32 callContext, struct GraphNode *b, Mat4 *mtx)
+{
+ struct GraphNodeHeldObject *asHeldObj = (struct GraphNodeHeldObject *)b;
Mat4 *curTransform = mtx;
struct MarioState *marioState = gMarioState; // &gMarioStates[asHeldObj->playerIndex]; // PATCH
- if (callContext == GEO_CONTEXT_RENDER) {
+ if (callContext == GEO_CONTEXT_RENDER)
+ {
asHeldObj->objNode = NULL;
- if (marioState->heldObj != NULL) {
+ if (marioState->heldObj != NULL)
+ {
asHeldObj->objNode = marioState->heldObj;
- switch (marioState->marioBodyState->grabPos) {
+ switch (marioState->marioBodyState->grabPos)
+ {
case GRAB_POS_LIGHT_OBJ:
- if (marioState->action & ACT_FLAG_THROWING) {
+ if (marioState->action & ACT_FLAG_THROWING)
+ {
vec3s_set(asHeldObj->translation, 50, 0, 0);
- } else {
+ }
+ else
+ {
vec3s_set(asHeldObj->translation, 50, 0, 110);
}
break;
@@ -578,7 +653,9 @@ Gfx *geo_switch_mario_hand_grab_pos(s32 callContext, struct GraphNode *b, Mat4 *
break;
}
}
- } else if (callContext == GEO_CONTEXT_HELD_OBJ) {
+ }
+ else if (callContext == GEO_CONTEXT_HELD_OBJ)
+ {
// ! The HOLP is set here, which is why it only updates when the held object is drawn.
// This is why it won't update during a pause buffered hitstun or when the camera is very far
// away.
@@ -595,40 +672,41 @@ Gfx *geo_switch_mario_hand_grab_pos(s32 callContext, struct GraphNode *b, Mat4 *
* Geo node that creates a clone of Mario's geo node and updates it to becomes
* a mirror image of the player.
*/
-Gfx *geo_render_mirror_mario(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c) {
-// f32 mirroredX;
-// struct Object *mario = gMarioState->marioObj; // PATCH gMarioStates[0].marioObj;
+Gfx *geo_render_mirror_mario(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c)
+{
+ // f32 mirroredX;
+ // struct Object *mario = gMarioState->marioObj; // PATCH gMarioStates[0].marioObj;
-// switch (callContext) {
-// case GEO_CONTEXT_CREATE:
-// init_graph_node_object(NULL, &gMirrorMario, NULL, gVec3fZero, gVec3sZero, gVec3fOne);
-// break;
-// case GEO_CONTEXT_AREA_LOAD:
-// geo_add_child(node, &gMirrorMario.node);
-// break;
-// case GEO_CONTEXT_AREA_UNLOAD:
-// geo_remove_child(&gMirrorMario.node);
-// break;
-// case GEO_CONTEXT_RENDER:
-// if (mario->header.gfx.pos[0] > 1700.0f) {
-// // TODO: Is this a geo layout copy or a graph node copy?
-// gMirrorMario.sharedChild = mario->header.gfx.sharedChild;
-// gMirrorMario.areaIndex = mario->header.gfx.areaIndex;
-// vec3s_copy(gMirrorMario.angle, mario->header.gfx.angle);
-// vec3f_copy(gMirrorMario.pos, mario->header.gfx.pos);
-// vec3f_copy(gMirrorMario.scale, mario->header.gfx.scale);
+ // switch (callContext) {
+ // case GEO_CONTEXT_CREATE:
+ // init_graph_node_object(NULL, &gMirrorMario, NULL, gVec3fZero, gVec3sZero, gVec3fOne);
+ // break;
+ // case GEO_CONTEXT_AREA_LOAD:
+ // geo_add_child(node, &gMirrorMario.node);
+ // break;
+ // case GEO_CONTEXT_AREA_UNLOAD:
+ // geo_remove_child(&gMirrorMario.node);
+ // break;
+ // case GEO_CONTEXT_RENDER:
+ // if (mario->header.gfx.pos[0] > 1700.0f) {
+ // // TODO: Is this a geo layout copy or a graph node copy?
+ // gMirrorMario.sharedChild = mario->header.gfx.sharedChild;
+ // gMirrorMario.areaIndex = mario->header.gfx.areaIndex;
+ // vec3s_copy(gMirrorMario.angle, mario->header.gfx.angle);
+ // vec3f_copy(gMirrorMario.pos, mario->header.gfx.pos);
+ // vec3f_copy(gMirrorMario.scale, mario->header.gfx.scale);
-// gMirrorMario.animInfo = mario->header.gfx.animInfo;
-// mirroredX = MIRROR_X - gMirrorMario.pos[0];
-// gMirrorMario.pos[0] = mirroredX + MIRROR_X;
-// gMirrorMario.angle[1] = -gMirrorMario.angle[1];
-// gMirrorMario.scale[0] *= -1.0f;
-// ((struct GraphNode *) &gMirrorMario)->flags |= 1;
-// } else {
-// ((struct GraphNode *) &gMirrorMario)->flags &= ~1;
-// }
-// break;
-// }
+ // gMirrorMario.animInfo = mario->header.gfx.animInfo;
+ // mirroredX = MIRROR_X - gMirrorMario.pos[0];
+ // gMirrorMario.pos[0] = mirroredX + MIRROR_X;
+ // gMirrorMario.angle[1] = -gMirrorMario.angle[1];
+ // gMirrorMario.scale[0] *= -1.0f;
+ // ((struct GraphNode *) &gMirrorMario)->flags |= 1;
+ // } else {
+ // ((struct GraphNode *) &gMirrorMario)->flags &= ~1;
+ // }
+ // break;
+ // }
return NULL;
}
@@ -636,24 +714,25 @@ Gfx *geo_render_mirror_mario(s32 callContext, struct GraphNode *node, UNUSED Mat
* Since Mirror Mario has an x scale of -1, the mesh becomes inside out.
* This node corrects that by changing the culling mode accordingly.
*/
-Gfx *geo_mirror_mario_backface_culling(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c) {
-// struct GraphNodeGenerated *asGenerated = (struct GraphNodeGenerated *) node;
-// Gfx *gfx = NULL;
+Gfx *geo_mirror_mario_backface_culling(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c)
+{
+ // struct GraphNodeGenerated *asGenerated = (struct GraphNodeGenerated *) node;
+ // Gfx *gfx = NULL;
-// if (callContext == GEO_CONTEXT_RENDER && gCurGraphNodeObject == &gMirrorMario) {
-// gfx = alloc_display_list(3 * sizeof(*gfx));
+ // if (callContext == GEO_CONTEXT_RENDER && gCurGraphNodeObject == &gMirrorMario) {
+ // gfx = alloc_display_list(3 * sizeof(*gfx));
-// if (asGenerated->parameter == 0) {
-// gSPClearGeometryMode(&gfx[0], G_CULL_BACK);
-// gSPSetGeometryMode(&gfx[1], G_CULL_FRONT);
-// gSPEndDisplayList(&gfx[2]);
-// } else {
-// gSPClearGeometryMode(&gfx[0], G_CULL_FRONT);
-// gSPSetGeometryMode(&gfx[1], G_CULL_BACK);
-// gSPEndDisplayList(&gfx[2]);
-// }
-// asGenerated->fnNode.node.flags = (asGenerated->fnNode.node.flags & 0xFF) | (LAYER_OPAQUE << 8);
-// }
-// return gfx;
+ // if (asGenerated->parameter == 0) {
+ // gSPClearGeometryMode(&gfx[0], G_CULL_BACK);
+ // gSPSetGeometryMode(&gfx[1], G_CULL_FRONT);
+ // gSPEndDisplayList(&gfx[2]);
+ // } else {
+ // gSPClearGeometryMode(&gfx[0], G_CULL_FRONT);
+ // gSPSetGeometryMode(&gfx[1], G_CULL_BACK);
+ // gSPEndDisplayList(&gfx[2]);
+ // }
+ // asGenerated->fnNode.node.flags = (asGenerated->fnNode.node.flags & 0xFF) | (LAYER_OPAQUE << 8);
+ // }
+ // return gfx;
return NULL;
}
diff --git a/src/decomp/game/mario_misc.h b/src/decomp/game/mario_misc.h
index 85c1205..d18c6cc 100644
--- a/src/decomp/game/mario_misc.h
+++ b/src/decomp/game/mario_misc.h
@@ -8,21 +8,37 @@
// Gfx *geo_draw_mario_head_goddard(s32 callContext, struct GraphNode *node, Mat4 *c);
void bhv_toad_message_loop(void);
+
void bhv_toad_message_init(void);
+
void bhv_unlock_door_star_init(void);
+
void bhv_unlock_door_star_loop(void);
+
Gfx *geo_mirror_mario_set_alpha(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c);
+
Gfx *geo_switch_mario_stand_run(s32 callContext, struct GraphNode *node, UNUSED Mat4 *mtx);
+
Gfx *geo_switch_mario_eyes(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c);
+
Gfx *geo_mario_tilt_torso(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c);
+
Gfx *geo_mario_head_rotation(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c);
+
Gfx *geo_switch_mario_hand(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c);
+
Gfx *geo_mario_hand_foot_scaler(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c);
+
Gfx *geo_switch_mario_cap_effect(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c);
+
Gfx *geo_switch_mario_cap_on_off(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c);
+
Gfx *geo_mario_rotate_wing_cap_wings(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c);
+
Gfx *geo_switch_mario_hand_grab_pos(s32 callContext, struct GraphNode *b, Mat4 *mtx);
+
Gfx *geo_render_mirror_mario(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c);
+
Gfx *geo_mirror_mario_backface_culling(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c);
#endif // MARIO_MISC_H
diff --git a/src/decomp/game/mario_step.c b/src/decomp/game/mario_step.c
index 1bbbd41..0b9163b 100644
--- a/src/decomp/game/mario_step.c
+++ b/src/decomp/game/mario_step.c
@@ -8,11 +8,11 @@
#include "interaction.h"
#include "mario_step.h"
-static s16 sMovingSandSpeeds[] = { 12, 8, 4, 0 };
+static s16 sMovingSandSpeeds[] = {12, 8, 4, 0};
struct SM64SurfaceCollisionData gWaterSurfacePseudoFloor = {
- SURFACE_VERY_SLIPPERY, 0, 0, 0, 0, 0, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
- { 0.0f, 1.0f, 0.0f }, 0.0f, 0, NULL, 0
+ SURFACE_VERY_SLIPPERY, 0, 0, 0, 0, 0, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
+ {0.0f, 1.0f, 0.0f}, 0.0f, 0, NULL, 0
};
/**
@@ -25,7 +25,8 @@ struct SM64SurfaceCollisionData gWaterSurfacePseudoFloor = {
* known through stub_mario_step_2 and whether Mario was on it,
* and if so return a higher value than 0.
*/
-f32 get_additive_y_vel_for_jumps(void) {
+f32 get_additive_y_vel_for_jumps(void)
+{
return 0.0f;
}
@@ -38,7 +39,8 @@ f32 get_additive_y_vel_for_jumps(void) {
* this could be used for checking if Mario was on the trampoline.
* It could, for example, make him bounce.
*/
-void stub_mario_step_1(UNUSED struct MarioState *x) {
+void stub_mario_step_1(UNUSED struct MarioState * x)
+{
}
/**
@@ -48,10 +50,12 @@ void stub_mario_step_1(UNUSED struct MarioState *x) {
* by the trampoline to make itself known to get_additive_y_vel_for_jumps,
* or to set a variable with its intended additive Y vel.
*/
-void stub_mario_step_2(void) {
+void stub_mario_step_2(void)
+{
}
-void transfer_bully_speed(struct BullyCollisionData *obj1, struct BullyCollisionData *obj2) {
+void transfer_bully_speed(struct BullyCollisionData *obj1, struct BullyCollisionData *obj2)
+{
f32 rx = obj2->posX - obj1->posX;
f32 rz = obj2->posZ - obj1->posZ;
@@ -70,9 +74,12 @@ void transfer_bully_speed(struct BullyCollisionData *obj1, struct BullyCollision
//! Bully battery
}
-BAD_RETURN(s32) init_bully_collision_data(struct BullyCollisionData *data, f32 posX, f32 posZ,
- f32 forwardVel, s16 yaw, f32 conversionRatio, f32 radius) {
- if (forwardVel < 0.0f) {
+BAD_RETURN (s32) init_bully_collision_data(
+ struct BullyCollisionData *data, f32 posX, f32 posZ,
+ f32 forwardVel, s16 yaw, f32 conversionRatio, f32 radius)
+{
+ if (forwardVel < 0.0f)
+ {
forwardVel *= -1.0f;
yaw += 0x8000;
}
@@ -85,55 +92,72 @@ BAD_RETURN(s32) init_bully_collision_data(struct BullyCollisionData *data, f32 p
data->velZ = forwardVel * coss(yaw);
}
-void mario_bonk_reflection(struct MarioState *m, u32 negateSpeed) {
- if (m->wall != NULL) {
+void mario_bonk_reflection(struct MarioState *m, u32 negateSpeed)
+{
+ if (m->wall != NULL)
+ {
s16 wallAngle = atan2s(m->wall->normal.z, m->wall->normal.x);
m->faceAngle[1] = wallAngle - (s16)(m->faceAngle[1] - wallAngle);
- play_sound((m->flags & MARIO_METAL_CAP) ? SOUND_ACTION_METAL_BONK : SOUND_ACTION_BONK,
+ play_sound(m->flags & MARIO_METAL_CAP ? SOUND_ACTION_METAL_BONK : SOUND_ACTION_BONK,
m->marioObj->header.gfx.cameraToObject);
- } else {
+ }
+ else
+ {
play_sound(SOUND_ACTION_HIT, m->marioObj->header.gfx.cameraToObject);
}
- if (negateSpeed) {
+ if (negateSpeed)
+ {
mario_set_forward_vel(m, -m->forwardVel);
- } else {
+ }
+ else
+ {
m->faceAngle[1] += 0x8000;
}
}
-u32 mario_update_quicksand(struct MarioState *m, f32 sinkingSpeed) {
- if (m->action & ACT_FLAG_RIDING_SHELL) {
+u32 mario_update_quicksand(struct MarioState *m, f32 sinkingSpeed)
+{
+ if (m->action & ACT_FLAG_RIDING_SHELL)
+ {
m->quicksandDepth = 0.0f;
- } else {
- if (m->quicksandDepth < 1.1f) {
+ }
+ else
+ {
+ if (m->quicksandDepth < 1.1f)
+ {
m->quicksandDepth = 1.1f;
}
- switch (m->floor->type) {
+ switch (m->floor->type)
+ {
case SURFACE_SHALLOW_QUICKSAND:
- if ((m->quicksandDepth += sinkingSpeed) >= 10.0f) {
+ if ((m->quicksandDepth += sinkingSpeed) >= 10.0f)
+ {
m->quicksandDepth = 10.0f;
}
break;
case SURFACE_SHALLOW_MOVING_QUICKSAND:
- if ((m->quicksandDepth += sinkingSpeed) >= 25.0f) {
+ if ((m->quicksandDepth += sinkingSpeed) >= 25.0f)
+ {
m->quicksandDepth = 25.0f;
}
break;
case SURFACE_QUICKSAND:
case SURFACE_MOVING_QUICKSAND:
- if ((m->quicksandDepth += sinkingSpeed) >= 60.0f) {
+ if ((m->quicksandDepth += sinkingSpeed) >= 60.0f)
+ {
m->quicksandDepth = 60.0f;
}
break;
case SURFACE_DEEP_QUICKSAND:
case SURFACE_DEEP_MOVING_QUICKSAND:
- if ((m->quicksandDepth += sinkingSpeed) >= 160.0f) {
+ if ((m->quicksandDepth += sinkingSpeed) >= 160.0f)
+ {
update_mario_sound_and_camera(m);
return drop_and_set_mario_action(m, ACT_QUICKSAND_DEATH, 0);
}
@@ -154,13 +178,17 @@ u32 mario_update_quicksand(struct MarioState *m, f32 sinkingSpeed) {
return FALSE;
}
-u32 mario_push_off_steep_floor(struct MarioState *m, u32 action, u32 actionArg) {
+u32 mario_push_off_steep_floor(struct MarioState *m, u32 action, u32 actionArg)
+{
s16 floorDYaw = m->floorAngle - m->faceAngle[1];
- if (floorDYaw > -0x4000 && floorDYaw < 0x4000) {
+ if (floorDYaw > -0x4000 && floorDYaw < 0x4000)
+ {
m->forwardVel = 16.0f;
m->faceAngle[1] = m->floorAngle;
- } else {
+ }
+ else
+ {
m->forwardVel = -16.0f;
m->faceAngle[1] = m->floorAngle + 0x8000;
}
@@ -168,12 +196,14 @@ u32 mario_push_off_steep_floor(struct MarioState *m, u32 action, u32 actionArg)
return set_mario_action(m, action, actionArg);
}
-u32 mario_update_moving_sand(struct MarioState *m) {
+u32 mario_update_moving_sand(struct MarioState *m)
+{
struct SM64SurfaceCollisionData *floor = m->floor;
s32 floorType = floor->type;
if (floorType == SURFACE_DEEP_MOVING_QUICKSAND || floorType == SURFACE_SHALLOW_MOVING_QUICKSAND
- || floorType == SURFACE_MOVING_QUICKSAND || floorType == SURFACE_INSTANT_MOVING_QUICKSAND) {
+ || floorType == SURFACE_MOVING_QUICKSAND || floorType == SURFACE_INSTANT_MOVING_QUICKSAND)
+ {
s16 pushAngle = floor->force << 8;
f32 pushSpeed = sMovingSandSpeeds[floor->force >> 8];
@@ -186,40 +216,47 @@ u32 mario_update_moving_sand(struct MarioState *m) {
return FALSE;
}
-u32 mario_update_windy_ground(struct MarioState *m) {
+u32 mario_update_windy_ground(struct MarioState *m)
+{
struct SM64SurfaceCollisionData *floor = m->floor;
- if (floor->type == SURFACE_HORIZONTAL_WIND) {
+ if (floor->type == SURFACE_HORIZONTAL_WIND)
+ {
f32 pushSpeed;
s16 pushAngle = floor->force << 8;
- if (m->action & ACT_FLAG_MOVING) {
+ if (m->action & ACT_FLAG_MOVING)
+ {
s16 pushDYaw = m->faceAngle[1] - pushAngle;
pushSpeed = m->forwardVel > 0.0f ? -m->forwardVel * 0.5f : -8.0f;
- if (pushDYaw > -0x4000 && pushDYaw < 0x4000) {
+ if (pushDYaw > -0x4000 && pushDYaw < 0x4000)
+ {
pushSpeed *= -1.0f;
}
pushSpeed *= coss(pushDYaw);
- } else {
- pushSpeed = 3.2f + (gGlobalTimer % 4);
+ }
+ else
+ {
+ pushSpeed = 3.2f + gGlobalTimer % 4;
}
m->vel[0] += pushSpeed * sins(pushAngle);
m->vel[2] += pushSpeed * coss(pushAngle);
-#if VERSION_JP
+ #if VERSION_JP
play_sound(SOUND_ENV_WIND2, m->marioObj->header.gfx.cameraToObject);
-#endif
+ #endif
return TRUE;
}
return FALSE;
}
-void stop_and_set_height_to_floor(struct MarioState *m) {
+void stop_and_set_height_to_floor(struct MarioState *m)
+{
struct Object *marioObj = m->marioObj;
mario_set_forward_vel(m, 0.0f);
@@ -232,7 +269,8 @@ void stop_and_set_height_to_floor(struct MarioState *m) {
vec3s_set(marioObj->header.gfx.angle, 0, m->faceAngle[1], 0);
}
-s32 stationary_ground_step(struct MarioState *m) {
+s32 stationary_ground_step(struct MarioState *m)
+{
u32 takeStep;
struct Object *marioObj = m->marioObj;
u32 stepResult = GROUND_STEP_NONE;
@@ -241,9 +279,12 @@ s32 stationary_ground_step(struct MarioState *m) {
takeStep = mario_update_moving_sand(m);
takeStep |= mario_update_windy_ground(m);
- if (takeStep) {
+ if (takeStep)
+ {
stepResult = perform_ground_step(m);
- } else {
+ }
+ else
+ {
//! This is responsible for several stationary downwarps.
m->pos[1] = m->floorHeight;
@@ -254,8 +295,10 @@ s32 stationary_ground_step(struct MarioState *m) {
return stepResult;
}
-static s32 perform_ground_quarter_step(struct MarioState *m, Vec3f nextPos) {
- UNUSED struct SM64SurfaceCollisionData *lowerWall;
+static s32 perform_ground_quarter_step(struct MarioState *m, Vec3f nextPos)
+{
+ UNUSED
+ struct SM64SurfaceCollisionData *lowerWall;
struct SM64SurfaceCollisionData *upperWall;
struct SM64SurfaceCollisionData *ceil;
struct SM64SurfaceCollisionData *floor;
@@ -274,18 +317,22 @@ static s32 perform_ground_quarter_step(struct MarioState *m, Vec3f nextPos) {
m->wall = upperWall;
- if (floor == NULL) {
+ if (floor == NULL)
+ {
return GROUND_STEP_HIT_WALL_STOP_QSTEPS;
}
- if ((m->action & ACT_FLAG_RIDING_SHELL) && floorHeight < waterLevel) {
+ if (m->action & ACT_FLAG_RIDING_SHELL && floorHeight < waterLevel)
+ {
floorHeight = waterLevel;
floor = &gWaterSurfacePseudoFloor;
floor->originOffset = floorHeight; //! Wrong origin offset (no effect)
}
- if (nextPos[1] > floorHeight + 100.0f) {
- if (nextPos[1] + 160.0f >= ceilHeight) {
+ if (nextPos[1] > floorHeight + 100.0f)
+ {
+ if (nextPos[1] + 160.0f >= ceilHeight)
+ {
return GROUND_STEP_HIT_WALL_STOP_QSTEPS;
}
@@ -295,7 +342,8 @@ static s32 perform_ground_quarter_step(struct MarioState *m, Vec3f nextPos) {
return GROUND_STEP_LEFT_GROUND;
}
- if (floorHeight + 160.0f >= ceilHeight) {
+ if (floorHeight + 160.0f >= ceilHeight)
+ {
return GROUND_STEP_HIT_WALL_STOP_QSTEPS;
}
@@ -303,13 +351,16 @@ static s32 perform_ground_quarter_step(struct MarioState *m, Vec3f nextPos) {
m->floor = floor;
m->floorHeight = floorHeight;
- if (upperWall != NULL) {
+ if (upperWall != NULL)
+ {
s16 wallDYaw = atan2s(upperWall->normal.z, upperWall->normal.x) - m->faceAngle[1];
- if (wallDYaw >= 0x2AAA && wallDYaw <= 0x5555) {
+ if (wallDYaw >= 0x2AAA && wallDYaw <= 0x5555)
+ {
return GROUND_STEP_NONE;
}
- if (wallDYaw <= -0x2AAA && wallDYaw >= -0x5555) {
+ if (wallDYaw <= -0x2AAA && wallDYaw >= -0x5555)
+ {
return GROUND_STEP_NONE;
}
@@ -319,18 +370,21 @@ static s32 perform_ground_quarter_step(struct MarioState *m, Vec3f nextPos) {
return GROUND_STEP_NONE;
}
-s32 perform_ground_step(struct MarioState *m) {
+s32 perform_ground_step(struct MarioState *m)
+{
s32 i;
u32 stepResult;
Vec3f intendedPos;
- for (i = 0; i < 4; i++) {
+ for (i = 0; i < 4; i++)
+ {
intendedPos[0] = m->pos[0] + m->floor->normal.y * (m->vel[0] / 4.0f);
intendedPos[2] = m->pos[2] + m->floor->normal.y * (m->vel[2] / 4.0f);
intendedPos[1] = m->pos[1];
stepResult = perform_ground_quarter_step(m, intendedPos);
- if (stepResult == GROUND_STEP_LEFT_GROUND || stepResult == GROUND_STEP_HIT_WALL_STOP_QSTEPS) {
+ if (stepResult == GROUND_STEP_LEFT_GROUND || stepResult == GROUND_STEP_HIT_WALL_STOP_QSTEPS)
+ {
break;
}
}
@@ -339,19 +393,22 @@ s32 perform_ground_step(struct MarioState *m) {
vec3f_copy(m->marioObj->header.gfx.pos, m->pos);
vec3s_set(m->marioObj->header.gfx.angle, 0, m->faceAngle[1], 0);
- if (stepResult == GROUND_STEP_HIT_WALL_CONTINUE_QSTEPS) {
+ if (stepResult == GROUND_STEP_HIT_WALL_CONTINUE_QSTEPS)
+ {
stepResult = GROUND_STEP_HIT_WALL;
}
return stepResult;
}
-u32 check_ledge_grab(struct MarioState *m, struct SM64SurfaceCollisionData *wall, Vec3f intendedPos, Vec3f nextPos) {
+u32 check_ledge_grab(struct MarioState *m, struct SM64SurfaceCollisionData *wall, Vec3f intendedPos, Vec3f nextPos)
+{
struct SM64SurfaceCollisionData *ledgeFloor;
Vec3f ledgePos;
f32 displacementX;
f32 displacementZ;
- if (m->vel[1] > 0) {
+ if (m->vel[1] > 0)
+ {
return FALSE;
}
@@ -360,7 +417,8 @@ u32 check_ledge_grab(struct MarioState *m, struct SM64SurfaceCollisionData *wall
// Only ledge grab if the wall displaced Mario in the opposite direction of
// his velocity.
- if (displacementX * m->vel[0] + displacementZ * m->vel[2] > 0.0f) {
+ if (displacementX * m->vel[0] + displacementZ * m->vel[2] > 0.0f)
+ {
return FALSE;
}
@@ -370,7 +428,8 @@ u32 check_ledge_grab(struct MarioState *m, struct SM64SurfaceCollisionData *wall
ledgePos[2] = nextPos[2] - wall->normal.z * 60.0f;
ledgePos[1] = find_floor(ledgePos[0], nextPos[1] + 160.0f, ledgePos[2], &ledgeFloor);
- if (ledgePos[1] - nextPos[1] <= 100.0f) {
+ if (ledgePos[1] - nextPos[1] <= 100.0f)
+ {
return FALSE;
}
@@ -385,7 +444,8 @@ u32 check_ledge_grab(struct MarioState *m, struct SM64SurfaceCollisionData *wall
return TRUE;
}
-s32 perform_air_quarter_step(struct MarioState *m, Vec3f intendedPos, u32 stepArg) {
+s32 perform_air_quarter_step(struct MarioState *m, Vec3f intendedPos, u32 stepArg)
+{
s16 wallDYaw;
Vec3f nextPos;
struct SM64SurfaceCollisionData *upperWall;
@@ -412,8 +472,10 @@ s32 perform_air_quarter_step(struct MarioState *m, Vec3f intendedPos, u32 stepAr
//! The water pseudo floor is not referenced when your intended qstep is
// out of bounds, so it won't detect you as landing.
- if (floor == NULL) {
- if (nextPos[1] <= m->floorHeight) {
+ if (floor == NULL)
+ {
+ if (nextPos[1] <= m->floorHeight)
+ {
m->pos[1] = m->floorHeight;
return AIR_STEP_LANDED;
}
@@ -422,15 +484,18 @@ s32 perform_air_quarter_step(struct MarioState *m, Vec3f intendedPos, u32 stepAr
return AIR_STEP_HIT_WALL;
}
- if ((m->action & ACT_FLAG_RIDING_SHELL) && floorHeight < waterLevel) {
+ if (m->action & ACT_FLAG_RIDING_SHELL && floorHeight < waterLevel)
+ {
floorHeight = waterLevel;
floor = &gWaterSurfacePseudoFloor;
floor->originOffset = floorHeight; //! Incorrect origin offset (no effect)
}
//! This check uses f32, but findFloor uses short (overflow jumps)
- if (nextPos[1] <= floorHeight) {
- if (ceilHeight - floorHeight > 160.0f) {
+ if (nextPos[1] <= floorHeight)
+ {
+ if (ceilHeight - floorHeight > 160.0f)
+ {
m->pos[0] = nextPos[0];
m->pos[2] = nextPos[2];
m->floor = floor;
@@ -444,13 +509,16 @@ s32 perform_air_quarter_step(struct MarioState *m, Vec3f intendedPos, u32 stepAr
return AIR_STEP_LANDED;
}
- if (nextPos[1] + 160.0f > ceilHeight) {
- if (m->vel[1] >= 0.0f) {
+ if (nextPos[1] + 160.0f > ceilHeight)
+ {
+ if (m->vel[1] >= 0.0f)
+ {
m->vel[1] = 0.0f;
//! Uses referenced ceiling instead of ceil (ceiling hang upwarp)
- if ((stepArg & AIR_STEP_CHECK_HANG) && m->ceil != NULL
- && m->ceil->type == SURFACE_HANGABLE) {
+ if (stepArg & AIR_STEP_CHECK_HANG && m->ceil != NULL
+ && m->ceil->type == SURFACE_HANGABLE)
+ {
return AIR_STEP_GRABBED_CEILING;
}
@@ -458,7 +526,8 @@ s32 perform_air_quarter_step(struct MarioState *m, Vec3f intendedPos, u32 stepAr
}
//! Potential subframe downwarp->upwarp?
- if (nextPos[1] <= m->floorHeight) {
+ if (nextPos[1] <= m->floorHeight)
+ {
m->pos[1] = m->floorHeight;
return AIR_STEP_LANDED;
}
@@ -469,8 +538,10 @@ s32 perform_air_quarter_step(struct MarioState *m, Vec3f intendedPos, u32 stepAr
//! When the wall is not completely vertical or there is a slight wall
// misalignment, you can activate these conditions in unexpected situations
- if ((stepArg & AIR_STEP_CHECK_LEDGE_GRAB) && upperWall == NULL && lowerWall != NULL) {
- if (check_ledge_grab(m, lowerWall, intendedPos, nextPos)) {
+ if (stepArg & AIR_STEP_CHECK_LEDGE_GRAB && upperWall == NULL && lowerWall != NULL)
+ {
+ if (check_ledge_grab(m, lowerWall, intendedPos, nextPos))
+ {
return AIR_STEP_GRABBED_LEDGE;
}
@@ -484,15 +555,18 @@ s32 perform_air_quarter_step(struct MarioState *m, Vec3f intendedPos, u32 stepAr
m->floor = floor;
m->floorHeight = floorHeight;
- if (upperWall != NULL || lowerWall != NULL) {
+ if (upperWall != NULL || lowerWall != NULL)
+ {
m->wall = upperWall != NULL ? upperWall : lowerWall;
wallDYaw = atan2s(m->wall->normal.z, m->wall->normal.x) - m->faceAngle[1];
- if (m->wall->type == SURFACE_BURNING) {
+ if (m->wall->type == SURFACE_BURNING)
+ {
return AIR_STEP_HIT_LAVA_WALL;
}
- if (wallDYaw < -0x6000 || wallDYaw > 0x6000) {
+ if (wallDYaw < -0x6000 || wallDYaw > 0x6000)
+ {
m->flags |= MARIO_UNKNOWN_30;
return AIR_STEP_HIT_WALL;
}
@@ -501,114 +575,156 @@ s32 perform_air_quarter_step(struct MarioState *m, Vec3f intendedPos, u32 stepAr
return AIR_STEP_NONE;
}
-void apply_twirl_gravity(struct MarioState *m) {
+void apply_twirl_gravity(struct MarioState *m)
+{
f32 terminalVelocity;
f32 heaviness = 1.0f;
- if (m->angleVel[1] > 1024) {
+ if (m->angleVel[1] > 1024)
+ {
heaviness = 1024.0f / m->angleVel[1];
}
terminalVelocity = -75.0f * heaviness;
m->vel[1] -= 4.0f * heaviness;
- if (m->vel[1] < terminalVelocity) {
+ if (m->vel[1] < terminalVelocity)
+ {
m->vel[1] = terminalVelocity;
}
}
-u32 should_strengthen_gravity_for_jump_ascent(struct MarioState *m) {
- if (!(m->flags & MARIO_UNKNOWN_08)) {
+u32 should_strengthen_gravity_for_jump_ascent(struct MarioState *m)
+{
+ if (!(m->flags & MARIO_UNKNOWN_08))
+ {
return FALSE;
}
- if (m->action & (ACT_FLAG_INTANGIBLE | ACT_FLAG_INVULNERABLE)) {
+ if (m->action & (ACT_FLAG_INTANGIBLE | ACT_FLAG_INVULNERABLE))
+ {
return FALSE;
}
- if (!(m->input & INPUT_A_DOWN) && m->vel[1] > 20.0f) {
+ if (!(m->input & INPUT_A_DOWN) && m->vel[1] > 20.0f)
+ {
return (m->action & ACT_FLAG_CONTROL_JUMP_HEIGHT) != 0;
}
return FALSE;
}
-void apply_gravity(struct MarioState *m) {
- if (m->action == ACT_TWIRLING && m->vel[1] < 0.0f) {
+void apply_gravity(struct MarioState *m)
+{
+ if (m->action == ACT_TWIRLING && m->vel[1] < 0.0f)
+ {
apply_twirl_gravity(m);
- } else if (m->action == ACT_SHOT_FROM_CANNON) {
+ }
+ else if (m->action == ACT_SHOT_FROM_CANNON)
+ {
m->vel[1] -= 1.0f;
- if (m->vel[1] < -75.0f) {
+ if (m->vel[1] < -75.0f)
+ {
m->vel[1] = -75.0f;
}
- } else if (m->action == ACT_LONG_JUMP || m->action == ACT_SLIDE_KICK
- || m->action == ACT_BBH_ENTER_SPIN) {
+ }
+ else if (m->action == ACT_LONG_JUMP || m->action == ACT_SLIDE_KICK
+ || m->action == ACT_BBH_ENTER_SPIN)
+ {
m->vel[1] -= 2.0f;
- if (m->vel[1] < -75.0f) {
+ if (m->vel[1] < -75.0f)
+ {
m->vel[1] = -75.0f;
}
- } else if (m->action == ACT_LAVA_BOOST || m->action == ACT_FALL_AFTER_STAR_GRAB) {
+ }
+ else if (m->action == ACT_LAVA_BOOST || m->action == ACT_FALL_AFTER_STAR_GRAB)
+ {
m->vel[1] -= 3.2f;
- if (m->vel[1] < -65.0f) {
+ if (m->vel[1] < -65.0f)
+ {
m->vel[1] = -65.0f;
}
- } else if (m->action == ACT_GETTING_BLOWN) {
+ }
+ else if (m->action == ACT_GETTING_BLOWN)
+ {
m->vel[1] -= m->unkC4;
- if (m->vel[1] < -75.0f) {
+ if (m->vel[1] < -75.0f)
+ {
m->vel[1] = -75.0f;
}
- } else if (should_strengthen_gravity_for_jump_ascent(m)) {
+ }
+ else if (should_strengthen_gravity_for_jump_ascent(m))
+ {
m->vel[1] /= 4.0f;
- } else if (m->action & ACT_FLAG_METAL_WATER) {
+ }
+ else if (m->action & ACT_FLAG_METAL_WATER)
+ {
m->vel[1] -= 1.6f;
- if (m->vel[1] < -16.0f) {
+ if (m->vel[1] < -16.0f)
+ {
m->vel[1] = -16.0f;
}
- } else if ((m->flags & MARIO_WING_CAP) && m->vel[1] < 0.0f && (m->input & INPUT_A_DOWN)) {
+ }
+ else if (m->flags & MARIO_WING_CAP && m->vel[1] < 0.0f && m->input & INPUT_A_DOWN)
+ {
m->marioBodyState->wingFlutter = TRUE;
m->vel[1] -= 2.0f;
- if (m->vel[1] < -37.5f) {
- if ((m->vel[1] += 4.0f) > -37.5f) {
+ if (m->vel[1] < -37.5f)
+ {
+ if ((m->vel[1] += 4.0f) > -37.5f)
+ {
m->vel[1] = -37.5f;
}
}
- } else {
+ }
+ else
+ {
m->vel[1] -= 4.0f;
- if (m->vel[1] < -75.0f) {
+ if (m->vel[1] < -75.0f)
+ {
m->vel[1] = -75.0f;
}
}
}
-void apply_vertical_wind(struct MarioState *m) {
+void apply_vertical_wind(struct MarioState *m)
+{
f32 maxVelY;
f32 offsetY;
- if (m->action != ACT_GROUND_POUND) {
+ if (m->action != ACT_GROUND_POUND)
+ {
offsetY = m->pos[1] - -1500.0f;
- if (m->floor->type == SURFACE_VERTICAL_WIND && -3000.0f < offsetY && offsetY < 2000.0f) {
- if (offsetY >= 0.0f) {
+ if (m->floor->type == SURFACE_VERTICAL_WIND && -3000.0f < offsetY && offsetY < 2000.0f)
+ {
+ if (offsetY >= 0.0f)
+ {
maxVelY = 10000.0f / (offsetY + 200.0f);
- } else {
+ }
+ else
+ {
maxVelY = 50.0f;
}
- if (m->vel[1] < maxVelY) {
- if ((m->vel[1] += maxVelY / 8.0f) > maxVelY) {
+ if (m->vel[1] < maxVelY)
+ {
+ if ((m->vel[1] += maxVelY / 8.0f) > maxVelY)
+ {
m->vel[1] = maxVelY;
}
}
-#ifdef VERSION_JP
+ #ifdef VERSION_JP
play_sound(SOUND_ENV_WIND2, m->marioObj->header.gfx.cameraToObject);
-#endif
+ #endif
}
}
}
-s32 perform_air_step(struct MarioState *m, u32 stepArg) {
+s32 perform_air_step(struct MarioState *m, u32 stepArg)
+{
Vec3f intendedPos;
s32 i;
s32 quarterStepResult;
@@ -616,7 +732,8 @@ s32 perform_air_step(struct MarioState *m, u32 stepArg) {
m->wall = NULL;
- for (i = 0; i < 4; i++) {
+ for (i = 0; i < 4; i++)
+ {
intendedPos[0] = m->pos[0] + m->vel[0] / 4.0f;
intendedPos[1] = m->pos[1] + m->vel[1] / 4.0f;
intendedPos[2] = m->pos[2] + m->vel[2] / 4.0f;
@@ -627,24 +744,28 @@ s32 perform_air_step(struct MarioState *m, u32 stepArg) {
// getting 0s until your last qf. Graze a wall on your last qf, and it will
// return the stored 2 with a sharply angled reference wall. (some gwks)
- if (quarterStepResult != AIR_STEP_NONE) {
+ if (quarterStepResult != AIR_STEP_NONE)
+ {
stepResult = quarterStepResult;
}
if (quarterStepResult == AIR_STEP_LANDED || quarterStepResult == AIR_STEP_GRABBED_LEDGE
|| quarterStepResult == AIR_STEP_GRABBED_CEILING
- || quarterStepResult == AIR_STEP_HIT_LAVA_WALL) {
+ || quarterStepResult == AIR_STEP_HIT_LAVA_WALL)
+ {
break;
}
}
- if (m->vel[1] >= 0.0f) {
+ if (m->vel[1] >= 0.0f)
+ {
m->peakHeight = m->pos[1];
}
m->terrainSoundAddend = mario_get_terrain_sound_addend(m);
- if (m->action != ACT_FLYING) {
+ if (m->action != ACT_FLYING)
+ {
apply_gravity(m);
}
apply_vertical_wind(m);
@@ -657,13 +778,15 @@ s32 perform_air_step(struct MarioState *m, u32 stepArg) {
// They had these functions the whole time and never used them? Lol
-void set_vel_from_pitch_and_yaw(struct MarioState *m) {
+void set_vel_from_pitch_and_yaw(struct MarioState *m)
+{
m->vel[0] = m->forwardVel * coss(m->faceAngle[0]) * sins(m->faceAngle[1]);
m->vel[1] = m->forwardVel * sins(m->faceAngle[0]);
m->vel[2] = m->forwardVel * coss(m->faceAngle[0]) * coss(m->faceAngle[1]);
}
-void set_vel_from_yaw(struct MarioState *m) {
+void set_vel_from_yaw(struct MarioState *m)
+{
m->vel[0] = m->slideVelX = m->forwardVel * sins(m->faceAngle[1]);
m->vel[1] = 0.0f;
m->vel[2] = m->slideVelZ = m->forwardVel * coss(m->faceAngle[1]);
diff --git a/src/decomp/game/mario_step.h b/src/decomp/game/mario_step.h
index 538da84..fbd7e95 100644
--- a/src/decomp/game/mario_step.h
+++ b/src/decomp/game/mario_step.h
@@ -5,32 +5,52 @@
#include "../include/types.h"
-struct BullyCollisionData {
- /*0x00*/ f32 conversionRatio;
- /*0x04*/ f32 radius;
- /*0x08*/ f32 posX;
- /*0x0C*/ f32 posZ;
- /*0x10*/ f32 velX;
- /*0x14*/ f32 velZ;
+struct BullyCollisionData
+{
+ /*0x00*/
+ f32 conversionRatio;
+ /*0x04*/
+ f32 radius;
+ /*0x08*/
+ f32 posX;
+ /*0x0C*/
+ f32 posZ;
+ /*0x10*/
+ f32 velX;
+ /*0x14*/
+ f32 velZ;
};
extern struct SM64SurfaceCollisionData gWaterSurfacePseudoFloor;
f32 get_additive_y_vel_for_jumps(void);
+
void stub_mario_step_1(struct MarioState *);
+
void stub_mario_step_2(void);
void mario_bonk_reflection(struct MarioState *, u32);
+
void transfer_bully_speed(struct BullyCollisionData *obj1, struct BullyCollisionData *obj2);
-BAD_RETURN(s32) init_bully_collision_data(struct BullyCollisionData *data, f32 posX, f32 posZ,
- f32 forwardVel, s16 yaw, f32 conversionRatio, f32 radius);
+
+BAD_RETURN (s32) init_bully_collision_data(
+ struct BullyCollisionData *data, f32 posX, f32 posZ,
+ f32 forwardVel, s16 yaw, f32 conversionRatio, f32 radius);
+
u32 mario_update_quicksand(struct MarioState *, f32);
+
u32 mario_push_off_steep_floor(struct MarioState *, u32, u32);
+
u32 mario_update_moving_sand(struct MarioState *);
+
u32 mario_update_windy_ground(struct MarioState *);
+
void stop_and_set_height_to_floor(struct MarioState *);
+
s32 stationary_ground_step(struct MarioState *);
+
s32 perform_ground_step(struct MarioState *);
+
s32 perform_air_step(struct MarioState *, u32);
#endif // MARIO_STEP_H
\ No newline at end of file
diff --git a/src/decomp/game/object_stuff.c b/src/decomp/game/object_stuff.c
index 90c1a8b..d46e088 100644
--- a/src/decomp/game/object_stuff.c
+++ b/src/decomp/game/object_stuff.c
@@ -8,18 +8,20 @@
#include "../engine/math_util.h"
#include "../include/object_fields.h"
-static Vec3f gVec3fZero = { 0.0f, 0.0f, 0.0f };
-static Vec3s gVec3sZero = { 0, 0, 0 };
+static Vec3f gVec3fZero = {0.0f, 0.0f, 0.0f};
+static Vec3s gVec3sZero = {0, 0, 0};
-static struct Object *try_allocate_object(void) {
+static struct Object *try_allocate_object(void)
+{
struct ObjectNode *nextObj;
- nextObj = (struct ObjectNode *) malloc(sizeof(struct Object));
+ nextObj = (struct ObjectNode *)malloc(sizeof(struct Object));
nextObj->prev = NULL;
nextObj->next = NULL;
- return (struct Object *) nextObj;
+ return (struct Object *)nextObj;
}
-static struct Object *allocate_object(void) {
+static struct Object *allocate_object(void)
+{
s32 i;
struct Object *obj = try_allocate_object();
@@ -31,21 +33,22 @@ static struct Object *allocate_object(void) {
obj->collidedObjInteractTypes = 0;
obj->numCollidedObjs = 0;
- for (i = 0; i < 0x50; i++) {
-#ifdef _WIN32
+ for (i = 0; i < 0x50; i++)
+ {
+ #ifdef _WIN32
obj->rawData.asS32[i] = 0;
-#endif
-#ifdef _WIN64
+ #endif
+ #ifdef _WIN64
obj->ptrData.asVoidPtr[i] = NULL;
-#endif
+ #endif
}
obj->unused1 = 0;
obj->bhvStackIndex = 0;
obj->bhvDelayTimer = 0;
- obj->hitboxRadius = 37.0f; // Override directly for Mario
- obj->hitboxHeight = 160.0f; //
+ obj->hitboxRadius = 37.0f; // Override directly for Mario
+ obj->hitboxHeight = 160.0f; //
obj->hurtboxRadius = 0.0f;
obj->hurtboxHeight = 0.0f;
obj->hitboxDownOffset = 0.0f;
@@ -58,9 +61,12 @@ static struct Object *allocate_object(void) {
obj->oHealth = 2048;
obj->oCollisionDistance = 1000.0f;
- if (gCurrLevelNum == LEVEL_TTC) {
+ if (gCurrLevelNum == LEVEL_TTC)
+ {
obj->oDrawingDistance = 2000.0f;
- } else {
+ }
+ else
+ {
obj->oDrawingDistance = 4000.0f;
}
@@ -81,7 +87,8 @@ static struct Object *allocate_object(void) {
return obj;
}
-static struct Object *create_object(void) {
+static struct Object *create_object(void)
+{
struct Object *obj;
obj = allocate_object();
obj->curBhvCommand = NULL;
@@ -89,7 +96,8 @@ static struct Object *create_object(void) {
return obj;
}
-static void geo_obj_init(struct GraphNodeObject *graphNode, void *sharedChild, Vec3f pos, Vec3s angle) {
+static void geo_obj_init(struct GraphNodeObject *graphNode, void *sharedChild, Vec3f pos, Vec3s angle)
+{
vec3f_set(graphNode->scale, 1.0f, 1.0f, 1.0f);
vec3f_copy(graphNode->pos, pos);
vec3s_copy(graphNode->angle, angle);
@@ -105,14 +113,15 @@ static void geo_obj_init(struct GraphNodeObject *graphNode, void *sharedChild, V
graphNode->node.flags &= ~GRAPH_RENDER_BILLBOARD;
}
-static struct Object *spawn_object_at_origin(void) {
+static struct Object *spawn_object_at_origin(void)
+{
struct Object *obj;
obj = create_object();
obj->parentObj = NULL;
obj->header.gfx.areaIndex = 0;
obj->header.gfx.activeAreaIndex = 0;
- geo_obj_init((struct GraphNodeObject *) &obj->header.gfx, NULL, gVec3fZero, gVec3sZero);
+ geo_obj_init(&obj->header.gfx, NULL, gVec3fZero, gVec3sZero);
return obj;
}
@@ -121,10 +130,12 @@ static struct Object *spawn_object_at_origin(void) {
* Copy position, velocity, and angle variables from MarioState to the Mario
* object.
*/
-static void copy_mario_state_to_object(void) {
+static void copy_mario_state_to_object(void)
+{
s32 i = 0;
// L is real
- if (gCurrentObject != gMarioObject) {
+ if (gCurrentObject != gMarioObject)
+ {
i += 1;
}
@@ -157,11 +168,12 @@ struct Object *hack_allocate_mario(void)
/**
* Mario's primary behavior update function.
*/
-void bhv_mario_update(void) {
+void bhv_mario_update(void)
+{
u32 particleFlags = 0;
-// s32 i;
+ // s32 i;
- gCurrentObject = gMarioObject;
+ gCurrentObject = gMarioObject;
particleFlags = execute_mario_action(gCurrentObject);
gCurrentObject->oMarioParticleFlags = particleFlags;
@@ -169,18 +181,19 @@ void bhv_mario_update(void) {
// to sync it with the Mario object
copy_mario_state_to_object();
-// i = 0;
-// while (sParticleTypes[i].particleFlag != 0) {
-// if (particleFlags & sParticleTypes[i].particleFlag) {
-// spawn_particle(sParticleTypes[i].activeParticleFlag, sParticleTypes[i].model,
-// sParticleTypes[i].behavior);
-// }
+ // i = 0;
+ // while (sParticleTypes[i].particleFlag != 0) {
+ // if (particleFlags & sParticleTypes[i].particleFlag) {
+ // spawn_particle(sParticleTypes[i].activeParticleFlag, sParticleTypes[i].model,
+ // sParticleTypes[i].behavior);
+ // }
-// i++;
-// }
+ // i++;
+ // }
}
-void create_transformation_from_matrices(Mat4 a0, Mat4 a1, Mat4 a2) {
+void create_transformation_from_matrices(Mat4 a0, Mat4 a1, Mat4 a2)
+{
f32 spC, sp8, sp4;
spC = a2[3][0] * a2[0][0] + a2[3][1] * a2[0][1] + a2[3][2] * a2[0][2];
@@ -208,7 +221,9 @@ void create_transformation_from_matrices(Mat4 a0, Mat4 a1, Mat4 a2) {
a0[2][3] = 0;
a0[3][3] = 1.0f;
}
-void obj_update_pos_from_parent_transformation(Mat4 a0, struct Object *a1) {
+
+void obj_update_pos_from_parent_transformation(Mat4 a0, struct Object *a1)
+{
f32 spC = a1->oParentRelativePosX;
f32 sp8 = a1->oParentRelativePosY;
f32 sp4 = a1->oParentRelativePosZ;
@@ -217,8 +232,10 @@ void obj_update_pos_from_parent_transformation(Mat4 a0, struct Object *a1) {
a1->oPosY = spC * a0[0][1] + sp8 * a0[1][1] + sp4 * a0[2][1] + a0[3][1];
a1->oPosZ = spC * a0[0][2] + sp8 * a0[1][2] + sp4 * a0[2][2] + a0[3][2];
}
-void obj_set_gfx_pos_from_pos(struct Object *obj) {
+
+void obj_set_gfx_pos_from_pos(struct Object *obj)
+{
obj->header.gfx.pos[0] = obj->oPosX;
obj->header.gfx.pos[1] = obj->oPosY;
obj->header.gfx.pos[2] = obj->oPosZ;
-}
\ No newline at end of file
+}
diff --git a/src/decomp/game/object_stuff.h b/src/decomp/game/object_stuff.h
index 0c1c205..58a4bc2 100644
--- a/src/decomp/game/object_stuff.h
+++ b/src/decomp/game/object_stuff.h
@@ -53,7 +53,11 @@
#define GRAPH_RENDER_HAS_ANIMATION (1 << 5)
struct Object *hack_allocate_mario(void);
+
void bhv_mario_update(void);
+
void create_transformation_from_matrices(Mat4 a0, Mat4 a1, Mat4 a2);
+
void obj_update_pos_from_parent_transformation(Mat4 a0, struct Object *a1);
+
void obj_set_gfx_pos_from_pos(struct Object *obj);
\ No newline at end of file
diff --git a/src/decomp/game/platform_displacement.c b/src/decomp/game/platform_displacement.c
index 2c93f15..e3a5300 100644
--- a/src/decomp/game/platform_displacement.c
+++ b/src/decomp/game/platform_displacement.c
@@ -16,16 +16,13 @@
* Determine if Mario is standing on a platform object, meaning that he is
* within 4 units of the floor. Set his referenced platform object accordingly.
*/
-void update_mario_platform(void) {
+void update_mario_platform(void)
+{
struct SM64SurfaceCollisionData *floor;
UNUSED u32 unused;
- f32 marioX;
- f32 marioY;
- f32 marioZ;
- f32 floorHeight;
- u32 awayFromFloor;
- if (gMarioObject == NULL) {
+ if (gMarioObject == NULL)
+ {
return;
}
@@ -34,26 +31,34 @@ void update_mario_platform(void) {
// of displacement since he is considered to be far from the platform's
// axis of rotation.
- marioX = gMarioObject->oPosX;
- marioY = gMarioObject->oPosY;
- marioZ = gMarioObject->oPosZ;
- floorHeight = find_floor(marioX, marioY, marioZ, &floor);
+ f32 marioX = gMarioObject->oPosX;
+ f32 marioY = gMarioObject->oPosY;
+ f32 marioZ = gMarioObject->oPosZ;
+ f32 floorHeight = find_floor(marioX, marioY, marioZ, &floor);
- if (absfx(marioY - floorHeight) < 4.0f) {
+ u32 awayFromFloor;
+
+ if (absfx(marioY - floorHeight) < 4.0f)
+ {
awayFromFloor = 0;
- } else {
+ }
+ else
+ {
awayFromFloor = 1;
}
- switch (awayFromFloor) {
+ switch (awayFromFloor)
+ {
case 1:
gMarioObject->platform = NULL;
break;
-
case 0:
- if (floor != NULL && floor->transform != NULL) {
+ if (floor != NULL && floor->transform != NULL)
+ {
gMarioObject->platform = floor->transform;
- } else {
+ }
+ else
+ {
gMarioObject->platform = NULL;
}
break;
@@ -63,7 +68,8 @@ void update_mario_platform(void) {
/**
* Get Mario's position and store it in x, y, and z.
*/
-static void get_mario_pos(f32 *x, f32 *y, f32 *z) {
+static void get_mario_pos(f32 *x, f32 *y, f32 *z)
+{
*x = gMarioState->pos[0];
*y = gMarioState->pos[1];
*z = gMarioState->pos[2];
@@ -72,7 +78,8 @@ static void get_mario_pos(f32 *x, f32 *y, f32 *z) {
/**
* Set Mario's position.
*/
-static void set_mario_pos(f32 x, f32 y, f32 z) {
+static void set_mario_pos(f32 x, f32 y, f32 z)
+{
gMarioState->pos[0] = x;
gMarioState->pos[1] = y;
gMarioState->pos[2] = z;
@@ -82,13 +89,11 @@ static void set_mario_pos(f32 x, f32 y, f32 z) {
* Apply one frame of platform rotation to Mario or an object using the given
* platform. If isMario is false, use gCurrentObject.
*/
-void apply_platform_displacement(u32 isMario, struct SM64SurfaceObjectTransform *platform) {
+void apply_platform_displacement(u32 isMario, struct SM64SurfaceObjectTransform *platform)
+{
f32 x;
f32 y;
f32 z;
- f32 platformPosX;
- f32 platformPosY;
- f32 platformPosZ;
Vec3f currentObjectOffset;
Vec3f relativeOffset;
Vec3f newObjectOffset;
@@ -102,30 +107,32 @@ void apply_platform_displacement(u32 isMario, struct SM64SurfaceObjectTransform
rotation[1] = platform->aAngleVelYaw;
rotation[2] = platform->aAngleVelRoll;
-// if (isMario) {
-// D_8032FEC0 = 0;
- get_mario_pos(&x, &y, &z);
-// } else {
-// x = gCurrentObject->aPosX;
-// y = gCurrentObject->aPosY;
-// z = gCurrentObject->aPosZ;
-// }
+ // if (isMario) {
+ // D_8032FEC0 = 0;
+ get_mario_pos(&x, &y, &z);
+ // } else {
+ // x = gCurrentObject->aPosX;
+ // y = gCurrentObject->aPosY;
+ // z = gCurrentObject->aPosZ;
+ // }
x += platform->aVelX;
z += platform->aVelZ;
- if (rotation[0] != 0 || rotation[1] != 0 || rotation[2] != 0) {
+ if (rotation[0] != 0 || rotation[1] != 0 || rotation[2] != 0)
+ {
unused1 = rotation[0];
unused2 = rotation[2];
unused3 = platform->aFaceAngleYaw;
- if (isMario) {
+ if (isMario)
+ {
gMarioState->faceAngle[1] += rotation[1];
}
- platformPosX = platform->aPosX;
- platformPosY = platform->aPosY;
- platformPosZ = platform->aPosZ;
+ f32 platformPosX = platform->aPosX;
+ f32 platformPosY = platform->aPosY;
+ f32 platformPosZ = platform->aPosZ;
currentObjectOffset[0] = x - platformPosX;
currentObjectOffset[1] = y - platformPosY;
@@ -150,20 +157,22 @@ void apply_platform_displacement(u32 isMario, struct SM64SurfaceObjectTransform
z = platformPosZ + newObjectOffset[2];
}
-// if (isMario) {
- set_mario_pos(x, y, z);
-// } else {
-// gCurrentObject->oPosX = x;
-// gCurrentObject->oPosY = y;
-// gCurrentObject->oPosZ = z;
-// }
+ // if (isMario) {
+ set_mario_pos(x, y, z);
+ // } else {
+ // gCurrentObject->oPosX = x;
+ // gCurrentObject->oPosY = y;
+ // gCurrentObject->oPosZ = z;
+ // }
}
/**
* If Mario's platform is not null, apply platform displacement.
*/
-void apply_mario_platform_displacement(void) {
- if (gMarioObject != NULL && gMarioObject->platform != NULL) {
+void apply_mario_platform_displacement(void)
+{
+ if (gMarioObject != NULL && gMarioObject->platform != NULL)
+ {
apply_platform_displacement(TRUE, gMarioObject->platform);
}
}
\ No newline at end of file
diff --git a/src/decomp/game/platform_displacement.h b/src/decomp/game/platform_displacement.h
index 3eb182d..6e7497a 100644
--- a/src/decomp/game/platform_displacement.h
+++ b/src/decomp/game/platform_displacement.h
@@ -5,6 +5,7 @@
#include "../include/types.h"
void update_mario_platform(void);
+
void apply_mario_platform_displacement(void);
#endif // PLATFORM_DISPLACEMENT_H
diff --git a/src/decomp/game/rendering_graph_node.c b/src/decomp/game/rendering_graph_node.c
index 97bfed4..11d29f2 100644
--- a/src/decomp/game/rendering_graph_node.c
+++ b/src/decomp/game/rendering_graph_node.c
@@ -17,18 +17,16 @@
#include "../../gfx_adapter.h"
-
#include "../mario/model.inc.h"
// PATCH
-static Vec3s gVec3sZero = { 0, 0, 0 };
-static Vec3f gVec3fZero = { 0, 0, 0 };
+static Vec3s gVec3sZero = {0, 0, 0};
+static Vec3f gVec3fZero = {0, 0, 0};
static Gfx *gDisplayListHead;
#define USE_SYSTEM_MALLOC
-
/**
* This file contains the code that processes the scene graph for rendering.
* The scene graph is responsible for drawing everything except the HUD / text boxes.
@@ -63,13 +61,20 @@ Mtx *gMatStackFixed[32];
* the animation state so a 'context switch' can be made when rendering the
* held object.
*/
-struct GeoAnimState {
- /*0x00*/ u8 type;
- /*0x01*/ u8 enabled;
- /*0x02*/ s16 frame;
- /*0x04*/ f32 translationMultiplier;
- /*0x08*/ u16 *attribute;
- /*0x0C*/ s16 *data;
+struct GeoAnimState
+{
+ /*0x00*/
+ u8 type;
+ /*0x01*/
+ u8 enabled;
+ /*0x02*/
+ s16 frame;
+ /*0x04*/
+ f32 translationMultiplier;
+ /*0x08*/
+ u16 *attribute;
+ /*0x0C*/
+ s16 *data;
};
// For some reason, this is a GeoAnimState struct, but the current state consists
@@ -85,55 +90,68 @@ s16 *gCurAnimData;
struct AllocOnlyPool *gDisplayListHeap;
-struct RenderModeContainer {
+struct RenderModeContainer
+{
u32 modes[8];
};
/* Rendermode settings for cycle 1 for all 8 layers. */
-struct RenderModeContainer renderModeTable_1Cycle[2] = { { {
- G_RM_OPA_SURF,
- G_RM_AA_OPA_SURF,
- G_RM_AA_OPA_SURF,
- G_RM_AA_OPA_SURF,
- G_RM_AA_TEX_EDGE,
- G_RM_AA_XLU_SURF,
- G_RM_AA_XLU_SURF,
- G_RM_AA_XLU_SURF,
- } },
- { {
- /* z-buffered */
- G_RM_ZB_OPA_SURF,
- G_RM_AA_ZB_OPA_SURF,
- G_RM_AA_ZB_OPA_DECAL,
- G_RM_AA_ZB_OPA_INTER,
- G_RM_AA_ZB_TEX_EDGE,
- G_RM_AA_ZB_XLU_SURF,
- G_RM_AA_ZB_XLU_DECAL,
- G_RM_AA_ZB_XLU_INTER,
- } } };
+struct RenderModeContainer renderModeTable_1Cycle[2] = {
+ {
+ {
+ G_RM_OPA_SURF,
+ G_RM_AA_OPA_SURF,
+ G_RM_AA_OPA_SURF,
+ G_RM_AA_OPA_SURF,
+ G_RM_AA_TEX_EDGE,
+ G_RM_AA_XLU_SURF,
+ G_RM_AA_XLU_SURF,
+ G_RM_AA_XLU_SURF,
+ }
+ },
+ {
+ {
+ /* z-buffered */
+ G_RM_ZB_OPA_SURF,
+ G_RM_AA_ZB_OPA_SURF,
+ G_RM_AA_ZB_OPA_DECAL,
+ G_RM_AA_ZB_OPA_INTER,
+ G_RM_AA_ZB_TEX_EDGE,
+ G_RM_AA_ZB_XLU_SURF,
+ G_RM_AA_ZB_XLU_DECAL,
+ G_RM_AA_ZB_XLU_INTER,
+ }
+ }
+};
/* Rendermode settings for cycle 2 for all 8 layers. */
-struct RenderModeContainer renderModeTable_2Cycle[2] = { { {
- G_RM_OPA_SURF2,
- G_RM_AA_OPA_SURF2,
- G_RM_AA_OPA_SURF2,
- G_RM_AA_OPA_SURF2,
- G_RM_AA_TEX_EDGE2,
- G_RM_AA_XLU_SURF2,
- G_RM_AA_XLU_SURF2,
- G_RM_AA_XLU_SURF2,
- } },
- { {
- /* z-buffered */
- G_RM_ZB_OPA_SURF2,
- G_RM_AA_ZB_OPA_SURF2,
- G_RM_AA_ZB_OPA_DECAL2,
- G_RM_AA_ZB_OPA_INTER2,
- G_RM_AA_ZB_TEX_EDGE2,
- G_RM_AA_ZB_XLU_SURF2,
- G_RM_AA_ZB_XLU_DECAL2,
- G_RM_AA_ZB_XLU_INTER2,
- } } };
+struct RenderModeContainer renderModeTable_2Cycle[2] = {
+ {
+ {
+ G_RM_OPA_SURF2,
+ G_RM_AA_OPA_SURF2,
+ G_RM_AA_OPA_SURF2,
+ G_RM_AA_OPA_SURF2,
+ G_RM_AA_TEX_EDGE2,
+ G_RM_AA_XLU_SURF2,
+ G_RM_AA_XLU_SURF2,
+ G_RM_AA_XLU_SURF2,
+ }
+ },
+ {
+ {
+ /* z-buffered */
+ G_RM_ZB_OPA_SURF2,
+ G_RM_AA_ZB_OPA_SURF2,
+ G_RM_AA_ZB_OPA_DECAL2,
+ G_RM_AA_ZB_OPA_INTER2,
+ G_RM_AA_ZB_TEX_EDGE2,
+ G_RM_AA_ZB_XLU_SURF2,
+ G_RM_AA_ZB_XLU_DECAL2,
+ G_RM_AA_ZB_XLU_INTER2,
+ }
+ }
+};
struct GraphNodeRoot *gCurGraphNodeRoot = NULL;
struct GraphNodeMasterList *gCurGraphNodeMasterList = NULL;
@@ -149,35 +167,41 @@ LookAt lookAt;
/**
* Process a master list node.
*/
-static void geo_process_master_list_sub(struct GraphNodeMasterList *node) {
+static void geo_process_master_list_sub(struct GraphNodeMasterList *node)
+{
struct DisplayListNode *currList;
s32 i;
s32 enableZBuffer = (node->node.flags & GRAPH_RENDER_Z_BUFFER) != 0;
-// struct RenderModeContainer *modeList = &renderModeTable_1Cycle[enableZBuffer];
-// struct RenderModeContainer *mode2List = &renderModeTable_2Cycle[enableZBuffer];
+ // struct RenderModeContainer *modeList = &renderModeTable_1Cycle[enableZBuffer];
+ // struct RenderModeContainer *mode2List = &renderModeTable_2Cycle[enableZBuffer];
// @bug This is where the LookAt values should be calculated but aren't.
// As a result, environment mapping is broken on Fast3DEX2 without the
// changes below.
-#ifdef F3DEX_GBI_2
+ #ifdef F3DEX_GBI_2
Mtx lMtx;
guLookAtReflect(&lMtx, &lookAt, 0, 0, 0, /* eye */ 0, 0, 1, /* at */ 1, 0, 0 /* up */);
-#endif
+ #endif
- if (enableZBuffer != 0) {
+ if (enableZBuffer != 0)
+ {
gDPPipeSync(gDisplayListHead++);
gSPSetGeometryMode(gDisplayListHead++, G_ZBUFFER);
}
- // libsm64 HACK
+ // libsm64 HACK
// Mario ends up in the second master list for some reason.
// The first item in the list is the projection matrix that is uninitialized, so just skip it.
int xx = FALSE;
- for (i = 1; i < GFX_NUM_MASTER_LISTS; i++) {
- if ((currList = node->listHeads[i]) != NULL) {
-// gDPSetRenderMode(gDisplayListHead++, modeList->modes[i], mode2List->modes[i]);
- while (currList != NULL) {
- if( !xx ) {
+ for (i = 1; i < GFX_NUM_MASTER_LISTS; i++)
+ {
+ if ((currList = node->listHeads[i]) != NULL)
+ {
+ // gDPSetRenderMode(gDisplayListHead++, modeList->modes[i], mode2List->modes[i]);
+ while (currList != NULL)
+ {
+ if (!xx)
+ {
xx = TRUE;
currList = currList->next;
continue;
@@ -190,7 +214,8 @@ static void geo_process_master_list_sub(struct GraphNodeMasterList *node) {
}
}
}
- if (enableZBuffer != 0) {
+ if (enableZBuffer != 0)
+ {
gDPPipeSync(gDisplayListHead++);
gSPClearGeometryMode(gDisplayListHead++, G_ZBUFFER);
}
@@ -201,21 +226,25 @@ static void geo_process_master_list_sub(struct GraphNodeMasterList *node) {
* parameter. Look at the RenderModeContainer struct to see the corresponding
* render modes of layers.
*/
-static void geo_append_display_list(void *displayList, s16 layer) {
-
-#ifdef F3DEX_GBI_2
+static void geo_append_display_list(void *displayList, s16 layer)
+{
+ #ifdef F3DEX_GBI_2
gSPLookAt(gDisplayListHead++, &lookAt);
-#endif
- if (gCurGraphNodeMasterList != 0) {
+ #endif
+ if (gCurGraphNodeMasterList != 0)
+ {
struct DisplayListNode *listNode =
- alloc_only_pool_alloc(gDisplayListHeap, sizeof(struct DisplayListNode));
+ alloc_only_pool_alloc(gDisplayListHeap, sizeof(struct DisplayListNode));
listNode->transform = gMatStackFixed[gMatStackIndex];
listNode->displayList = displayList;
listNode->next = 0;
- if (gCurGraphNodeMasterList->listHeads[layer] == 0) {
+ if (gCurGraphNodeMasterList->listHeads[layer] == 0)
+ {
gCurGraphNodeMasterList->listHeads[layer] = listNode;
- } else {
+ }
+ else
+ {
gCurGraphNodeMasterList->listTails[layer]->next = listNode;
}
gCurGraphNodeMasterList->listTails[layer] = listNode;
@@ -225,13 +254,16 @@ static void geo_append_display_list(void *displayList, s16 layer) {
/**
* Process the master list node.
*/
-static void geo_process_master_list(struct GraphNodeMasterList *node) {
+static void geo_process_master_list(struct GraphNodeMasterList *node)
+{
s32 i;
UNUSED s32 sp1C;
- if (gCurGraphNodeMasterList == NULL && node->node.children != NULL) {
+ if (gCurGraphNodeMasterList == NULL && node->node.children != NULL)
+ {
gCurGraphNodeMasterList = node;
- for (i = 0; i < GFX_NUM_MASTER_LISTS; i++) {
+ for (i = 0; i < GFX_NUM_MASTER_LISTS; i++)
+ {
node->listHeads[i] = NULL;
}
geo_process_node_and_siblings(node->node.children);
@@ -243,16 +275,18 @@ static void geo_process_master_list(struct GraphNodeMasterList *node) {
/**
* Process an orthographic projection node.
*/
-static void geo_process_ortho_projection(struct GraphNodeOrthoProjection *node) {
- if (node->node.children != NULL) {
+static void geo_process_ortho_projection(struct GraphNodeOrthoProjection *node)
+{
+ if (node->node.children != NULL)
+ {
Mtx *mtx = alloc_display_list(sizeof(*mtx));
-// f32 left = (gCurGraphNodeRoot->x - gCurGraphNodeRoot->width) / 2.0f * node->scale;
-// f32 right = (gCurGraphNodeRoot->x + gCurGraphNodeRoot->width) / 2.0f * node->scale;
-// f32 top = (gCurGraphNodeRoot->y - gCurGraphNodeRoot->height) / 2.0f * node->scale;
-// f32 bottom = (gCurGraphNodeRoot->y + gCurGraphNodeRoot->height) / 2.0f * node->scale;
+ // f32 left = (gCurGraphNodeRoot->x - gCurGraphNodeRoot->width) / 2.0f * node->scale;
+ // f32 right = (gCurGraphNodeRoot->x + gCurGraphNodeRoot->width) / 2.0f * node->scale;
+ // f32 top = (gCurGraphNodeRoot->y - gCurGraphNodeRoot->height) / 2.0f * node->scale;
+ // f32 bottom = (gCurGraphNodeRoot->y + gCurGraphNodeRoot->height) / 2.0f * node->scale;
-// guOrtho(mtx, left, right, bottom, top, -2.0f, 2.0f, 1.0f);
-// gSPPerspNormalize(gDisplayListHead++, 0xFFFF);
+ // guOrtho(mtx, left, right, bottom, top, -2.0f, 2.0f, 1.0f);
+ // gSPPerspNormalize(gDisplayListHead++, 0xFFFF);
gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(mtx), G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);
geo_process_node_and_siblings(node->node.children);
@@ -262,22 +296,25 @@ static void geo_process_ortho_projection(struct GraphNodeOrthoProjection *node)
/**
* Process a perspective projection node.
*/
-static void geo_process_perspective(struct GraphNodePerspective *node) {
- if (node->fnNode.func != NULL) {
+static void geo_process_perspective(struct GraphNodePerspective *node)
+{
+ if (node->fnNode.func != NULL)
+ {
node->fnNode.func(GEO_CONTEXT_RENDER, &node->fnNode.node, gMatStack[gMatStackIndex]);
}
- if (node->fnNode.node.children != NULL) {
-// u16 perspNorm;
+ if (node->fnNode.node.children != NULL)
+ {
+ // u16 perspNorm;
Mtx *mtx = alloc_display_list(sizeof(*mtx));
-// #ifdef VERSION_EU
-// f32 aspect = ((f32) gCurGraphNodeRoot->width / (f32) gCurGraphNodeRoot->height) * 1.1f;
-// #else
-// f32 aspect = (f32) gCurGraphNodeRoot->width / (f32) gCurGraphNodeRoot->height;
-// #endif
+ // #ifdef VERSION_EU
+ // f32 aspect = ((f32) gCurGraphNodeRoot->width / (f32) gCurGraphNodeRoot->height) * 1.1f;
+ // #else
+ // f32 aspect = (f32) gCurGraphNodeRoot->width / (f32) gCurGraphNodeRoot->height;
+ // #endif
-// guPerspective(mtx, &perspNorm, node->fov, aspect, node->near, node->far, 1.0f);
-// gSPPerspNormalize(gDisplayListHead++, perspNorm);
+ // guPerspective(mtx, &perspNorm, node->fov, aspect, node->near, node->far, 1.0f);
+ // gSPPerspNormalize(gDisplayListHead++, perspNorm);
gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(mtx), G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);
@@ -293,24 +330,27 @@ static void geo_process_perspective(struct GraphNodePerspective *node) {
* of this node are only processed if that distance is within the render
* range of this node.
*/
-static void geo_process_level_of_detail(struct GraphNodeLevelOfDetail *node) {
-#ifdef GBI_FLOATS
+static void geo_process_level_of_detail(struct GraphNodeLevelOfDetail *node)
+{
+ #ifdef GBI_FLOATS
Mtx *mtx = gMatStackFixed[gMatStackIndex];
- s16 distanceFromCam = (s32) -mtx->m[3][2]; // z-component of the translation column
-#else
+ s16 distanceFromCam = (s32) - mtx->m[3][2]; // z-component of the translation column
+ #else
// The fixed point Mtx type is defined as 16 longs, but it's actually 16
// shorts for the integer parts followed by 16 shorts for the fraction parts
Mtx *mtx = gMatStackFixed[gMatStackIndex];
s16 distanceFromCam = -GET_HIGH_S16_OF_32(mtx->m[1][3]); // z-component of the translation column
-#endif
+ #endif
-#ifndef TARGET_N64
+ #ifndef TARGET_N64
// We assume modern hardware is powerful enough to draw the most detailed variant
distanceFromCam = 0;
-#endif
+ #endif
- if (node->minDistance <= distanceFromCam && distanceFromCam < node->maxDistance) {
- if (node->node.children != 0) {
+ if (node->minDistance <= distanceFromCam && distanceFromCam < node->maxDistance)
+ {
+ if (node->node.children != 0)
+ {
geo_process_node_and_siblings(node->node.children);
}
}
@@ -321,17 +361,21 @@ static void geo_process_level_of_detail(struct GraphNodeLevelOfDetail *node) {
* if it is 0, and among the node's children, only the selected child is
* processed next.
*/
-static void geo_process_switch(struct GraphNodeSwitchCase *node) {
+static void geo_process_switch(struct GraphNodeSwitchCase *node)
+{
struct GraphNode *selectedChild = node->fnNode.node.children;
s32 i;
- if (node->fnNode.func != NULL) {
+ if (node->fnNode.func != NULL)
+ {
node->fnNode.func(GEO_CONTEXT_RENDER, &node->fnNode.node, gMatStack[gMatStackIndex]);
}
- for (i = 0; selectedChild != NULL && node->selectedCase > i; i++) {
+ for (i = 0; selectedChild != NULL && node->selectedCase > i; i++)
+ {
selectedChild = selectedChild->next;
}
- if (selectedChild != NULL) {
+ if (selectedChild != NULL)
+ {
geo_process_node_and_siblings(selectedChild);
}
}
@@ -339,12 +383,14 @@ static void geo_process_switch(struct GraphNodeSwitchCase *node) {
/**
* Process a camera node.
*/
-static void geo_process_camera(struct GraphNodeCamera *node) {
+static void geo_process_camera(struct GraphNodeCamera *node)
+{
Mat4 cameraTransform;
Mtx *rollMtx = alloc_display_list(sizeof(*rollMtx));
Mtx *mtx = alloc_display_list(sizeof(*mtx));
- if (node->fnNode.func != NULL) {
+ if (node->fnNode.func != NULL)
+ {
node->fnNode.func(GEO_CONTEXT_RENDER, &node->fnNode.node, gMatStack[gMatStackIndex]);
}
mtxf_rotate_xy(rollMtx, node->rollScreen);
@@ -356,7 +402,8 @@ static void geo_process_camera(struct GraphNodeCamera *node) {
gMatStackIndex++;
mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]);
gMatStackFixed[gMatStackIndex] = mtx;
- if (node->fnNode.node.children != 0) {
+ if (node->fnNode.node.children != 0)
+ {
gCurGraphNodeCamera = node;
node->matrixPtr = &gMatStack[gMatStackIndex];
geo_process_node_and_siblings(node->fnNode.node.children);
@@ -371,7 +418,8 @@ static void geo_process_camera(struct GraphNodeCamera *node) {
* the float and fixed point matrix stacks.
* For the rest it acts as a normal display list node.
*/
-static void geo_process_translation_rotation(struct GraphNodeTranslationRotation *node) {
+static void geo_process_translation_rotation(struct GraphNodeTranslationRotation *node)
+{
Mat4 mtxf;
Vec3f translation;
Mtx *mtx = alloc_display_list(sizeof(*mtx));
@@ -382,10 +430,12 @@ static void geo_process_translation_rotation(struct GraphNodeTranslationRotation
gMatStackIndex++;
mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]);
gMatStackFixed[gMatStackIndex] = mtx;
- if (node->displayList != NULL) {
+ if (node->displayList != NULL)
+ {
geo_append_display_list(node->displayList, node->node.flags >> 8);
}
- if (node->node.children != NULL) {
+ if (node->node.children != NULL)
+ {
geo_process_node_and_siblings(node->node.children);
}
gMatStackIndex--;
@@ -396,7 +446,8 @@ static void geo_process_translation_rotation(struct GraphNodeTranslationRotation
* translation is created and pushed on both the float and fixed point matrix stacks.
* For the rest it acts as a normal display list node.
*/
-static void geo_process_translation(struct GraphNodeTranslation *node) {
+static void geo_process_translation(struct GraphNodeTranslation *node)
+{
Mat4 mtxf;
Vec3f translation;
Mtx *mtx = alloc_display_list(sizeof(*mtx));
@@ -407,10 +458,12 @@ static void geo_process_translation(struct GraphNodeTranslation *node) {
gMatStackIndex++;
mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]);
gMatStackFixed[gMatStackIndex] = mtx;
- if (node->displayList != NULL) {
+ if (node->displayList != NULL)
+ {
geo_append_display_list(node->displayList, node->node.flags >> 8);
}
- if (node->node.children != NULL) {
+ if (node->node.children != NULL)
+ {
geo_process_node_and_siblings(node->node.children);
}
gMatStackIndex--;
@@ -421,7 +474,8 @@ static void geo_process_translation(struct GraphNodeTranslation *node) {
* rotation is created and pushed on both the float and fixed point matrix stacks.
* For the rest it acts as a normal display list node.
*/
-static void geo_process_rotation(struct GraphNodeRotation *node) {
+static void geo_process_rotation(struct GraphNodeRotation *node)
+{
Mat4 mtxf;
Mtx *mtx = alloc_display_list(sizeof(*mtx));
@@ -430,10 +484,12 @@ static void geo_process_rotation(struct GraphNodeRotation *node) {
gMatStackIndex++;
mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]);
gMatStackFixed[gMatStackIndex] = mtx;
- if (node->displayList != NULL) {
+ if (node->displayList != NULL)
+ {
geo_append_display_list(node->displayList, node->node.flags >> 8);
}
- if (node->node.children != NULL) {
+ if (node->node.children != NULL)
+ {
geo_process_node_and_siblings(node->node.children);
}
gMatStackIndex--;
@@ -444,7 +500,8 @@ static void geo_process_rotation(struct GraphNodeRotation *node) {
* scale is created and pushed on both the float and fixed point matrix stacks.
* For the rest it acts as a normal display list node.
*/
-static void geo_process_scale(struct GraphNodeScale *node) {
+static void geo_process_scale(struct GraphNodeScale *node)
+{
UNUSED Mat4 transform;
Vec3f scaleVec;
Mtx *mtx = alloc_display_list(sizeof(*mtx));
@@ -454,10 +511,12 @@ static void geo_process_scale(struct GraphNodeScale *node) {
gMatStackIndex++;
mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]);
gMatStackFixed[gMatStackIndex] = mtx;
- if (node->displayList != NULL) {
+ if (node->displayList != NULL)
+ {
geo_append_display_list(node->displayList, node->node.flags >> 8);
}
- if (node->node.children != NULL) {
+ if (node->node.children != NULL)
+ {
geo_process_node_and_siblings(node->node.children);
}
gMatStackIndex--;
@@ -469,7 +528,8 @@ static void geo_process_scale(struct GraphNodeScale *node) {
* point matrix stacks.
* For the rest it acts as a normal display list node.
*/
-static void geo_process_billboard(struct GraphNodeBillboard *node) {
+static void geo_process_billboard(struct GraphNodeBillboard *node)
+{
Vec3f translation;
Mtx *mtx = alloc_display_list(sizeof(*mtx));
@@ -477,20 +537,25 @@ static void geo_process_billboard(struct GraphNodeBillboard *node) {
vec3s_to_vec3f(translation, node->translation);
mtxf_billboard(gMatStack[gMatStackIndex], gMatStack[gMatStackIndex - 1], translation,
gCurGraphNodeCamera->roll);
- if (gCurGraphNodeHeldObject != NULL) {
+ if (gCurGraphNodeHeldObject != NULL)
+ {
mtxf_scale_vec3f(gMatStack[gMatStackIndex], gMatStack[gMatStackIndex],
gCurGraphNodeHeldObject->objNode->header.gfx.scale);
- } else if (gCurGraphNodeObject != NULL) {
+ }
+ else if (gCurGraphNodeObject != NULL)
+ {
mtxf_scale_vec3f(gMatStack[gMatStackIndex], gMatStack[gMatStackIndex],
gCurGraphNodeObject->scale);
}
mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]);
gMatStackFixed[gMatStackIndex] = mtx;
- if (node->displayList != NULL) {
+ if (node->displayList != NULL)
+ {
geo_append_display_list(node->displayList, node->node.flags >> 8);
}
- if (node->node.children != NULL) {
+ if (node->node.children != NULL)
+ {
geo_process_node_and_siblings(node->node.children);
}
gMatStackIndex--;
@@ -501,11 +566,14 @@ static void geo_process_billboard(struct GraphNodeBillboard *node) {
* a transformation on the stack, so all transformations are inherited from the
* parent node. It processes its children if it has them.
*/
-static void geo_process_display_list(struct GraphNodeDisplayList *node) {
- if (node->displayList != NULL) {
+static void geo_process_display_list(struct GraphNodeDisplayList *node)
+{
+ if (node->displayList != NULL)
+ {
geo_append_display_list(node->displayList, node->node.flags >> 8);
}
- if (node->node.children != NULL) {
+ if (node->node.children != NULL)
+ {
geo_process_node_and_siblings(node->node.children);
}
}
@@ -514,16 +582,20 @@ static void geo_process_display_list(struct GraphNodeDisplayList *node) {
* Process a generated list. Instead of storing a pointer to a display list,
* the list is generated on the fly by a function.
*/
-static void geo_process_generated_list(struct GraphNodeGenerated *node) {
- if (node->fnNode.func != NULL) {
+static void geo_process_generated_list(struct GraphNodeGenerated *node)
+{
+ if (node->fnNode.func != NULL)
+ {
Gfx *list = node->fnNode.func(GEO_CONTEXT_RENDER, &node->fnNode.node,
- (struct AllocOnlyPool *) gMatStack[gMatStackIndex]);
+ (struct AllocOnlyPool *)gMatStack[gMatStackIndex]);
- if (list != NULL) {
- geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(list), node->fnNode.node.flags >> 8);
+ if (list != NULL)
+ {
+ geo_append_display_list(VIRTUAL_TO_PHYSICAL(list), node->fnNode.node.flags >> 8);
}
}
- if (node->fnNode.node.children != NULL) {
+ if (node->fnNode.node.children != NULL)
+ {
geo_process_node_and_siblings(node->fnNode.node.children);
}
}
@@ -533,35 +605,41 @@ static void geo_process_generated_list(struct GraphNodeGenerated *node) {
* the function of the node. If that function is null or returns null, a black
* rectangle is drawn instead.
*/
-static void geo_process_background(struct GraphNodeBackground *node) {
+static void geo_process_background(struct GraphNodeBackground *node)
+{
Gfx *list = NULL;
- if (node->fnNode.func != NULL) {
+ if (node->fnNode.func != NULL)
+ {
list = node->fnNode.func(GEO_CONTEXT_RENDER, &node->fnNode.node,
- (struct AllocOnlyPool *) gMatStack[gMatStackIndex]);
+ (struct AllocOnlyPool *)gMatStack[gMatStackIndex]);
}
- if (list != NULL) {
- geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(list), node->fnNode.node.flags >> 8);
- } else if (gCurGraphNodeMasterList != NULL) {
-#ifndef F3DEX_GBI_2E
+ if (list != NULL)
+ {
+ geo_append_display_list(VIRTUAL_TO_PHYSICAL(list), node->fnNode.node.flags >> 8);
+ }
+ else if (gCurGraphNodeMasterList != NULL)
+ {
+ #ifndef F3DEX_GBI_2E
Gfx *gfxStart = alloc_display_list(sizeof(Gfx) * 7);
-#else
+ #else
Gfx *gfxStart = alloc_display_list(sizeof(Gfx) * 8);
-#endif
+ #endif
Gfx *gfx = gfxStart;
gDPPipeSync(gfx++);
gDPSetCycleType(gfx++, G_CYC_FILL);
gDPSetFillColor(gfx++, node->background);
gDPFillRectangle(gfx++, GFX_DIMENSIONS_RECT_FROM_LEFT_EDGE(0), BORDER_HEIGHT,
- GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(0) - 1, SCREEN_HEIGHT - BORDER_HEIGHT - 1);
+ GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(0) - 1, SCREEN_HEIGHT - BORDER_HEIGHT - 1);
gDPPipeSync(gfx++);
gDPSetCycleType(gfx++, G_CYC_1CYCLE);
gSPEndDisplayList(gfx++);
- geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(gfxStart), 0);
+ geo_append_display_list(VIRTUAL_TO_PHYSICAL(gfxStart), 0);
}
- if (node->fnNode.node.children != NULL) {
+ if (node->fnNode.node.children != NULL)
+ {
geo_process_node_and_siblings(node->fnNode.node.children);
}
}
@@ -570,7 +648,8 @@ static void geo_process_background(struct GraphNodeBackground *node) {
* Render an animated part. The current animation state is not part of the node
* but set in global variables. If an animated part is skipped, everything afterwards desyncs.
*/
-static void geo_process_animated_part(struct GraphNodeAnimatedPart *node) {
+static void geo_process_animated_part(struct GraphNodeAnimatedPart *node)
+{
Mat4 matrix;
Vec3s rotation;
Vec3f translation;
@@ -578,40 +657,50 @@ static void geo_process_animated_part(struct GraphNodeAnimatedPart *node) {
vec3s_copy(rotation, gVec3sZero);
vec3f_set(translation, node->translation[0], node->translation[1], node->translation[2]);
- if (gCurAnimType == ANIM_TYPE_TRANSLATION) {
+ if (gCurAnimType == ANIM_TYPE_TRANSLATION)
+ {
translation[0] += gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)]
- * gCurAnimTranslationMultiplier;
+ * gCurAnimTranslationMultiplier;
translation[1] += gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)]
- * gCurAnimTranslationMultiplier;
+ * gCurAnimTranslationMultiplier;
translation[2] += gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)]
- * gCurAnimTranslationMultiplier;
+ * gCurAnimTranslationMultiplier;
gCurAnimType = ANIM_TYPE_ROTATION;
- } else {
- if (gCurAnimType == ANIM_TYPE_LATERAL_TRANSLATION) {
+ }
+ else
+ {
+ if (gCurAnimType == ANIM_TYPE_LATERAL_TRANSLATION)
+ {
translation[0] +=
- gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)]
- * gCurAnimTranslationMultiplier;
- gCurrAnimAttribute += 2;
- translation[2] +=
- gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)]
- * gCurAnimTranslationMultiplier;
- gCurAnimType = ANIM_TYPE_ROTATION;
- } else {
- if (gCurAnimType == ANIM_TYPE_VERTICAL_TRANSLATION) {
- gCurrAnimAttribute += 2;
- translation[1] +=
gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)]
* gCurAnimTranslationMultiplier;
+ gCurrAnimAttribute += 2;
+ translation[2] +=
+ gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)]
+ * gCurAnimTranslationMultiplier;
+ gCurAnimType = ANIM_TYPE_ROTATION;
+ }
+ else
+ {
+ if (gCurAnimType == ANIM_TYPE_VERTICAL_TRANSLATION)
+ {
+ gCurrAnimAttribute += 2;
+ translation[1] +=
+ gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)]
+ * gCurAnimTranslationMultiplier;
gCurrAnimAttribute += 2;
gCurAnimType = ANIM_TYPE_ROTATION;
- } else if (gCurAnimType == ANIM_TYPE_NO_TRANSLATION) {
+ }
+ else if (gCurAnimType == ANIM_TYPE_NO_TRANSLATION)
+ {
gCurrAnimAttribute += 6;
gCurAnimType = ANIM_TYPE_ROTATION;
}
}
}
- if (gCurAnimType == ANIM_TYPE_ROTATION) {
+ if (gCurAnimType == ANIM_TYPE_ROTATION)
+ {
rotation[0] = gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)];
rotation[1] = gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)];
rotation[2] = gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)];
@@ -621,10 +710,12 @@ static void geo_process_animated_part(struct GraphNodeAnimatedPart *node) {
gMatStackIndex++;
mtxf_to_mtx(matrixPtr, gMatStack[gMatStackIndex]);
gMatStackFixed[gMatStackIndex] = matrixPtr;
- if (node->displayList != NULL) {
+ if (node->displayList != NULL)
+ {
geo_append_display_list(node->displayList, node->node.flags >> 8);
}
- if (node->node.children != NULL) {
+ if (node->node.children != NULL)
+ {
geo_process_node_and_siblings(node->node.children);
}
gMatStackIndex--;
@@ -634,32 +725,44 @@ static void geo_process_animated_part(struct GraphNodeAnimatedPart *node) {
* Initialize the animation-related global variables for the currently drawn
* object's animation.
*/
-void geo_set_animation_globals(struct AnimInfo *node, s32 hasAnimation) {
+void geo_set_animation_globals(struct AnimInfo *node, s32 hasAnimation)
+{
struct Animation *anim = node->curAnim;
- if (hasAnimation) {
+ if (hasAnimation)
+ {
node->animFrame = geo_update_animation_frame(node, &node->animFrameAccelAssist);
}
node->animTimer = gAreaUpdateCounter;
- if (anim->flags & ANIM_FLAG_HOR_TRANS) {
+ if (anim->flags & ANIM_FLAG_HOR_TRANS)
+ {
gCurAnimType = ANIM_TYPE_VERTICAL_TRANSLATION;
- } else if (anim->flags & ANIM_FLAG_VERT_TRANS) {
+ }
+ else if (anim->flags & ANIM_FLAG_VERT_TRANS)
+ {
gCurAnimType = ANIM_TYPE_LATERAL_TRANSLATION;
- } else if (anim->flags & ANIM_FLAG_6) {
+ }
+ else if (anim->flags & ANIM_FLAG_6)
+ {
gCurAnimType = ANIM_TYPE_NO_TRANSLATION;
- } else {
+ }
+ else
+ {
gCurAnimType = ANIM_TYPE_TRANSLATION;
}
gCurrAnimFrame = node->animFrame;
gCurAnimEnabled = (anim->flags & ANIM_FLAG_5) == 0;
- gCurrAnimAttribute = segmented_to_virtual((void *) anim->index);
- gCurAnimData = segmented_to_virtual((void *) anim->values);
+ gCurrAnimAttribute = segmented_to_virtual(anim->index);
+ gCurAnimData = segmented_to_virtual(anim->values);
- if (anim->animYTransDivisor == 0) {
+ if (anim->animYTransDivisor == 0)
+ {
gCurAnimTranslationMultiplier = 1.0f;
- } else {
- gCurAnimTranslationMultiplier = (f32) node->animYTrans / (f32) anim->animYTransDivisor;
+ }
+ else
+ {
+ gCurAnimTranslationMultiplier = (f32)node->animYTrans / (f32)anim->animYTransDivisor;
}
}
@@ -668,77 +771,78 @@ void geo_set_animation_globals(struct AnimInfo *node, s32 hasAnimation) {
* translation of the first animated component and rotated according to
* the floor below it.
*/
-static void geo_process_shadow(struct GraphNodeShadow *node) {
-// Gfx *shadowList;
-// Mat4 mtxf;
-// Vec3f shadowPos;
-// Vec3f animOffset;
-// f32 objScale;
-// f32 shadowScale;
-// f32 sinAng;
-// f32 cosAng;
-// struct GraphNode *geo;
-// Mtx *mtx;
+static void geo_process_shadow(struct GraphNodeShadow *node)
+{
+ // Gfx *shadowList;
+ // Mat4 mtxf;
+ // Vec3f shadowPos;
+ // Vec3f animOffset;
+ // f32 objScale;
+ // f32 shadowScale;
+ // f32 sinAng;
+ // f32 cosAng;
+ // struct GraphNode *geo;
+ // Mtx *mtx;
-// if (gCurGraphNodeCamera != NULL && gCurGraphNodeObject != NULL) {
-// if (gCurGraphNodeHeldObject != NULL) {
-// get_pos_from_transform_mtx(shadowPos, gMatStack[gMatStackIndex],
-// *gCurGraphNodeCamera->matrixPtr);
-// shadowScale = node->shadowScale;
-// } else {
-// vec3f_copy(shadowPos, gCurGraphNodeObject->pos);
-// shadowScale = node->shadowScale * gCurGraphNodeObject->scale[0];
-// }
+ // if (gCurGraphNodeCamera != NULL && gCurGraphNodeObject != NULL) {
+ // if (gCurGraphNodeHeldObject != NULL) {
+ // get_pos_from_transform_mtx(shadowPos, gMatStack[gMatStackIndex],
+ // *gCurGraphNodeCamera->matrixPtr);
+ // shadowScale = node->shadowScale;
+ // } else {
+ // vec3f_copy(shadowPos, gCurGraphNodeObject->pos);
+ // shadowScale = node->shadowScale * gCurGraphNodeObject->scale[0];
+ // }
-// objScale = 1.0f;
-// if (gCurAnimEnabled) {
-// if (gCurAnimType == ANIM_TYPE_TRANSLATION
-// || gCurAnimType == ANIM_TYPE_LATERAL_TRANSLATION) {
-// geo = node->node.children;
-// if (geo != NULL && geo->type == GRAPH_NODE_TYPE_SCALE) {
-// objScale = ((struct GraphNodeScale *) geo)->scale;
-// }
-// animOffset[0] =
-// gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)]
-// * gCurAnimTranslationMultiplier * objScale;
-// animOffset[1] = 0.0f;
-// gCurrAnimAttribute += 2;
-// animOffset[2] =
-// gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)]
-// * gCurAnimTranslationMultiplier * objScale;
-// gCurrAnimAttribute -= 6;
+ // objScale = 1.0f;
+ // if (gCurAnimEnabled) {
+ // if (gCurAnimType == ANIM_TYPE_TRANSLATION
+ // || gCurAnimType == ANIM_TYPE_LATERAL_TRANSLATION) {
+ // geo = node->node.children;
+ // if (geo != NULL && geo->type == GRAPH_NODE_TYPE_SCALE) {
+ // objScale = ((struct GraphNodeScale *) geo)->scale;
+ // }
+ // animOffset[0] =
+ // gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)]
+ // * gCurAnimTranslationMultiplier * objScale;
+ // animOffset[1] = 0.0f;
+ // gCurrAnimAttribute += 2;
+ // animOffset[2] =
+ // gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)]
+ // * gCurAnimTranslationMultiplier * objScale;
+ // gCurrAnimAttribute -= 6;
-// // simple matrix rotation so the shadow offset rotates along with the object
-// sinAng = sins(gCurGraphNodeObject->angle[1]);
-// cosAng = coss(gCurGraphNodeObject->angle[1]);
+ // // simple matrix rotation so the shadow offset rotates along with the object
+ // sinAng = sins(gCurGraphNodeObject->angle[1]);
+ // cosAng = coss(gCurGraphNodeObject->angle[1]);
-// shadowPos[0] += animOffset[0] * cosAng + animOffset[2] * sinAng;
-// shadowPos[2] += -animOffset[0] * sinAng + animOffset[2] * cosAng;
-// }
-// }
+ // shadowPos[0] += animOffset[0] * cosAng + animOffset[2] * sinAng;
+ // shadowPos[2] += -animOffset[0] * sinAng + animOffset[2] * cosAng;
+ // }
+ // }
-// shadowList = create_shadow_below_xyz(shadowPos[0], shadowPos[1], shadowPos[2], shadowScale,
-// node->shadowSolidity, node->shadowType);
-// if (shadowList != NULL) {
-// mtx = alloc_display_list(sizeof(*mtx));
-// gMatStackIndex++;
-// mtxf_translate(mtxf, shadowPos);
-// mtxf_mul(gMatStack[gMatStackIndex], mtxf, *gCurGraphNodeCamera->matrixPtr);
-// mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]);
-// gMatStackFixed[gMatStackIndex] = mtx;
-// if (gShadowAboveWaterOrLava == TRUE) {
-// geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(shadowList), 4);
-// } else if (gMarioOnIceOrCarpet == 1) {
-// geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(shadowList), 5);
-// } else {
-// geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(shadowList), 6);
-// }
-// gMatStackIndex--;
-// }
-// }
-// if (node->node.children != NULL) {
-// geo_process_node_and_siblings(node->node.children);
-// }
+ // shadowList = create_shadow_below_xyz(shadowPos[0], shadowPos[1], shadowPos[2], shadowScale,
+ // node->shadowSolidity, node->shadowType);
+ // if (shadowList != NULL) {
+ // mtx = alloc_display_list(sizeof(*mtx));
+ // gMatStackIndex++;
+ // mtxf_translate(mtxf, shadowPos);
+ // mtxf_mul(gMatStack[gMatStackIndex], mtxf, *gCurGraphNodeCamera->matrixPtr);
+ // mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]);
+ // gMatStackFixed[gMatStackIndex] = mtx;
+ // if (gShadowAboveWaterOrLava == TRUE) {
+ // geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(shadowList), 4);
+ // } else if (gMarioOnIceOrCarpet == 1) {
+ // geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(shadowList), 5);
+ // } else {
+ // geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(shadowList), 6);
+ // }
+ // gMatStackIndex--;
+ // }
+ // }
+ // if (node->node.children != NULL) {
+ // geo_process_node_and_siblings(node->node.children);
+ // }
}
/**
@@ -772,13 +876,15 @@ static void geo_process_shadow(struct GraphNodeShadow *node) {
*
* Since (0,0,0) is unaffected by rotation, columns 0, 1 and 2 are ignored.
*/
-static s32 obj_is_in_view(struct GraphNodeObject *node, Mat4 matrix) {
+static s32 obj_is_in_view(struct GraphNodeObject *node, Mat4 matrix)
+{
s16 cullingRadius;
s16 halfFov; // half of the fov in in-game angle units instead of degrees
struct GraphNode *geo;
f32 hScreenEdge;
- if (node->node.flags & GRAPH_RENDER_INVISIBLE) {
+ if (node->node.flags & GRAPH_RENDER_INVISIBLE)
+ {
return FALSE;
}
@@ -794,21 +900,25 @@ static s32 obj_is_in_view(struct GraphNodeObject *node, Mat4 matrix) {
// the amount of units between the center of the screen and the horizontal edge
// given the distance from the object to the camera.
-#ifdef WIDESCREEN
+ #ifdef WIDESCREEN
// This multiplication should really be performed on 4:3 as well,
// but the issue will be more apparent on widescreen.
hScreenEdge *= GFX_DIMENSIONS_ASPECT_RATIO;
-#endif
+ #endif
- if (geo != NULL && geo->type == GRAPH_NODE_TYPE_CULLING_RADIUS) {
+ if (geo != NULL && geo->type == GRAPH_NODE_TYPE_CULLING_RADIUS)
+ {
cullingRadius =
- (f32)((struct GraphNodeCullingRadius *) geo)->cullingRadius; //! Why is there a f32 cast?
- } else {
+ (f32)((struct GraphNodeCullingRadius *)geo)->cullingRadius; //! Why is there a f32 cast?
+ }
+ else
+ {
cullingRadius = 300;
}
// Don't render if the object is close to or behind the camera
- if (matrix[3][2] > -100.0f + cullingRadius) {
+ if (matrix[3][2] > -100.0f + cullingRadius)
+ {
return FALSE;
}
@@ -816,15 +926,18 @@ static s32 obj_is_in_view(struct GraphNodeObject *node, Mat4 matrix) {
// makes PU travel safe when the camera is locked on the main map.
// If Mario were rendered with a depth over 65536 it would cause overflow
// when converting the transformation matrix to a fixed point matrix.
- if (matrix[3][2] < -20000.0f - cullingRadius) {
+ if (matrix[3][2] < -20000.0f - cullingRadius)
+ {
return FALSE;
}
// Check whether the object is horizontally in view
- if (matrix[3][0] > hScreenEdge + cullingRadius) {
+ if (matrix[3][0] > hScreenEdge + cullingRadius)
+ {
return FALSE;
}
- if (matrix[3][0] < -hScreenEdge - cullingRadius) {
+ if (matrix[3][0] < -hScreenEdge - cullingRadius)
+ {
return FALSE;
}
return TRUE;
@@ -833,18 +946,25 @@ static s32 obj_is_in_view(struct GraphNodeObject *node, Mat4 matrix) {
/**
* Process an object node.
*/
-static void geo_process_object(struct Object *node) {
+static void geo_process_object(struct Object *node)
+{
Mat4 mtxf;
s32 hasAnimation = (node->header.gfx.node.flags & GRAPH_RENDER_HAS_ANIMATION) != 0;
- if (node->header.gfx.areaIndex == gCurGraphNodeRoot->areaIndex) {
- if (node->header.gfx.throwMatrix != NULL) {
+ if (node->header.gfx.areaIndex == gCurGraphNodeRoot->areaIndex)
+ {
+ if (node->header.gfx.throwMatrix != NULL)
+ {
mtxf_mul(gMatStack[gMatStackIndex + 1], *node->header.gfx.throwMatrix,
gMatStack[gMatStackIndex]);
- } else if (node->header.gfx.node.flags & GRAPH_RENDER_BILLBOARD) {
+ }
+ else if (node->header.gfx.node.flags & GRAPH_RENDER_BILLBOARD)
+ {
mtxf_billboard(gMatStack[gMatStackIndex + 1], gMatStack[gMatStackIndex],
node->header.gfx.pos, gCurGraphNodeCamera->roll);
- } else {
+ }
+ else
+ {
mtxf_rotate_zxy_and_translate(mtxf, node->header.gfx.pos, node->header.gfx.angle);
mtxf_mul(gMatStack[gMatStackIndex + 1], mtxf, gMatStack[gMatStackIndex]);
}
@@ -857,22 +977,26 @@ static void geo_process_object(struct Object *node) {
node->header.gfx.cameraToObject[2] = gMatStack[gMatStackIndex][3][2];
// FIXME: correct types
- if (node->header.gfx.animInfo.curAnim != NULL) {
+ if (node->header.gfx.animInfo.curAnim != NULL)
+ {
geo_set_animation_globals(&node->header.gfx.animInfo, hasAnimation);
}
- if (obj_is_in_view(&node->header.gfx, gMatStack[gMatStackIndex])) {
+ if (obj_is_in_view(&node->header.gfx, gMatStack[gMatStackIndex]))
+ {
Mtx *mtx = alloc_display_list(sizeof(*mtx));
mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]);
gMatStackFixed[gMatStackIndex] = mtx;
- if (node->header.gfx.sharedChild != NULL) {
- gCurGraphNodeObject = (struct GraphNodeObject *) node;
+ if (node->header.gfx.sharedChild != NULL)
+ {
+ gCurGraphNodeObject = (struct GraphNodeObject *)node;
node->header.gfx.sharedChild->parent = &node->header.gfx.node;
geo_process_node_and_siblings(node->header.gfx.sharedChild);
node->header.gfx.sharedChild->parent = NULL;
gCurGraphNodeObject = NULL;
}
- if (node->header.gfx.node.children != NULL) {
+ if (node->header.gfx.node.children != NULL)
+ {
geo_process_node_and_siblings(node->header.gfx.node.children);
}
}
@@ -888,13 +1012,16 @@ static void geo_process_object(struct Object *node) {
* the subtree rooted at 'sharedChild' and processes the subtree, after which the
* actual children are be processed. (in practice they are null though)
*/
-static void geo_process_object_parent(struct GraphNodeObjectParent *node) {
- if (node->sharedChild != NULL) {
- node->sharedChild->parent = (struct GraphNode *) node;
+static void geo_process_object_parent(struct GraphNodeObjectParent *node)
+{
+ if (node->sharedChild != NULL)
+ {
+ node->sharedChild->parent = (struct GraphNode *)node;
geo_process_node_and_siblings(node->sharedChild);
node->sharedChild->parent = NULL;
}
- if (node->node.children != NULL) {
+ if (node->node.children != NULL)
+ {
geo_process_node_and_siblings(node->node.children);
}
}
@@ -902,19 +1029,22 @@ static void geo_process_object_parent(struct GraphNodeObjectParent *node) {
/**
* Process a held object node.
*/
-void geo_process_held_object(struct GraphNodeHeldObject *node) {
+void geo_process_held_object(struct GraphNodeHeldObject *node)
+{
Mat4 mat;
Vec3f translation;
Mtx *mtx = alloc_display_list(sizeof(*mtx));
-#ifdef F3DEX_GBI_2
+ #ifdef F3DEX_GBI_2
gSPLookAt(gDisplayListHead++, &lookAt);
-#endif
+ #endif
- if (node->fnNode.func != NULL) {
+ if (node->fnNode.func != NULL)
+ {
node->fnNode.func(GEO_CONTEXT_RENDER, &node->fnNode.node, gMatStack[gMatStackIndex]);
}
- if (node->objNode != NULL && node->objNode->header.gfx.sharedChild != NULL) {
+ if (node->objNode != NULL && node->objNode->header.gfx.sharedChild != NULL)
+ {
s32 hasAnimation = (node->objNode->header.gfx.node.flags & GRAPH_RENDER_HAS_ANIMATION) != 0;
translation[0] = node->translation[0] / 4.0f;
@@ -929,9 +1059,10 @@ void geo_process_held_object(struct GraphNodeHeldObject *node) {
mtxf_mul(gMatStack[gMatStackIndex + 1], mat, gMatStack[gMatStackIndex + 1]);
mtxf_scale_vec3f(gMatStack[gMatStackIndex + 1], gMatStack[gMatStackIndex + 1],
node->objNode->header.gfx.scale);
- if (node->fnNode.func != NULL) {
+ if (node->fnNode.func != NULL)
+ {
node->fnNode.func(GEO_CONTEXT_HELD_OBJ, &node->fnNode.node,
- (struct AllocOnlyPool *) gMatStack[gMatStackIndex + 1]);
+ (struct AllocOnlyPool *)gMatStack[gMatStackIndex + 1]);
}
gMatStackIndex++;
mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]);
@@ -943,8 +1074,9 @@ void geo_process_held_object(struct GraphNodeHeldObject *node) {
gGeoTempState.attribute = gCurrAnimAttribute;
gGeoTempState.data = gCurAnimData;
gCurAnimType = 0;
- gCurGraphNodeHeldObject = (void *) node;
- if (node->objNode->header.gfx.animInfo.curAnim != NULL) {
+ gCurGraphNodeHeldObject = (void *)node;
+ if (node->objNode->header.gfx.animInfo.curAnim != NULL)
+ {
geo_set_animation_globals(&node->objNode->header.gfx.animInfo, hasAnimation);
}
@@ -959,7 +1091,8 @@ void geo_process_held_object(struct GraphNodeHeldObject *node) {
gMatStackIndex--;
}
- if (node->fnNode.node.children != NULL) {
+ if (node->fnNode.node.children != NULL)
+ {
geo_process_node_and_siblings(node->fnNode.node.children);
}
}
@@ -967,8 +1100,10 @@ void geo_process_held_object(struct GraphNodeHeldObject *node) {
/**
* Processes the children of the given GraphNode if it has any
*/
-void geo_try_process_children(struct GraphNode *node) {
- if (node->children != NULL) {
+void geo_try_process_children(struct GraphNode *node)
+{
+ if (node->children != NULL)
+ {
geo_process_node_and_siblings(node->children);
}
}
@@ -978,92 +1113,104 @@ void geo_try_process_children(struct GraphNode *node) {
* The first argument is the start node, and all its siblings will
* be iterated over.
*/
-void geo_process_node_and_siblings(struct GraphNode *firstNode) {
+void geo_process_node_and_siblings(struct GraphNode *firstNode)
+{
s16 iterateChildren = TRUE;
struct GraphNode *curGraphNode = firstNode;
struct GraphNode *parent = curGraphNode->parent;
// In the case of a switch node, exactly one of the children of the node is
// processed instead of all children like usual
- if (parent != NULL) {
- iterateChildren = (parent->type != GRAPH_NODE_TYPE_SWITCH_CASE);
+ if (parent != NULL)
+ {
+ iterateChildren = parent->type != GRAPH_NODE_TYPE_SWITCH_CASE;
}
- do {
- if (curGraphNode->flags & GRAPH_RENDER_ACTIVE) {
- if (curGraphNode->flags & GRAPH_RENDER_CHILDREN_FIRST) {
+ do
+ {
+ if (curGraphNode->flags & GRAPH_RENDER_ACTIVE)
+ {
+ if (curGraphNode->flags & GRAPH_RENDER_CHILDREN_FIRST)
+ {
geo_try_process_children(curGraphNode);
- } else {
- switch (curGraphNode->type) {
+ }
+ else
+ {
+ switch (curGraphNode->type)
+ {
case GRAPH_NODE_TYPE_ORTHO_PROJECTION:
- geo_process_ortho_projection((struct GraphNodeOrthoProjection *) curGraphNode);
+ geo_process_ortho_projection((struct GraphNodeOrthoProjection *)curGraphNode);
break;
case GRAPH_NODE_TYPE_PERSPECTIVE:
- geo_process_perspective((struct GraphNodePerspective *) curGraphNode);
+ geo_process_perspective((struct GraphNodePerspective *)curGraphNode);
break;
case GRAPH_NODE_TYPE_MASTER_LIST:
- geo_process_master_list((struct GraphNodeMasterList *) curGraphNode);
+ geo_process_master_list((struct GraphNodeMasterList *)curGraphNode);
break;
case GRAPH_NODE_TYPE_LEVEL_OF_DETAIL:
- geo_process_level_of_detail((struct GraphNodeLevelOfDetail *) curGraphNode);
+ geo_process_level_of_detail((struct GraphNodeLevelOfDetail *)curGraphNode);
break;
case GRAPH_NODE_TYPE_SWITCH_CASE:
- geo_process_switch((struct GraphNodeSwitchCase *) curGraphNode);
+ geo_process_switch((struct GraphNodeSwitchCase *)curGraphNode);
break;
case GRAPH_NODE_TYPE_CAMERA:
- geo_process_camera((struct GraphNodeCamera *) curGraphNode);
+ geo_process_camera((struct GraphNodeCamera *)curGraphNode);
break;
case GRAPH_NODE_TYPE_TRANSLATION_ROTATION:
geo_process_translation_rotation(
- (struct GraphNodeTranslationRotation *) curGraphNode);
+ (struct GraphNodeTranslationRotation *)curGraphNode);
break;
case GRAPH_NODE_TYPE_TRANSLATION:
- geo_process_translation((struct GraphNodeTranslation *) curGraphNode);
+ geo_process_translation((struct GraphNodeTranslation *)curGraphNode);
break;
case GRAPH_NODE_TYPE_ROTATION:
- geo_process_rotation((struct GraphNodeRotation *) curGraphNode);
+ geo_process_rotation((struct GraphNodeRotation *)curGraphNode);
break;
case GRAPH_NODE_TYPE_OBJECT:
- geo_process_object((struct Object *) curGraphNode);
+ geo_process_object((struct Object *)curGraphNode);
break;
case GRAPH_NODE_TYPE_ANIMATED_PART:
- geo_process_animated_part((struct GraphNodeAnimatedPart *) curGraphNode);
+ geo_process_animated_part((struct GraphNodeAnimatedPart *)curGraphNode);
break;
case GRAPH_NODE_TYPE_BILLBOARD:
- geo_process_billboard((struct GraphNodeBillboard *) curGraphNode);
+ geo_process_billboard((struct GraphNodeBillboard *)curGraphNode);
break;
case GRAPH_NODE_TYPE_DISPLAY_LIST:
- geo_process_display_list((struct GraphNodeDisplayList *) curGraphNode);
+ geo_process_display_list((struct GraphNodeDisplayList *)curGraphNode);
break;
case GRAPH_NODE_TYPE_SCALE:
- geo_process_scale((struct GraphNodeScale *) curGraphNode);
+ geo_process_scale((struct GraphNodeScale *)curGraphNode);
break;
case GRAPH_NODE_TYPE_SHADOW:
- geo_process_shadow((struct GraphNodeShadow *) curGraphNode);
+ geo_process_shadow((struct GraphNodeShadow *)curGraphNode);
break;
case GRAPH_NODE_TYPE_OBJECT_PARENT:
- geo_process_object_parent((struct GraphNodeObjectParent *) curGraphNode);
+ geo_process_object_parent((struct GraphNodeObjectParent *)curGraphNode);
break;
case GRAPH_NODE_TYPE_GENERATED_LIST:
- geo_process_generated_list((struct GraphNodeGenerated *) curGraphNode);
+ geo_process_generated_list((struct GraphNodeGenerated *)curGraphNode);
break;
case GRAPH_NODE_TYPE_BACKGROUND:
- geo_process_background((struct GraphNodeBackground *) curGraphNode);
+ geo_process_background((struct GraphNodeBackground *)curGraphNode);
break;
case GRAPH_NODE_TYPE_HELD_OBJ:
- geo_process_held_object((struct GraphNodeHeldObject *) curGraphNode);
+ geo_process_held_object((struct GraphNodeHeldObject *)curGraphNode);
break;
default:
- geo_try_process_children((struct GraphNode *) curGraphNode);
+ geo_try_process_children(curGraphNode);
break;
}
}
- } else {
- if (curGraphNode->type == GRAPH_NODE_TYPE_OBJECT) {
- ((struct GraphNodeObject *) curGraphNode)->throwMatrix = NULL;
+ }
+ else
+ {
+ if (curGraphNode->type == GRAPH_NODE_TYPE_OBJECT)
+ {
+ ((struct GraphNodeObject *)curGraphNode)->throwMatrix = NULL;
}
}
- } while (iterateChildren && (curGraphNode = curGraphNode->next) != firstNode);
+ }
+ while (iterateChildren && (curGraphNode = curGraphNode->next) != firstNode);
}
/**
@@ -1073,11 +1220,11 @@ void geo_process_node_and_siblings(struct GraphNode *firstNode) {
*/
// void geo_process_root(struct GraphNodeRoot *node, Vp *b, Vp *c, s32 clearColor) {
// UNUSED s32 unused;
-//
+//
// if (node->node.flags & GRAPH_RENDER_ACTIVE) {
// Mtx *initialMatrix;
// Vp *viewport = alloc_display_list(sizeof(*viewport));
-//
+//
// #ifdef USE_SYSTEM_MALLOC
// gDisplayListHeap = alloc_only_pool_init();
// #else
@@ -1089,7 +1236,7 @@ void geo_process_node_and_siblings(struct GraphNode *firstNode) {
// gCurAnimType = 0;
// vec3s_set(viewport->vp.vtrans, node->x * 4, node->y * 4, 511);
// vec3s_set(viewport->vp.vscale, node->width * 4, node->height * 4, 511);
-//
+//
// // if (b != NULL) {
// // clear_frame_buffer(clearColor);
// // make_viewport_clip_rect(b);
@@ -1099,7 +1246,7 @@ void geo_process_node_and_siblings(struct GraphNode *firstNode) {
// // clear_frame_buffer(clearColor);
// // make_viewport_clip_rect(c);
// // }
-//
+//
// mtxf_identity(gMatStack[gMatStackIndex]);
// mtxf_to_mtx(initialMatrix, gMatStack[gMatStackIndex]);
// gMatStackFixed[gMatStackIndex] = initialMatrix;
@@ -1138,26 +1285,29 @@ void geo_process_root_hack_single_node(struct GraphNode *node)
mtxf_to_mtx(initialMatrix, gMatStack[gMatStackIndex]);
gMatStackFixed[gMatStackIndex] = initialMatrix;
gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(gMatStackFixed[gMatStackIndex]),
- G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH);
+ G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH);
// Hacked in from geo_proces_object since we only have Mario
//geo_process_object( node );
- if (gMarioObject->header.gfx.throwMatrix != NULL) {
+ if (gMarioObject->header.gfx.throwMatrix != NULL)
+ {
mtxf_mul(gMatStack[gMatStackIndex + 1], *gMarioObject->header.gfx.throwMatrix, gMatStack[gMatStackIndex]);
- mtxf_scale_vec3f( gMatStack[gMatStackIndex + 1], gMatStack[gMatStackIndex + 1], gMarioObject->header.gfx.scale );
+ mtxf_scale_vec3f(gMatStack[gMatStackIndex + 1], gMatStack[gMatStackIndex + 1], gMarioObject->header.gfx.scale);
gMarioObject->header.gfx.throwMatrix = &gMatStack[++gMatStackIndex];
}
- else {
+ else
+ {
Mat4 identity, scale, rotTran;
- mtxf_identity( identity );
- mtxf_scale_vec3f( scale, identity, gMarioObject->header.gfx.scale );
- mtxf_rotate_zxy_and_translate( rotTran, gMarioObject->header.gfx.pos, gMarioObject->header.gfx.angle );
- mtxf_mul( gMatStack[++gMatStackIndex], scale, rotTran );
+ mtxf_identity(identity);
+ mtxf_scale_vec3f(scale, identity, gMarioObject->header.gfx.scale);
+ mtxf_rotate_zxy_and_translate(rotTran, gMarioObject->header.gfx.pos, gMarioObject->header.gfx.angle);
+ mtxf_mul(gMatStack[++gMatStackIndex], scale, rotTran);
}
geo_set_animation_globals(&gMarioObject->header.gfx.animInfo, 1);
gCurGraphNodeRoot = (struct GraphNodeRoot *)node;
- if (node->children != NULL) {
+ if (node->children != NULL)
+ {
geo_process_node_and_siblings(node->children);
}
gCurGraphNodeRoot = NULL;
diff --git a/src/decomp/game/rendering_graph_node.h b/src/decomp/game/rendering_graph_node.h
index 5fe5eb9..b89777c 100644
--- a/src/decomp/game/rendering_graph_node.h
+++ b/src/decomp/game/rendering_graph_node.h
@@ -27,6 +27,7 @@ extern struct GraphNodeHeldObject *gCurGraphNodeHeldObject;
#define ANIM_TYPE_ROTATION 5
void geo_process_node_and_siblings(struct GraphNode *firstNode);
+
//void geo_process_root(struct GraphNodeRoot *node, Vp *b, Vp *c, s32 clearColor);
void geo_process_root_hack_single_node(struct GraphNode *node);
diff --git a/src/decomp/game/save_file.h b/src/decomp/game/save_file.h
index 9d6eb5e..ed28509 100644
--- a/src/decomp/game/save_file.h
+++ b/src/decomp/game/save_file.h
@@ -42,7 +42,8 @@ struct SaveFile
struct SaveBlockSignature signature;
};
-enum SaveFileIndex {
+enum SaveFileIndex
+{
SAVE_FILE_A,
SAVE_FILE_B,
SAVE_FILE_C,
@@ -57,15 +58,15 @@ struct MainMenuSaveData
u32 coinScoreAges[NUM_SAVE_FILES];
u16 soundMode;
-#ifdef VERSION_EU
+ #ifdef VERSION_EU
u16 language;
-#define SUBTRAHEND 8
-#else
-#define SUBTRAHEND 6
-#endif
+ #define SUBTRAHEND 8
+ #else
+ #define SUBTRAHEND 6
+ #endif
// Pad to match the EEPROM size of 0x200 (10 bytes on JP/US, 8 bytes on EU)
- u8 filler[ 128 ]; // EEPROM_SIZE / 2 - SUBTRAHEND - NUM_SAVE_FILES * (4 + sizeof(struct SaveFile))];
+ u8 filler[128]; // EEPROM_SIZE / 2 - SUBTRAHEND - NUM_SAVE_FILES * (4 + sizeof(struct SaveFile))];
struct SaveBlockSignature signature;
};
@@ -75,7 +76,7 @@ struct SaveBuffer
// Each of the four save files has two copies. If one is bad, the other is used as a backup.
struct SaveFile files[NUM_SAVE_FILES][2];
// The main menu data has two copies. If one is bad, the other is used as a backup.
-// struct MainMenuSaveData menuData[0];
+ // struct MainMenuSaveData menuData[0];
};
extern u8 gLastCompletedCourseNum;
@@ -120,12 +121,18 @@ extern s8 gLevelToCourseNumTable[];
// Variable for setting a warp checkpoint.
// possibly a WarpDest struct where arg is a union. TODO: Check?
-struct WarpCheckpoint {
- /*0x00*/ u8 actNum;
- /*0x01*/ u8 courseNum;
- /*0x02*/ u8 levelID;
- /*0x03*/ u8 areaNum;
- /*0x04*/ u8 warpNode;
+struct WarpCheckpoint
+{
+ /*0x00*/
+ u8 actNum;
+ /*0x01*/
+ u8 courseNum;
+ /*0x02*/
+ u8 levelID;
+ /*0x03*/
+ u8 areaNum;
+ /*0x04*/
+ u8 warpNode;
};
extern struct WarpCheckpoint gWarpCheckpoint;
@@ -134,38 +141,57 @@ extern s8 gMainMenuDataModified;
extern s8 gSaveFileModified;
void save_file_do_save(s32 fileIndex);
+
void save_file_erase(s32 fileIndex);
-BAD_RETURN(s32) save_file_copy(s32 srcFileIndex, s32 destFileIndex);
+
+BAD_RETURN (s32) save_file_copy(s32 srcFileIndex, s32 destFileIndex);
+
void save_file_load_all(void);
+
void save_file_reload(void);
+
void save_file_collect_star_or_key(s16 coinScore, s16 starIndex);
+
s32 save_file_exists(s32 fileIndex);
+
u32 save_file_get_max_coin_score(s32 courseIndex);
+
s32 save_file_get_course_star_count(s32 fileIndex, s32 courseIndex);
+
//s32 save_file_get_total_star_count(s32 fileIndex, s32 minCourse, s32 maxCourse);
//void save_file_set_flags(u32 flags);
//void save_file_clear_flags(u32 flags);
//u32 save_file_get_flags(void);
u32 save_file_get_star_flags(s32 fileIndex, s32 courseIndex);
+
void save_file_set_star_flags(s32 fileIndex, s32 courseIndex, u32 starFlags);
+
s32 save_file_get_course_coin_score(s32 fileIndex, s32 courseIndex);
+
s32 save_file_is_cannon_unlocked(void);
+
void save_file_set_cannon_unlocked(void);
+
void save_file_set_cap_pos(s16 x, s16 y, s16 z);
+
s32 save_file_get_cap_pos(Vec3s capPos);
+
void save_file_set_sound_mode(u16 mode);
+
u16 save_file_get_sound_mode(void);
+
void save_file_move_cap_to_default_location(void);
void disable_warp_checkpoint(void);
+
void check_if_should_set_warp_checkpoint(struct WarpNode *warpNode);
+
s32 check_warp_checkpoint(struct WarpNode *warpNode);
#ifdef VERSION_EU
-enum EuLanguages {
- LANGUAGE_ENGLISH,
- LANGUAGE_FRENCH,
- LANGUAGE_GERMAN
+enum EuLanguages
+{
+ LANGUAGE_ENGLISH, LANGUAGE_FRENCH, LANGUAGE_GERMAN
};
void eu_set_language(u16 language);
diff --git a/src/decomp/game/sound_init.c b/src/decomp/game/sound_init.c
index 985fac8..fcd1abd 100644
--- a/src/decomp/game/sound_init.c
+++ b/src/decomp/game/sound_init.c
@@ -34,8 +34,8 @@ static u16 sCurrentMusic = MUSIC_NONE;
static u16 sCurrentShellMusic = MUSIC_NONE;
static u16 sCurrentCapMusic = MUSIC_NONE;
static u8 sPlayingInfiniteStairs = FALSE;
-UNUSED static u8 unused8032C6D8[16] = { 0 };
-static s16 sSoundMenuModeToSoundMode[] = { SOUND_MODE_STEREO, SOUND_MODE_MONO, SOUND_MODE_HEADSET };
+UNUSED static u8 unused8032C6D8[16] = {0};
+static s16 sSoundMenuModeToSoundMode[] = {SOUND_MODE_STEREO, SOUND_MODE_MONO, SOUND_MODE_HEADSET};
// Only the 20th array element is used.
static u32 sMenuSoundsExtra[] = {
SOUND_MOVING_TERRAIN_SLIDE + (0 << 16),
@@ -82,15 +82,18 @@ void play_menu_sounds_extra(s32 a, void *b);
/**
* Called from threads: thread5_game_loop
*/
-void reset_volume(void) {
+void reset_volume(void)
+{
sMusicVolume = 0;
}
/**
* Called from threads: thread5_game_loop
*/
-void lower_background_noise(s32 a) {
- switch (a) {
+void lower_background_noise(s32 a)
+{
+ switch (a)
+ {
case 1:
set_audio_muted(TRUE);
break;
@@ -104,8 +107,10 @@ void lower_background_noise(s32 a) {
/**
* Called from threads: thread5_game_loop
*/
-void raise_background_noise(s32 a) {
- switch (a) {
+void raise_background_noise(s32 a)
+{
+ switch (a)
+ {
case 1:
set_audio_muted(FALSE);
break;
@@ -119,8 +124,10 @@ void raise_background_noise(s32 a) {
/**
* Called from threads: thread5_game_loop
*/
-void disable_background_sound(void) {
- if (sBgMusicDisabled == FALSE) {
+void disable_background_sound(void)
+{
+ if (sBgMusicDisabled == FALSE)
+ {
sBgMusicDisabled = TRUE;
sound_banks_disable(SEQ_PLAYER_SFX, SOUND_BANKS_BACKGROUND);
}
@@ -129,8 +136,10 @@ void disable_background_sound(void) {
/**
* Called from threads: thread5_game_loop
*/
-void enable_background_sound(void) {
- if (sBgMusicDisabled == TRUE) {
+void enable_background_sound(void)
+{
+ if (sBgMusicDisabled == TRUE)
+ {
sBgMusicDisabled = FALSE;
sound_banks_enable(SEQ_PLAYER_SFX, SOUND_BANKS_BACKGROUND);
}
@@ -141,8 +150,10 @@ void enable_background_sound(void) {
*
* Called from threads: thread5_game_loop
*/
-void set_sound_mode(u16 soundMode) {
- if (soundMode < 3) {
+void set_sound_mode(u16 soundMode)
+{
+ if (soundMode < 3)
+ {
audio_set_sound_mode(sSoundMenuModeToSoundMode[soundMode]);
}
}
@@ -152,33 +163,51 @@ void set_sound_mode(u16 soundMode) {
*
* Called from threads: thread5_game_loop
*/
-void play_menu_sounds(s16 soundMenuFlags) {
- if (soundMenuFlags & SOUND_MENU_FLAG_HANDAPPEAR) {
+void play_menu_sounds(s16 soundMenuFlags)
+{
+ if (soundMenuFlags & SOUND_MENU_FLAG_HANDAPPEAR)
+ {
play_sound(SOUND_MENU_HAND_APPEAR, gGlobalSoundSource);
- } else if (soundMenuFlags & SOUND_MENU_FLAG_HANDISAPPEAR) {
+ }
+ else if (soundMenuFlags & SOUND_MENU_FLAG_HANDISAPPEAR)
+ {
play_sound(SOUND_MENU_HAND_DISAPPEAR, gGlobalSoundSource);
- } else if (soundMenuFlags & SOUND_MENU_FLAG_UNKNOWN1) {
+ }
+ else if (soundMenuFlags & SOUND_MENU_FLAG_UNKNOWN1)
+ {
play_sound(SOUND_MENU_UNK0C, gGlobalSoundSource);
- } else if (soundMenuFlags & SOUND_MENU_FLAG_PINCHMARIOFACE) {
+ }
+ else if (soundMenuFlags & SOUND_MENU_FLAG_PINCHMARIOFACE)
+ {
play_sound(SOUND_MENU_PINCH_MARIO_FACE, gGlobalSoundSource);
- } else if (soundMenuFlags & SOUND_MENU_FLAG_PINCHMARIOFACE2) {
+ }
+ else if (soundMenuFlags & SOUND_MENU_FLAG_PINCHMARIOFACE2)
+ {
play_sound(SOUND_MENU_PINCH_MARIO_FACE, gGlobalSoundSource);
- } else if (soundMenuFlags & SOUND_MENU_FLAG_LETGOMARIOFACE) {
+ }
+ else if (soundMenuFlags & SOUND_MENU_FLAG_LETGOMARIOFACE)
+ {
play_sound(SOUND_MENU_LET_GO_MARIO_FACE, gGlobalSoundSource);
- } else if (soundMenuFlags & SOUND_MENU_FLAG_CAMERAZOOMIN) {
+ }
+ else if (soundMenuFlags & SOUND_MENU_FLAG_CAMERAZOOMIN)
+ {
play_sound(SOUND_MENU_CAMERA_ZOOM_IN, gGlobalSoundSource);
- } else if (soundMenuFlags & SOUND_MENU_FLAG_CAMERAZOOMOUT) {
+ }
+ else if (soundMenuFlags & SOUND_MENU_FLAG_CAMERAZOOMOUT)
+ {
play_sound(SOUND_MENU_CAMERA_ZOOM_OUT, gGlobalSoundSource);
}
- if (soundMenuFlags & 0x100) {
+ if (soundMenuFlags & 0x100)
+ {
play_menu_sounds_extra(20, NULL);
}
-#if ENABLE_RUMBLE
- if (soundMenuFlags & SOUND_MENU_FLAG_LETGOMARIOFACE) {
+ #if ENABLE_RUMBLE
+ if (soundMenuFlags & SOUND_MENU_FLAG_LETGOMARIOFACE)
+ {
queue_rumble_data(10, 60);
}
-#endif
+ #endif
}
/**
@@ -245,7 +274,8 @@ void play_menu_sounds(s16 soundMenuFlags) {
/**
* Called from threads: thread3_main, thread5_game_loop
*/
-void fadeout_music(s16 fadeOutTime) {
+void fadeout_music(s16 fadeOutTime)
+{
func_803210D4(fadeOutTime);
sCurrentMusic = MUSIC_NONE;
sCurrentShellMusic = MUSIC_NONE;
@@ -255,7 +285,8 @@ void fadeout_music(s16 fadeOutTime) {
/**
* Called from threads: thread5_game_loop
*/
-void fadeout_level_music(s16 fadeTimer) {
+void fadeout_level_music(s16 fadeTimer)
+{
seq_player_fade_out(SEQ_PLAYER_LEVEL, fadeTimer);
sCurrentMusic = MUSIC_NONE;
sCurrentShellMusic = MUSIC_NONE;
@@ -265,7 +296,8 @@ void fadeout_level_music(s16 fadeTimer) {
/**
* Called from threads: thread5_game_loop
*/
-void play_cutscene_music(u16 seqArgs) {
+void play_cutscene_music(u16 seqArgs)
+{
play_music(SEQ_PLAYER_LEVEL, seqArgs, 0);
sCurrentMusic = seqArgs;
}
@@ -273,7 +305,8 @@ void play_cutscene_music(u16 seqArgs) {
/**
* Called from threads: thread5_game_loop
*/
-void play_shell_music(void) {
+void play_shell_music(void)
+{
play_music(SEQ_PLAYER_LEVEL, SEQUENCE_ARGS(4, SEQ_EVENT_POWERUP | SEQ_VARIATION), 0);
sCurrentShellMusic = SEQUENCE_ARGS(4, SEQ_EVENT_POWERUP | SEQ_VARIATION);
}
@@ -281,8 +314,10 @@ void play_shell_music(void) {
/**
* Called from threads: thread5_game_loop
*/
-void stop_shell_music(void) {
- if (sCurrentShellMusic != MUSIC_NONE) {
+void stop_shell_music(void)
+{
+ if (sCurrentShellMusic != MUSIC_NONE)
+ {
stop_background_music(sCurrentShellMusic);
sCurrentShellMusic = MUSIC_NONE;
}
@@ -291,9 +326,11 @@ void stop_shell_music(void) {
/**
* Called from threads: thread5_game_loop
*/
-void play_cap_music(u16 seqArgs) {
+void play_cap_music(u16 seqArgs)
+{
play_music(SEQ_PLAYER_LEVEL, seqArgs, 0);
- if (sCurrentCapMusic != MUSIC_NONE && sCurrentCapMusic != seqArgs) {
+ if (sCurrentCapMusic != MUSIC_NONE && sCurrentCapMusic != seqArgs)
+ {
stop_background_music(sCurrentCapMusic);
}
sCurrentCapMusic = seqArgs;
@@ -302,8 +339,10 @@ void play_cap_music(u16 seqArgs) {
/**
* Called from threads: thread5_game_loop
*/
-void fadeout_cap_music(void) {
- if (sCurrentCapMusic != MUSIC_NONE) {
+void fadeout_cap_music(void)
+{
+ if (sCurrentCapMusic != MUSIC_NONE)
+ {
fadeout_background_music(sCurrentCapMusic, 600);
}
}
@@ -311,8 +350,10 @@ void fadeout_cap_music(void) {
/**
* Called from threads: thread5_game_loop
*/
-void stop_cap_music(void) {
- if (sCurrentCapMusic != MUSIC_NONE) {
+void stop_cap_music(void)
+{
+ if (sCurrentCapMusic != MUSIC_NONE)
+ {
stop_background_music(sCurrentCapMusic);
sCurrentCapMusic = MUSIC_NONE;
}
@@ -321,7 +362,8 @@ void stop_cap_music(void) {
/**
* Called from threads: thread5_game_loop
*/
-void play_menu_sounds_extra(s32 a, void *b) {
+void play_menu_sounds_extra(s32 a, void *b)
+{
play_sound(sMenuSoundsExtra[a], b);
}
diff --git a/src/decomp/game/sound_init.h b/src/decomp/game/sound_init.h
index 82c3b0c..97eb958 100644
--- a/src/decomp/game/sound_init.h
+++ b/src/decomp/game/sound_init.h
@@ -19,23 +19,38 @@
#define SOUND_MENU_MODE_HEADSET 2
void reset_volume(void);
+
void raise_background_noise(s32 a);
+
void lower_background_noise(s32 a);
+
void disable_background_sound(void);
+
void enable_background_sound(void);
+
void set_sound_mode(u16 soundMode);
+
void play_menu_sounds(s16 soundMenuFlags);
+
//void play_painting_eject_sound(void);
//void play_infinite_stairs_music(void);
//void set_background_music(u16 a, u16 seqArgs, s16 fadeTimer);
void fadeout_music(s16 fadeOutTime);
+
void fadeout_level_music(s16 fadeTimer);
+
void play_cutscene_music(u16 seqArgs);
+
void play_shell_music(void);
+
void stop_shell_music(void);
+
void play_cap_music(u16 seqArgs);
+
void fadeout_cap_music(void);
+
void stop_cap_music(void);
+
//void audio_game_loop_tick(void);
//void thread4_sound(UNUSED void *arg);
diff --git a/src/decomp/global_state.c b/src/decomp/global_state.c
index 5d9bc6c..ac09076 100644
--- a/src/decomp/global_state.c
+++ b/src/decomp/global_state.c
@@ -7,18 +7,18 @@ struct GlobalState *g_state = 0;
struct GlobalState *global_state_create(void)
{
- struct GlobalState *state = malloc( sizeof( struct GlobalState ));
- memset( state, 0, sizeof( struct GlobalState ));
- state->msSwimStrength = MIN_SWIM_STRENGTH;
- return state;
+ struct GlobalState *state = malloc(sizeof(struct GlobalState));
+ memset(state, 0, sizeof(struct GlobalState));
+ state->msSwimStrength = MIN_SWIM_STRENGTH;
+ return state;
}
void global_state_bind(struct GlobalState *state)
{
- g_state = state;
+ g_state = state;
}
void global_state_delete(struct GlobalState *state)
{
- free( state );
+ free(state);
}
\ No newline at end of file
diff --git a/src/decomp/global_state.h b/src/decomp/global_state.h
index 9fe431e..a4e91b0 100644
--- a/src/decomp/global_state.h
+++ b/src/decomp/global_state.h
@@ -50,5 +50,7 @@ struct GlobalState
extern struct GlobalState *g_state;
extern struct GlobalState *global_state_create(void);
+
extern void global_state_bind(struct GlobalState *state);
+
extern void global_state_delete(struct GlobalState *state);
\ No newline at end of file
diff --git a/src/decomp/include/PR/abi.h b/src/decomp/include/PR/abi.h
index b4b2f84..57a765e 100644
--- a/src/decomp/include/PR/abi.h
+++ b/src/decomp/include/PR/abi.h
@@ -98,168 +98,188 @@
* Data Structures.
*/
-typedef struct {
- unsigned int cmd:8;
- unsigned int flags:8;
- unsigned int gain:16;
- unsigned int addr;
+typedef struct
+{
+ unsigned int cmd: 8;
+ unsigned int flags: 8;
+ unsigned int gain: 16;
+ unsigned int addr;
} Aadpcm;
-typedef struct {
- unsigned int cmd:8;
- unsigned int flags:8;
- unsigned int gain:16;
- unsigned int addr;
+typedef struct
+{
+ unsigned int cmd: 8;
+ unsigned int flags: 8;
+ unsigned int gain: 16;
+ unsigned int addr;
} Apolef;
-typedef struct {
- unsigned int cmd:8;
- unsigned int flags:8;
- unsigned int pad1:16;
- unsigned int addr;
+typedef struct
+{
+ unsigned int cmd: 8;
+ unsigned int flags: 8;
+ unsigned int pad1: 16;
+ unsigned int addr;
} Aenvelope;
-typedef struct {
- unsigned int cmd:8;
- unsigned int pad1:8;
- unsigned int dmem:16;
- unsigned int pad2:16;
- unsigned int count:16;
+typedef struct
+{
+ unsigned int cmd: 8;
+ unsigned int pad1: 8;
+ unsigned int dmem: 16;
+ unsigned int pad2: 16;
+ unsigned int count: 16;
} Aclearbuff;
-typedef struct {
- unsigned int cmd:8;
- unsigned int pad1:8;
- unsigned int pad2:16;
- unsigned int inL:16;
- unsigned int inR:16;
+typedef struct
+{
+ unsigned int cmd: 8;
+ unsigned int pad1: 8;
+ unsigned int pad2: 16;
+ unsigned int inL: 16;
+ unsigned int inR: 16;
} Ainterleave;
-typedef struct {
- unsigned int cmd:8;
- unsigned int pad1:24;
- unsigned int addr;
+typedef struct
+{
+ unsigned int cmd: 8;
+ unsigned int pad1: 24;
+ unsigned int addr;
} Aloadbuff;
-typedef struct {
- unsigned int cmd:8;
- unsigned int flags:8;
- unsigned int pad1:16;
- unsigned int addr;
+typedef struct
+{
+ unsigned int cmd: 8;
+ unsigned int flags: 8;
+ unsigned int pad1: 16;
+ unsigned int addr;
} Aenvmixer;
-typedef struct {
- unsigned int cmd:8;
- unsigned int flags:8;
- unsigned int gain:16;
- unsigned int dmemi:16;
- unsigned int dmemo:16;
+typedef struct
+{
+ unsigned int cmd: 8;
+ unsigned int flags: 8;
+ unsigned int gain: 16;
+ unsigned int dmemi: 16;
+ unsigned int dmemo: 16;
} Amixer;
-typedef struct {
- unsigned int cmd:8;
- unsigned int flags:8;
- unsigned int dmem2:16;
- unsigned int addr;
+typedef struct
+{
+ unsigned int cmd: 8;
+ unsigned int flags: 8;
+ unsigned int dmem2: 16;
+ unsigned int addr;
} Apan;
-typedef struct {
- unsigned int cmd:8;
- unsigned int flags:8;
- unsigned int pitch:16;
- unsigned int addr;
+typedef struct
+{
+ unsigned int cmd: 8;
+ unsigned int flags: 8;
+ unsigned int pitch: 16;
+ unsigned int addr;
} Aresample;
-typedef struct {
- unsigned int cmd:8;
- unsigned int flags:8;
- unsigned int pad1:16;
- unsigned int addr;
+typedef struct
+{
+ unsigned int cmd: 8;
+ unsigned int flags: 8;
+ unsigned int pad1: 16;
+ unsigned int addr;
} Areverb;
-typedef struct {
- unsigned int cmd:8;
- unsigned int pad1:24;
- unsigned int addr;
+typedef struct
+{
+ unsigned int cmd: 8;
+ unsigned int pad1: 24;
+ unsigned int addr;
} Asavebuff;
-typedef struct {
- unsigned int cmd:8;
- unsigned int pad1:24;
- unsigned int pad2:2;
- unsigned int number:4;
- unsigned int base:24;
+typedef struct
+{
+ unsigned int cmd: 8;
+ unsigned int pad1: 24;
+ unsigned int pad2: 2;
+ unsigned int number: 4;
+ unsigned int base: 24;
} Asegment;
-typedef struct {
- unsigned int cmd:8;
- unsigned int flags:8;
- unsigned int dmemin:16;
- unsigned int dmemout:16;
- unsigned int count:16;
+typedef struct
+{
+ unsigned int cmd: 8;
+ unsigned int flags: 8;
+ unsigned int dmemin: 16;
+ unsigned int dmemout: 16;
+ unsigned int count: 16;
} Asetbuff;
-typedef struct {
- unsigned int cmd:8;
- unsigned int flags:8;
- unsigned int vol:16;
- unsigned int voltgt:16;
- unsigned int volrate:16;
+typedef struct
+{
+ unsigned int cmd: 8;
+ unsigned int flags: 8;
+ unsigned int vol: 16;
+ unsigned int voltgt: 16;
+ unsigned int volrate: 16;
} Asetvol;
-typedef struct {
- unsigned int cmd:8;
- unsigned int pad1:8;
- unsigned int dmemin:16;
- unsigned int dmemout:16;
- unsigned int count:16;
+typedef struct
+{
+ unsigned int cmd: 8;
+ unsigned int pad1: 8;
+ unsigned int dmemin: 16;
+ unsigned int dmemout: 16;
+ unsigned int count: 16;
} Admemmove;
-typedef struct {
- unsigned int cmd:8;
- unsigned int pad1:8;
- unsigned int count:16;
- unsigned int addr;
+typedef struct
+{
+ unsigned int cmd: 8;
+ unsigned int pad1: 8;
+ unsigned int count: 16;
+ unsigned int addr;
} Aloadadpcm;
-typedef struct {
- unsigned int cmd:8;
- unsigned int pad1:8;
- unsigned int pad2:16;
- unsigned int addr;
+typedef struct
+{
+ unsigned int cmd: 8;
+ unsigned int pad1: 8;
+ unsigned int pad2: 16;
+ unsigned int addr;
} Asetloop;
/*
* Generic Acmd Packet
*/
-typedef struct {
+typedef struct
+{
uintptr_t w0;
uintptr_t w1;
} Awords;
-typedef union {
- Awords words;
+typedef union
+{
+ Awords words;
#if IS_BIG_ENDIAN && !IS_64_BIT
- Aadpcm adpcm;
- Apolef polef;
- Aclearbuff clearbuff;
- Aenvelope envelope;
- Ainterleave interleave;
- Aloadbuff loadbuff;
- Aenvmixer envmixer;
- Aresample resample;
- Areverb reverb;
- Asavebuff savebuff;
- Asegment segment;
- Asetbuff setbuff;
- Asetvol setvol;
- Admemmove dmemmove;
- Aloadadpcm loadadpcm;
- Amixer mixer;
- Asetloop setloop;
+Aadpcm adpcm;
+Apolef polef;
+Aclearbuff clearbuff;
+Aenvelope envelope;
+Ainterleave interleave;
+Aloadbuff loadbuff;
+Aenvmixer envmixer;
+Aresample resample;
+Areverb reverb;
+Asavebuff savebuff;
+Asegment segment;
+Asetbuff setbuff;
+Asetvol setvol;
+Admemmove dmemmove;
+Aloadadpcm loadadpcm;
+Amixer mixer;
+Asetloop setloop;
#endif
- long long int force_union_align; /* dummy, force alignment */
+long long int force_union_align; /* dummy, force alignment */
} Acmd;
/*
diff --git a/src/decomp/include/PR/gbi.h b/src/decomp/include/PR/gbi.h
index 4ff5de7..bdb3a70 100644
--- a/src/decomp/include/PR/gbi.h
+++ b/src/decomp/include/PR/gbi.h
@@ -24,14 +24,13 @@
#include "ultratypes.h"
-
// FROM mbi.h
/*
* the SHIFT macros are used to build display list commands, inserting
- * bit-fields into a 32-bit word. They take a value, a shift amount,
+ * bit-fields into a 32-bit word. They take a value, a shift amount,
* and a width.
*
- * For the left shift, the lower bits of the value are masked,
+ * For the left shift, the lower bits of the value are masked,
* then shifted left.
*
* For the right shift, the value is shifted right, then the lower bits
@@ -51,9 +50,6 @@
#define G_OFF (0)
-
-
-
/*
* To use the F3DEX ucodes, define F3DEX_GBI before include this file.
*
@@ -107,13 +103,13 @@
*
* IMPLEMENTATION NOTE:
* There is another group of RDP commands that includes the triangle commands
- * generated by the RSP code. These are the raw commands the rasterizer
- * hardware chews on, with slope info, etc. They will follow the RDP
+ * generated by the RSP code. These are the raw commands the rasterizer
+ * hardware chews on, with slope info, etc. They will follow the RDP
* ordering...
*
* IMPLEMENTATION NOTE:
- * The RDP hardware has some of these bit patterns wired up. If the hardware
- * changes, we must adjust this table, likewise we can't change/add things
+ * The RDP hardware has some of these bit patterns wired up. If the hardware
+ * changes, we must adjust this table, likewise we can't change/add things
* once the hardware is frozen. (actually, the RDP hardware only looks at
* the lower 6 bits of the command byte)
*
@@ -237,7 +233,7 @@
#define G_TEXRECT 0xe4 /* -28 */
-/*
+/*
* The following commands are the "generated" RDP commands; the user
* never sees them, the RSP microcode generates them.
*
@@ -357,7 +353,7 @@
*
* DO NOT USE THE LOW 8 BITS OF GEOMETRYMODE:
* The weird bit-ordering is for the micro-code: the lower byte
- * can be OR'd in with G_TRI_SHADE (11001100) to construct
+ * can be OR'd in with G_TRI_SHADE (11001100) to construct
* the triangle command directly. Don't break it...
*
* DO NOT USE THE HIGH 8 BITS OF GEOMETRYMODE:
@@ -371,7 +367,7 @@
* appropriately and use primcolor to see anything.
*
* G_SHADING_SMOOTH enabled means use all 3 colors of the triangle.
- * If it is not set, then do 'flat shading', where only one vertex color
+ * If it is not set, then do 'flat shading', where only one vertex color
* is used (and all 3 vertices are set to that same color by the ucode)
* See the man page for gSP1Triangle().
*
@@ -905,27 +901,27 @@
Z_CMP | Z_UPD | CVG_DST_FULL | ALPHA_CVG_SEL | \
ZMODE_OPA | \
GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM)
-
+
#define RM_ZB_XLU_SURF(clk) \
Z_CMP | IM_RD | CVG_DST_FULL | FORCE_BL | ZMODE_XLU | \
GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA)
-
+
#define RM_ZB_OPA_DECAL(clk) \
Z_CMP | CVG_DST_FULL | ALPHA_CVG_SEL | ZMODE_DEC | \
GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM)
-
+
#define RM_ZB_XLU_DECAL(clk) \
Z_CMP | IM_RD | CVG_DST_FULL | FORCE_BL | ZMODE_DEC | \
GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA)
-
+
#define RM_ZB_CLD_SURF(clk) \
Z_CMP | IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_XLU | \
GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA)
-
+
#define RM_ZB_OVL_SURF(clk) \
Z_CMP | IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_DEC | \
GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA)
-
+
#define RM_ZB_PCL_SURF(clk) \
Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | \
G_AC_DITHER | \
@@ -1118,7 +1114,7 @@
* element, we can't depend on the C compiler to align things
* properly.
*
- * 64-bit structure alignment is enforced by wrapping structures with
+ * 64-bit structure alignment is enforced by wrapping structures with
* unions that contain a dummy "long long int". Why this works is
* explained in the ANSI C Spec, or on page 186 of the second edition
* of K&R, "The C Programming Language".
@@ -1141,72 +1137,77 @@
/*
* Vertex (set up for use with colors)
*/
-typedef struct {
-#ifndef GBI_FLOATS
- short ob[3]; /* x, y, z */
-#else
- float ob[3]; /* x, y, z */
-#endif
- unsigned short flag;
- short tc[2]; /* texture coord */
- unsigned char cn[4]; /* color & alpha */
+typedef struct
+{
+ #ifndef GBI_FLOATS
+ short ob[3]; /* x, y, z */
+ #else
+ float ob[3]; /* x, y, z */
+ #endif
+ unsigned short flag;
+ short tc[2]; /* texture coord */
+ unsigned char cn[4]; /* color & alpha */
} Vtx_t;
/*
* Vertex (set up for use with normals)
*/
-typedef struct {
-#ifndef GBI_FLOATS
- short ob[3]; /* x, y, z */
-#else
- float ob[3]; /* x, y, z */
-#endif
- unsigned short flag;
- short tc[2]; /* texture coord */
- signed char n[3]; /* normal */
- unsigned char a; /* alpha */
+typedef struct
+{
+ #ifndef GBI_FLOATS
+ short ob[3]; /* x, y, z */
+ #else
+ float ob[3]; /* x, y, z */
+ #endif
+ unsigned short flag;
+ short tc[2]; /* texture coord */
+ signed char n[3]; /* normal */
+ unsigned char a; /* alpha */
} Vtx_tn;
-typedef union {
- Vtx_t v; /* Use this one for colors */
- Vtx_tn n; /* Use this one for normals */
- long long int force_structure_alignment;
+typedef union
+{
+ Vtx_t v; /* Use this one for colors */
+ Vtx_tn n; /* Use this one for normals */
+ long long int force_structure_alignment;
} Vtx;
/*
* Sprite structure
*/
-typedef struct {
- void *SourceImagePointer;
- void *TlutPointer;
- short Stride;
- short SubImageWidth;
- short SubImageHeight;
- char SourceImageType;
- char SourceImageBitSize;
- short SourceImageOffsetS;
- short SourceImageOffsetT;
- /* 20 bytes for above */
-
- /* padding to bring structure size to 64 bit allignment */
- char dummy[4];
+typedef struct
+{
+ void *SourceImagePointer;
+ void *TlutPointer;
+ short Stride;
+ short SubImageWidth;
+ short SubImageHeight;
+ char SourceImageType;
+ char SourceImageBitSize;
+ short SourceImageOffsetS;
+ short SourceImageOffsetT;
+ /* 20 bytes for above */
+ /* padding to bring structure size to 64 bit allignment */
+ char dummy[4];
} uSprite_t;
-typedef union {
- uSprite_t s;
+typedef union
+{
+ uSprite_t s;
- /* Need to make sure this is 64 bit aligned */
- long long int force_structure_allignment[3];
+ /* Need to make sure this is 64 bit aligned */
+ long long int force_structure_allignment[3];
} uSprite;
/*
* Triangle face
*/
-typedef struct {
- unsigned char flag;
- unsigned char v[3];
+typedef struct
+{
+ unsigned char flag;
+ unsigned char v[3];
} Tri;
#ifndef GBI_FLOATS
@@ -1215,14 +1216,16 @@ typedef struct {
* First 8 words are integer portion of the 4x4 matrix
* Last 8 words are the fraction portion of the 4x4 matrix
*/
-typedef s32 Mtx_t[4][4];
+typedef s32 Mtx_t[4][4];
-typedef union {
- Mtx_t m;
- long long int force_structure_alignment;
+typedef union
+{
+ Mtx_t m;
+ long long int force_structure_alignment;
} Mtx;
#else
-typedef struct {
+typedef struct
+{
float m[4][4];
} Mtx;
#endif
@@ -1261,15 +1264,17 @@ typedef struct {
* (SCREEN_WD/2)*4, (SCREEN_HT/2)*4, G_MAXZ, 0,
* (SCREEN_WD/2)*4, (SCREEN_HT/2)*4, 0, 0,
*/
-typedef struct {
- short vscale[4]; /* scale, 2 bits fraction */
- short vtrans[4]; /* translate, 2 bits fraction */
- /* both the above arrays are padded to 64-bit boundary */
+typedef struct
+{
+ short vscale[4]; /* scale, 2 bits fraction */
+ short vtrans[4]; /* translate, 2 bits fraction */
+ /* both the above arrays are padded to 64-bit boundary */
} Vp_t;
-typedef union {
- Vp_t vp;
- long long int force_structure_alignment;
+typedef union
+{
+ Vp_t vp;
+ long long int force_structure_alignment;
} Vp;
/*
@@ -1282,7 +1287,7 @@ typedef union {
*/
#ifdef F3DEX_GBI_2
/* 0,4 are reserved by G_MTX */
-# define G_MV_MMTX 2
+# define G_MV_MMTX 2
# define G_MV_PMTX 6
# define G_MV_VIEWPORT 8
# define G_MV_LIGHT 10
@@ -1340,7 +1345,7 @@ typedef union {
/*
* These are offsets from the address in the dmem table
- */
+ */
#define G_MWO_NUMLIGHT 0x00
#define G_MWO_CLIP_RNX 0x04
#define G_MWO_CLIP_RNY 0x0c
@@ -1422,93 +1427,109 @@ typedef union {
*
* Note: only directional (infinite) lights are currently supported.
*
- * Note: the weird order is for the DMEM alignment benefit of
+ * Note: the weird order is for the DMEM alignment benefit of
* the microcode.
*
*/
-typedef struct {
- unsigned char col[3]; /* diffuse light value (rgba) */
- char pad1;
- unsigned char colc[3]; /* copy of diffuse light value (rgba) */
- char pad2;
- signed char dir[3]; /* direction of light (normalized) */
- char pad3;
+typedef struct
+{
+ unsigned char col[3]; /* diffuse light value (rgba) */
+ char pad1;
+ unsigned char colc[3]; /* copy of diffuse light value (rgba) */
+ char pad2;
+ signed char dir[3]; /* direction of light (normalized) */
+ char pad3;
} Light_t;
-typedef struct {
- unsigned char col[3]; /* ambient light value (rgba) */
- char pad1;
- unsigned char colc[3]; /* copy of ambient light value (rgba) */
- char pad2;
+typedef struct
+{
+ unsigned char col[3]; /* ambient light value (rgba) */
+ char pad1;
+ unsigned char colc[3]; /* copy of ambient light value (rgba) */
+ char pad2;
} Ambient_t;
-typedef struct {
- int x1,y1,x2,y2; /* texture offsets for highlight 1/2 */
+typedef struct
+{
+ int x1, y1, x2, y2; /* texture offsets for highlight 1/2 */
} Hilite_t;
-typedef union {
- Light_t l;
- long long int force_structure_alignment[2];
+typedef union
+{
+ Light_t l;
+ long long int force_structure_alignment[2];
} Light;
-typedef union {
- Ambient_t l;
- long long int force_structure_alignment[1];
+typedef union
+{
+ Ambient_t l;
+ long long int force_structure_alignment[1];
} Ambient;
-typedef struct {
- Ambient a;
- Light l[7];
+typedef struct
+{
+ Ambient a;
+ Light l[7];
} Lightsn;
-typedef struct {
- Ambient a;
- Light l[1];
+typedef struct
+{
+ Ambient a;
+ Light l[1];
} Lights0;
-typedef struct {
- Ambient a;
- Light l[1];
+typedef struct
+{
+ Ambient a;
+ Light l[1];
} Lights1;
-typedef struct {
- Ambient a;
- Light l[2];
+typedef struct
+{
+ Ambient a;
+ Light l[2];
} Lights2;
-typedef struct {
- Ambient a;
- Light l[3];
+typedef struct
+{
+ Ambient a;
+ Light l[3];
} Lights3;
-typedef struct {
- Ambient a;
- Light l[4];
+typedef struct
+{
+ Ambient a;
+ Light l[4];
} Lights4;
-typedef struct {
- Ambient a;
- Light l[5];
+typedef struct
+{
+ Ambient a;
+ Light l[5];
} Lights5;
-typedef struct {
- Ambient a;
- Light l[6];
+typedef struct
+{
+ Ambient a;
+ Light l[6];
} Lights6;
-typedef struct {
- Ambient a;
- Light l[7];
+typedef struct
+{
+ Ambient a;
+ Light l[7];
} Lights7;
-typedef struct {
- Light l[2];
+typedef struct
+{
+ Light l[2];
} LookAt;
-typedef union {
- Hilite_t h;
- long int force_structure_alignment[4];
+typedef union
+{
+ Hilite_t h;
+ long int force_structure_alignment[4];
} Hilite;
#define gdSPDefLights0(ar,ag,ab) \
@@ -1571,27 +1592,30 @@ typedef union {
/*
* Graphics DMA Packet
*/
-typedef struct {
- int cmd:8;
- unsigned int par:8;
- unsigned int len:16;
- uintptr_t addr;
+typedef struct
+{
+ int cmd: 8;
+ unsigned int par: 8;
+ unsigned int len: 16;
+ uintptr_t addr;
} Gdma;
/*
* Graphics Immediate Mode Packet types
*/
-typedef struct {
- int cmd:8;
- int pad:24;
- Tri tri;
+typedef struct
+{
+ int cmd: 8;
+ int pad: 24;
+ Tri tri;
} Gtri;
-typedef struct {
- int cmd:8;
- int pad1:24;
- int pad2:24;
- unsigned char param:8;
+typedef struct
+{
+ int cmd: 8;
+ int pad1: 24;
+ int pad2: 24;
+ unsigned char param: 8;
} Gpopmtx;
/*
@@ -1603,121 +1627,133 @@ typedef struct {
* int base:24;
* } Gsegment;
*/
-typedef struct {
- int cmd:8;
- int pad0:8;
- int mw_index:8;
- int number:8;
- int pad1:8;
- int base:24;
+typedef struct
+{
+ int cmd: 8;
+ int pad0: 8;
+ int mw_index: 8;
+ int number: 8;
+ int pad1: 8;
+ int base: 24;
} Gsegment;
-typedef struct {
- int cmd:8;
- int pad0:8;
- int sft:8;
- int len:8;
- unsigned int data:32;
+typedef struct
+{
+ int cmd: 8;
+ int pad0: 8;
+ int sft: 8;
+ int len: 8;
+ unsigned int data: 32;
} GsetothermodeL;
-typedef struct {
- int cmd:8;
- int pad0:8;
- int sft:8;
- int len:8;
- unsigned int data:32;
+typedef struct
+{
+ int cmd: 8;
+ int pad0: 8;
+ int sft: 8;
+ int len: 8;
+ unsigned int data: 32;
} GsetothermodeH;
-typedef struct {
- unsigned char cmd;
- unsigned char lodscale;
- unsigned char tile;
- unsigned char on;
- unsigned short s;
- unsigned short t;
+typedef struct
+{
+ unsigned char cmd;
+ unsigned char lodscale;
+ unsigned char tile;
+ unsigned char on;
+ unsigned short s;
+ unsigned short t;
} Gtexture;
-typedef struct {
- int cmd:8;
- int pad:24;
- Tri line;
+typedef struct
+{
+ int cmd: 8;
+ int pad: 24;
+ Tri line;
} Gline3D;
-typedef struct {
- int cmd:8;
- int pad1:24;
- short int pad2;
- short int scale;
+typedef struct
+{
+ int cmd: 8;
+ int pad1: 24;
+ short int pad2;
+ short int scale;
} Gperspnorm;
/*
* RDP Packet types
*/
-typedef struct {
- int cmd:8;
- unsigned int fmt:3;
- unsigned int siz:2;
- unsigned int pad:7;
- unsigned int wd:12; /* really only 10 bits, extra */
- uintptr_t dram; /* to account for 1024 */
+typedef struct
+{
+ int cmd: 8;
+ unsigned int fmt: 3;
+ unsigned int siz: 2;
+ unsigned int pad: 7;
+ unsigned int wd: 12; /* really only 10 bits, extra */
+ uintptr_t dram; /* to account for 1024 */
} Gsetimg;
-typedef struct {
- int cmd:8;
- unsigned int muxs0:24;
- unsigned int muxs1:32;
+typedef struct
+{
+ int cmd: 8;
+ unsigned int muxs0: 24;
+ unsigned int muxs1: 32;
} Gsetcombine;
-typedef struct {
- int cmd:8;
- unsigned char pad;
- unsigned char prim_min_level;
- unsigned char prim_level;
- unsigned long color;
+typedef struct
+{
+ int cmd: 8;
+ unsigned char pad;
+ unsigned char prim_min_level;
+ unsigned char prim_level;
+ unsigned long color;
} Gsetcolor;
-typedef struct {
- int cmd:8;
- int x0:10;
- int x0frac:2;
- int y0:10;
- int y0frac:2;
- unsigned int pad:8;
- int x1:10;
- int x1frac:2;
- int y1:10;
- int y1frac:2;
+typedef struct
+{
+ int cmd: 8;
+ int x0: 10;
+ int x0frac: 2;
+ int y0: 10;
+ int y0frac: 2;
+ unsigned int pad: 8;
+ int x1: 10;
+ int x1frac: 2;
+ int y1: 10;
+ int y1frac: 2;
} Gfillrect;
-typedef struct {
- int cmd:8;
- unsigned int fmt:3;
- unsigned int siz:2;
- unsigned int pad0:1;
- unsigned int line:9;
- unsigned int tmem:9;
- unsigned int pad1:5;
- unsigned int tile:3;
- unsigned int palette:4;
- unsigned int ct:1;
- unsigned int mt:1;
- unsigned int maskt:4;
- unsigned int shiftt:4;
- unsigned int cs:1;
- unsigned int ms:1;
- unsigned int masks:4;
- unsigned int shifts:4;
+typedef struct
+{
+ int cmd: 8;
+ unsigned int fmt: 3;
+ unsigned int siz: 2;
+ unsigned int pad0: 1;
+ unsigned int line: 9;
+ unsigned int tmem: 9;
+ unsigned int pad1: 5;
+ unsigned int tile: 3;
+ unsigned int palette: 4;
+ unsigned int ct: 1;
+ unsigned int mt: 1;
+ unsigned int maskt: 4;
+ unsigned int shiftt: 4;
+ unsigned int cs: 1;
+ unsigned int ms: 1;
+ unsigned int masks: 4;
+ unsigned int shifts: 4;
} Gsettile;
-typedef struct {
- int cmd:8;
- unsigned int sl:12;
- unsigned int tl:12;
- int pad:5;
- unsigned int tile:3;
- unsigned int sh:12;
- unsigned int th:12;
+typedef struct
+{
+ int cmd: 8;
+ unsigned int sl: 12;
+ unsigned int tl: 12;
+ int pad: 5;
+ unsigned int tile: 3;
+ unsigned int sh: 12;
+ unsigned int th: 12;
} Gloadtile;
typedef Gloadtile Gloadblock;
@@ -1726,24 +1762,26 @@ typedef Gloadtile Gsettilesize;
typedef Gloadtile Gloadtlut;
-typedef struct {
- unsigned int cmd:8; /* command */
- unsigned int xl:12; /* X coordinate of upper left */
- unsigned int yl:12; /* Y coordinate of upper left */
- unsigned int pad1:5; /* Padding */
- unsigned int tile:3; /* Tile descriptor index */
- unsigned int xh:12; /* X coordinate of lower right */
- unsigned int yh:12; /* Y coordinate of lower right */
- unsigned int s:16; /* S texture coord at top left */
- unsigned int t:16; /* T texture coord at top left */
- unsigned int dsdx:16;/* Change in S per change in X */
- unsigned int dtdy:16;/* Change in T per change in Y */
+typedef struct
+{
+ unsigned int cmd: 8; /* command */
+ unsigned int xl: 12; /* X coordinate of upper left */
+ unsigned int yl: 12; /* Y coordinate of upper left */
+ unsigned int pad1: 5; /* Padding */
+ unsigned int tile: 3; /* Tile descriptor index */
+ unsigned int xh: 12; /* X coordinate of lower right */
+ unsigned int yh: 12; /* Y coordinate of lower right */
+ unsigned int s: 16; /* S texture coord at top left */
+ unsigned int t: 16; /* T texture coord at top left */
+ unsigned int dsdx: 16; /* Change in S per change in X */
+ unsigned int dtdy: 16; /* Change in T per change in Y */
} Gtexrect;
/*
* Textured rectangles are 128 bits not 64 bits
- */
-typedef struct {
+ */
+typedef struct
+{
unsigned long w0;
unsigned long w1;
unsigned long w2;
@@ -1757,9 +1795,10 @@ typedef struct {
/*
* Generic Gfx Packet
*/
-typedef struct {
- uintptr_t w0;
- uintptr_t w1;
+typedef struct
+{
+ uintptr_t w0;
+ uintptr_t w1;
} Gwords;
/*
@@ -1770,28 +1809,29 @@ typedef struct {
* 64-bit systems, only the 'words' member may be accessed; the rest of the
* structs don't have matching layouts for now.)
*/
-typedef union {
- Gwords words;
-#if !defined(F3D_OLD) && IS_BIG_ENDIAN && !IS_64_BIT
- Gdma dma;
- Gtri tri;
- Gline3D line;
- Gpopmtx popmtx;
- Gsegment segment;
- GsetothermodeH setothermodeH;
- GsetothermodeL setothermodeL;
- Gtexture texture;
- Gperspnorm perspnorm;
- Gsetimg setimg;
- Gsetcombine setcombine;
- Gsetcolor setcolor;
- Gfillrect fillrect; /* use for setscissor also */
- Gsettile settile;
- Gloadtile loadtile; /* use for loadblock also, th is dxt */
- Gsettilesize settilesize;
- Gloadtlut loadtlut;
-#endif
- long long int force_structure_alignment;
+typedef union
+{
+ Gwords words;
+ #if !defined(F3D_OLD) && IS_BIG_ENDIAN && !IS_64_BIT
+ Gdma dma;
+ Gtri tri;
+ Gline3D line;
+ Gpopmtx popmtx;
+ Gsegment segment;
+ GsetothermodeH setothermodeH;
+ GsetothermodeL setothermodeL;
+ Gtexture texture;
+ Gperspnorm perspnorm;
+ Gsetimg setimg;
+ Gsetcombine setcombine;
+ Gsetcolor setcolor;
+ Gfillrect fillrect; /* use for setscissor also */
+ Gsettile settile;
+ Gloadtile loadtile; /* use for loadblock also, th is dxt */
+ Gsettilesize settilesize;
+ Gloadtlut loadtlut;
+ #endif
+ long long int force_structure_alignment;
} Gfx;
/*
@@ -1900,7 +1940,7 @@ typedef union {
gsDma1p(G_VTX, v, sizeof(Vtx)*(n), ((n)-1)<<4|(v0))
#endif
-
+
#ifdef F3DEX_GBI_2
# define gSPViewport(pkt, v) \
gDma2p((pkt), G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT, 0)
@@ -2163,7 +2203,7 @@ typedef union {
/***
*** 1 Triangle
- ***/
+ ***/
#define gSP1Triangle(pkt, v0, v1, v2, flag) \
{ \
Gfx *_g = (Gfx *)(pkt); \
@@ -2339,7 +2379,7 @@ typedef union {
* Insert values into Matrix
*
* where = element of matrix (byte offset)
- * num = new element (32 bit value replacing 2 int or 2 frac matrix
+ * num = new element (32 bit value replacing 2 int or 2 frac matrix
* componants
*/
#ifdef F3DEX_GBI_2
@@ -2367,7 +2407,7 @@ typedef union {
#define gsSPForceMatrix(mptr) \
gsDma2p(G_MOVEMEM,(mptr),sizeof(Mtx),G_MV_MATRIX,0), \
gsMoveWd(G_MW_FORCEMTX,0,0x00010000)
-
+
#else /* F3DEX_GBI_2 */
#define gSPForceMatrix(pkt, mptr) \
{ \
@@ -2415,7 +2455,7 @@ typedef union {
/*
* gSPBranchLessZ Branch DL if (vtx.z) less than or equal (zval).
*
- * dl = DL branch to
+ * dl = DL branch to
* vtx = Vertex
* zval = Screen depth
* near = Near plane
@@ -2462,7 +2502,7 @@ typedef union {
/*
* gSPBranchLessZraw Branch DL if (vtx.z) less than or equal (raw zval).
*
- * dl = DL branch to
+ * dl = DL branch to
* vtx = Vertex
* zval = Raw value of screen depth
*/
@@ -2563,7 +2603,7 @@ typedef union {
#define NUMLIGHTS_7 7
/*
* n should be one of: NUMLIGHTS_0, NUMLIGHTS_1, ..., NUMLIGHTS_7
- * NOTE: in addition to the number of directional lights specified,
+ * NOTE: in addition to the number of directional lights specified,
* there is always 1 ambient light
*/
#define gSPNumLights(pkt, n) \
@@ -2575,7 +2615,7 @@ typedef union {
#define LIGHT_2 2
#define LIGHT_3 3
#define LIGHT_4 4
-#define LIGHT_5 5
+#define LIGHT_5 5
#define LIGHT_6 6
#define LIGHT_7 7
#define LIGHT_8 8
@@ -2800,7 +2840,7 @@ typedef union {
* min, max: range 0 to 1000: 0=nearplane, 1000=farplane
* min is where fog begins (usually less than max and often 0)
* max is where fog is thickest (usually 1000)
- *
+ *
*/
#define gSPFogFactor(pkt, fm, fo) \
gMoveWd(pkt, G_MW_FOG, G_MWO_FOG, \
@@ -2840,7 +2880,7 @@ typedef union {
_SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | _SHIFTL((on),1,7)),\
(_SHIFTL((s),16,16) | _SHIFTL((t),0,16)) \
}}
-/*
+/*
* Different version of SPTexture macro, has an additional parameter
* which is currently reserved in the microcode.
*/
@@ -2879,7 +2919,7 @@ typedef union {
_SHIFTL((level),11,3)|_SHIFTL((tile),8,3)|_SHIFTL((on),0,8)), \
(_SHIFTL((s),16,16)|_SHIFTL((t),0,16)) \
}}
-/*
+/*
* Different version of SPTexture macro, has an additional parameter
* which is currently reserved in the microcode.
*/
@@ -3110,7 +3150,7 @@ typedef union {
gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 2, mode)
#endif
-/* 'blendmask' is not supported anymore.
+/* 'blendmask' is not supported anymore.
* The bits are reserved for future use.
* Fri May 26 13:45:55 PDT 1995
*/
@@ -3199,7 +3239,7 @@ typedef union {
_SHIFTL((sbA1), 3, 3) | _SHIFTL((aA1), 0, 3))
#define gDPSetCombineLERP(pkt, a0, b0, c0, d0, Aa0, Ab0, Ac0, Ad0, \
- a1, b1, c1, d1, Aa1, Ab1, Ac1, Ad1) \
+ a1, b1, c1, d1, Aa1, Ab1, Ac1, Ad1) \
{ \
Gfx *_g = (Gfx *)(pkt); \
\
@@ -3221,7 +3261,7 @@ typedef union {
}
#define gsDPSetCombineLERP(a0, b0, c0, d0, Aa0, Ab0, Ac0, Ad0, \
- a1, b1, c1, d1, Aa1, Ab1, Ac1, Ad1) \
+ a1, b1, c1, d1, Aa1, Ab1, Ac1, Ad1) \
{{ \
_SHIFTL(G_SETCOMBINE, 24, 8) | \
_SHIFTL(GCCc0w0(G_CCMUX_##a0, G_CCMUX_##c0, \
@@ -3316,7 +3356,7 @@ typedef union {
*
* This command makes all othermode parameters set.
* Do not use this command in the same DL with another g*SPSetOtherMode DLs.
- *
+ *
* [Usage]
* gDPSetOtherMode(pkt, modeA, modeB)
*
@@ -3439,7 +3479,7 @@ typedef union {
gsDPLoadTileGeneric(G_LOADTILE, t, uls, ult, lrs, lrt)
#define gDPSetTile(pkt, fmt, siz, line, tmem, tile, palette, cmt, \
- maskt, shiftt, cms, masks, shifts) \
+ maskt, shiftt, cms, masks, shifts) \
{ \
Gfx *_g = (Gfx *)(pkt); \
\
@@ -3453,7 +3493,7 @@ typedef union {
}
#define gsDPSetTile(fmt, siz, line, tmem, tile, palette, cmt, \
- maskt, shiftt, cms, masks, shifts) \
+ maskt, shiftt, cms, masks, shifts) \
{{ \
(_SHIFTL(G_SETTILE, 24, 8) | _SHIFTL(fmt, 21, 3) | \
_SHIFTL(siz, 19, 2) | _SHIFTL(line, 9, 9) | _SHIFTL(tmem, 0, 9)),\
@@ -3508,7 +3548,7 @@ typedef union {
}}
#define gDPLoadTextureBlock(pkt, timg, fmt, siz, width, height, \
- pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ pal, cms, cmt, masks, maskt, shifts, shiftt) \
{ \
gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \
gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \
@@ -3528,7 +3568,7 @@ typedef union {
}
#define gDPLoadTextureBlockYuv(pkt, timg, fmt, siz, width, height, \
- pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ pal, cms, cmt, masks, maskt, shifts, shiftt) \
{ \
gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \
gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \
@@ -3551,7 +3591,7 @@ typedef union {
/* The S at the end means odd lines are already word Swapped */
#define gDPLoadTextureBlockS(pkt, timg, fmt, siz, width, height, \
- pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ pal, cms, cmt, masks, maskt, shifts, shiftt) \
{ \
gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \
gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \
@@ -3569,12 +3609,12 @@ typedef union {
((height)-1) << G_TEXTURE_IMAGE_FRAC) \
}
-/*
+/*
* Allow tmem address and render tile to be specified.
- * The S at the end means odd lines are already word Swapped
+ * The S at the end means odd lines are already word Swapped
*/
#define gDPLoadMultiBlockS(pkt, timg, tmem, rtile, fmt, siz, width, \
- height, pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ height, pal, cms, cmt, masks, maskt, shifts, shiftt) \
{ \
gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \
gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \
@@ -3594,7 +3634,7 @@ typedef union {
#define gDPLoadTextureBlockYuvS(pkt, timg, fmt, siz, width, height, \
- pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ pal, cms, cmt, masks, maskt, shifts, shiftt) \
{ \
gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \
gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \
@@ -3616,7 +3656,7 @@ typedef union {
* allows tmem address to be specified
*/
#define _gDPLoadTextureBlock(pkt, timg, tmem, fmt, siz, width, height, \
- pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ pal, cms, cmt, masks, maskt, shifts, shiftt) \
{ \
gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \
gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \
@@ -3638,7 +3678,7 @@ typedef union {
* allows tmem address and render tile to be specified
*/
#define _gDPLoadTextureBlockTile(pkt, timg, tmem, rtile, fmt, siz, width, \
- height, pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ height, pal, cms, cmt, masks, maskt, shifts, shiftt) \
{ \
gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \
gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0,\
@@ -3660,7 +3700,7 @@ typedef union {
* allows tmem address and render tile to be specified
*/
#define gDPLoadMultiBlock(pkt, timg, tmem, rtile, fmt, siz, width, \
- height, pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ height, pal, cms, cmt, masks, maskt, shifts, shiftt) \
{ \
gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \
gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0,\
@@ -3679,7 +3719,7 @@ typedef union {
}
#define gsDPLoadTextureBlock(timg, fmt, siz, width, height, \
- pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ pal, cms, cmt, masks, maskt, shifts, shiftt) \
\
gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \
gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, 0, \
@@ -3702,7 +3742,7 @@ typedef union {
calculate DxT, use 0 */
#define gsDPLoadTextureBlockS(timg, fmt, siz, width, height, \
- pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ pal, cms, cmt, masks, maskt, shifts, shiftt) \
\
gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \
gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, 0 , \
@@ -3722,7 +3762,7 @@ typedef union {
* Allow tmem address to be specified
*/
#define _gsDPLoadTextureBlock(timg, tmem, fmt, siz, width, height, \
- pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ pal, cms, cmt, masks, maskt, shifts, shiftt) \
\
gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \
gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \
@@ -3745,7 +3785,7 @@ typedef union {
* Allow tmem address and render_tile to be specified
*/
#define _gsDPLoadTextureBlockTile(timg, tmem, rtile, fmt, siz, width, \
- height, pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ height, pal, cms, cmt, masks, maskt, shifts, shiftt) \
\
gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \
gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \
@@ -3769,7 +3809,7 @@ typedef union {
* mutilple tiles at a time.
*/
#define gsDPLoadMultiBlock(timg, tmem, rtile, fmt, siz, width, \
- height, pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ height, pal, cms, cmt, masks, maskt, shifts, shiftt) \
\
gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \
gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \
@@ -3787,17 +3827,17 @@ typedef union {
((width)-1) << G_TEXTURE_IMAGE_FRAC, \
((height)-1) << G_TEXTURE_IMAGE_FRAC)
-/*
+/*
* Allows tmem and render tile to be specified. Useful when loading
* several tiles at a time.
*
* Here is the static form of the pre-swapped texture block loading
* See gDPLoadTextureBlockS() for reference. Basically, just don't
- * calculate DxT, use 0
+ * calculate DxT, use 0
*/
#define gsDPLoadMultiBlockS(timg, tmem, rtile, fmt, siz, width, height, \
- pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ pal, cms, cmt, masks, maskt, shifts, shiftt) \
\
gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \
gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0 , \
@@ -3815,7 +3855,7 @@ typedef union {
#define gDPLoadTextureBlock_4b(pkt, timg, fmt, width, height, \
- pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ pal, cms, cmt, masks, maskt, shifts, shiftt) \
{ \
gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \
gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, \
@@ -3837,7 +3877,7 @@ typedef union {
/* The S at the end means odd lines are already word Swapped */
#define gDPLoadTextureBlock_4bS(pkt, timg, fmt, width, height, \
- pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ pal, cms, cmt, masks, maskt, shifts, shiftt) \
{ \
gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \
gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, \
@@ -3858,7 +3898,7 @@ typedef union {
* 4-bit load block. Useful when loading multiple tiles
*/
#define gDPLoadMultiBlock_4b(pkt, timg, tmem, rtile, fmt, width, height,\
- pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ pal, cms, cmt, masks, maskt, shifts, shiftt) \
{ \
gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \
gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, \
@@ -3877,11 +3917,11 @@ typedef union {
}
/*
- * 4-bit load block. Allows tmem and render tile to be specified. Useful when
+ * 4-bit load block. Allows tmem and render tile to be specified. Useful when
* loading multiple tiles. The S means odd lines are already word swapped.
*/
#define gDPLoadMultiBlock_4bS(pkt, timg, tmem, rtile, fmt, width, height,\
- pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ pal, cms, cmt, masks, maskt, shifts, shiftt) \
{ \
gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \
gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, \
@@ -3900,7 +3940,7 @@ typedef union {
#define _gDPLoadTextureBlock_4b(pkt, timg, tmem, fmt, width, height, \
- pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ pal, cms, cmt, masks, maskt, shifts, shiftt) \
{ \
gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \
gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, \
@@ -3919,7 +3959,7 @@ typedef union {
}
#define gsDPLoadTextureBlock_4b(timg, fmt, width, height, \
- pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ pal, cms, cmt, masks, maskt, shifts, shiftt) \
\
gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \
gsDPSetTile(fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0 , cmt, \
@@ -3936,7 +3976,7 @@ typedef union {
((height)-1) << G_TEXTURE_IMAGE_FRAC)
#define gsDPLoadTextureBlock_4bS(timg, fmt, width, height, \
- pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ pal, cms, cmt, masks, maskt, shifts, shiftt) \
\
gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \
gsDPSetTile(fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0 , cmt, \
@@ -3956,7 +3996,7 @@ typedef union {
* Useful when loading multiple tiles.
*/
#define gsDPLoadMultiBlock_4b(timg, tmem, rtile, fmt, width, height, \
- pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ pal, cms, cmt, masks, maskt, shifts, shiftt) \
\
gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \
gsDPSetTile(fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0 , cmt, \
@@ -3978,7 +4018,7 @@ typedef union {
* Useful when loading multiple tiles. S means odd lines are already swapped.
*/
#define gsDPLoadMultiBlock_4bS(timg, tmem, rtile, fmt, width, height, \
- pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ pal, cms, cmt, masks, maskt, shifts, shiftt) \
\
gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \
gsDPSetTile(fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0 , cmt, \
@@ -3998,7 +4038,7 @@ typedef union {
* Allows tmem address to be specified
*/
#define _gsDPLoadTextureBlock_4b(timg, tmem, fmt, width, height, \
- pal, cms, cmt, masks, maskt, shifts, shiftt) \
+ pal, cms, cmt, masks, maskt, shifts, shiftt) \
\
gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \
gsDPSetTile(fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0 , cmt, \
@@ -4017,8 +4057,8 @@ typedef union {
#ifndef _HW_VERSION_1
#define gDPLoadTextureTile(pkt, timg, fmt, siz, width, height, \
- uls, ult, lrs, lrt, pal, \
- cms, cmt, masks, maskt, shifts, shiftt) \
+ uls, ult, lrs, lrt, pal, \
+ cms, cmt, masks, maskt, shifts, shiftt) \
{ \
gDPSetTextureImage(pkt, fmt, siz, width, timg); \
gDPSetTile(pkt, fmt, siz, \
@@ -4067,8 +4107,8 @@ typedef union {
* Useful for loading multiple tiles.
*/
#define gDPLoadMultiTile(pkt, timg, tmem, rtile, fmt, siz, width, height,\
- uls, ult, lrs, lrt, pal, \
- cms, cmt, masks, maskt, shifts, shiftt) \
+ uls, ult, lrs, lrt, pal, \
+ cms, cmt, masks, maskt, shifts, shiftt) \
{ \
gDPSetTextureImage(pkt, fmt, siz, width, timg); \
gDPSetTile(pkt, fmt, siz, \
@@ -4095,8 +4135,8 @@ typedef union {
#define gsDPLoadTextureTile(timg, fmt, siz, width, height, \
- uls, ult, lrs, lrt, pal, \
- cms, cmt, masks, maskt, shifts, shiftt) \
+ uls, ult, lrs, lrt, pal, \
+ cms, cmt, masks, maskt, shifts, shiftt) \
\
gsDPSetTextureImage(fmt, siz, width, timg), \
gsDPSetTile(fmt, siz, \
@@ -4125,8 +4165,8 @@ typedef union {
* Useful for loading multiple tiles.
*/
#define gsDPLoadMultiTile(timg, tmem, rtile, fmt, siz, width, height, \
- uls, ult, lrs, lrt, pal, \
- cms, cmt, masks, maskt, shifts, shiftt) \
+ uls, ult, lrs, lrt, pal, \
+ cms, cmt, masks, maskt, shifts, shiftt) \
\
gsDPSetTextureImage(fmt, siz, width, timg), \
gsDPSetTile(fmt, siz, \
@@ -4151,8 +4191,8 @@ typedef union {
(lrt)<>1), timg); \
gDPSetTile(pkt, fmt, G_IM_SIZ_8b, \
@@ -4182,8 +4222,8 @@ typedef union {
* Useful for loading multiple tiles.
*/
#define gDPLoadMultiTile_4b(pkt, timg, tmem, rtile, fmt, width, height, \
- uls, ult, lrs, lrt, pal, \
- cms, cmt, masks, maskt, shifts, shiftt) \
+ uls, ult, lrs, lrt, pal, \
+ cms, cmt, masks, maskt, shifts, shiftt) \
{ \
gDPSetTextureImage(pkt, fmt, G_IM_SIZ_8b, ((width)>>1), timg); \
gDPSetTile(pkt, fmt, G_IM_SIZ_8b, \
@@ -4209,8 +4249,8 @@ typedef union {
}
#define gsDPLoadTextureTile_4b(timg, fmt, width, height, \
- uls, ult, lrs, lrt, pal, \
- cms, cmt, masks, maskt, shifts, shiftt) \
+ uls, ult, lrs, lrt, pal, \
+ cms, cmt, masks, maskt, shifts, shiftt) \
\
gsDPSetTextureImage(fmt, G_IM_SIZ_8b, ((width)>>1), timg), \
gsDPSetTile(fmt, G_IM_SIZ_8b, (((((lrs)-(uls)+1)>>1)+7)>>3), 0, \
@@ -4237,8 +4277,8 @@ typedef union {
* Useful for loading multiple tiles.
*/
#define gsDPLoadMultiTile_4b(timg, tmem, rtile, fmt, width, height, \
- uls, ult, lrs, lrt, pal, \
- cms, cmt, masks, maskt, shifts, shiftt) \
+ uls, ult, lrs, lrt, pal, \
+ cms, cmt, masks, maskt, shifts, shiftt) \
\
gsDPSetTextureImage(fmt, G_IM_SIZ_8b, ((width)>>1), timg), \
gsDPSetTile(fmt, G_IM_SIZ_8b, (((((lrs)-(uls)+1)>>1)+7)>>3), \
@@ -4312,7 +4352,7 @@ typedef union {
G_IM_FMT_RGBA, G_IM_SIZ_16b, 4*16, 1, \
pal, 0, 0, 0, 0, 0, 0)
-#endif /* _HW_VERSION_1 */
+#endif /* _HW_VERSION_1 */
/*
* Load a 256-entry palette (for 8-bit CI textures)
@@ -4354,7 +4394,7 @@ typedef union {
gsDPLoadSync(), \
gsDPLoadTLUTCmd(G_TX_LOADTILE, 255), \
gsDPPipeSync()
-
+
#else /* **** WORKAROUND hardware 1 load_tlut bug ****** */
#define gsDPLoadTLUT_pal256(dram) \
diff --git a/src/decomp/include/PR/libaudio.h b/src/decomp/include/PR/libaudio.h
index 81d1c18..dfd1c13 100644
--- a/src/decomp/include/PR/libaudio.h
+++ b/src/decomp/include/PR/libaudio.h
@@ -6,18 +6,29 @@
typedef struct
{
- u8 *offset __attribute__((aligned (8)));
- s32 len __attribute__((aligned (8)));
+ u8 *offset __attribute__((aligned (8)
+
+ )
+ );
+
+ s32 len __attribute__((aligned (8)
+
+ )
+ );
} ALSeqData;
typedef struct
{
- unsigned short revision;
- unsigned short seqCount;
- unsigned int pad;
+ unsigned short revision;
+ unsigned short seqCount;
+ unsigned int pad;
ALSeqData seqArray[1];
-} __attribute__((aligned (16))) ALSeqFile;
+} __attribute__((aligned (16)
-void alSeqFileNew(ALSeqFile *f, u8 *base);
+)
+)
+ALSeqFile;
+
+void alSeqFileNew(ALSeqFile * f, u8 * base);
#endif
diff --git a/src/decomp/include/PR/os.h b/src/decomp/include/PR/os.h
index c8de719..d356db9 100644
--- a/src/decomp/include/PR/os.h
+++ b/src/decomp/include/PR/os.h
@@ -32,7 +32,10 @@
#define _OS_H_
#ifdef _LANGUAGE_C_PLUS_PLUS
-extern "C" {
+extern "C"
+{
+
+
#endif
#include "ultratypes.h"
@@ -49,15 +52,17 @@ extern "C" {
/*
* Structure for device manager block
*/
-typedef struct {
- s32 active; /* Status flag */
- OSThread *thread; /* Calling thread */
- OSMesgQueue *cmdQueue; /* Command queue */
- OSMesgQueue *evtQueue; /* Event queue */
- OSMesgQueue *acsQueue; /* Access queue */
- /* Raw DMA routine */
- s32 (*dma)(s32, u32, void *, u32);
- s32 (*edma)(OSPiHandle *, s32, u32, void *, u32);
+typedef struct
+{
+ s32 active; /* Status flag */
+ OSThread *thread; /* Calling thread */
+ OSMesgQueue *cmdQueue; /* Command queue */
+ OSMesgQueue *evtQueue; /* Event queue */
+ OSMesgQueue *acsQueue; /* Access queue */
+ /* Raw DMA routine */
+ s32 (*dma)(s32, u32, void *, u32);
+
+ s32 (*edma)(OSPiHandle *, s32, u32, void *, u32);
} OSDevMgr;
/*
@@ -65,40 +70,42 @@ typedef struct {
*/
-
-typedef struct {
- int status;
- OSMesgQueue *queue;
- int channel;
- u8 id[32];
- u8 label[32];
- int version;
- int dir_size;
- int inode_table; /* block location */
- int minode_table; /* mirrioring inode_table */
- int dir_table; /* block location */
- int inode_start_page; /* page # */
- u8 banks;
- u8 activebank;
+typedef struct
+{
+ int status;
+ OSMesgQueue *queue;
+ int channel;
+ u8 id[32];
+ u8 label[32];
+ int version;
+ int dir_size;
+ int inode_table; /* block location */
+ int minode_table; /* mirrioring inode_table */
+ int dir_table; /* block location */
+ int inode_start_page; /* page # */
+ u8 banks;
+ u8 activebank;
} OSPfs;
-typedef struct {
- u32 file_size; /* bytes */
- u32 game_code;
- u16 company_code;
- char ext_name[4];
- char game_name[16];
+typedef struct
+{
+ u32 file_size; /* bytes */
+ u32 game_code;
+ u16 company_code;
+ char ext_name[4];
+ char game_name[16];
} OSPfsState;
-
+
/*
- * Structure for Profiler
+ * Structure for Profiler
*/
-typedef struct {
- u16 *histo_base; /* histogram base */
- u32 histo_size; /* histogram size */
- u32 *text_start; /* start of text segment */
- u32 *text_end; /* end of text segment */
+typedef struct
+{
+ u16 *histo_base; /* histogram base */
+ u32 histo_size; /* histogram size */
+ u32 *text_start; /* start of text segment */
+ u32 *text_end; /* end of text segment */
} OSProf;
#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */
@@ -239,7 +246,7 @@ typedef struct {
#define OS_MIN_STACKSIZE 72
/*
- * Values for osTvType
+ * Values for osTvType
*/
#define OS_TV_PAL 0
#define OS_TV_NTSC 1
@@ -321,8 +328,8 @@ typedef struct {
#define OS_VI_BIT_NTSC 0x0400
#define OS_VI_BIT_PAL 0x0800
-/*
- * Leo Disk
+/*
+ * Leo Disk
*/
/* transfer mode */
@@ -347,7 +354,7 @@ typedef struct {
#ifdef _HW_VERSION_1
#define CONT_FRAME_ERROR 0x2
#define CONT_COLLISION_ERROR 0x1
-#endif
+#endif
/* Controller type */
@@ -431,9 +438,9 @@ typedef struct {
#define PFS_ERR_NOPACK 1 /* no memory card is plugged or */
#define PFS_ERR_NEW_PACK 2 /* ram pack has been changed to a */
- /* different one */
+/* different one */
#define PFS_ERR_INCONSISTENT 3 /* need to run Pfschecker */
-#define PFS_ERR_CONTRFAIL CONT_OVERRUN_ERROR
+#define PFS_ERR_CONTRFAIL CONT_OVERRUN_ERROR
#define PFS_ERR_INVALID 5 /* invalid parameter or file not exist*/
#define PFS_ERR_BAD_DATA 6 /* the data read from pack are bad*/
#define PFS_DATA_FULL 7 /* no free pages on ram pack */
@@ -514,66 +521,65 @@ extern u64 osClockRate;
* Extern variables
*
*/
-extern OSViMode osViModeTable[]; /* Global VI mode table */
+extern OSViMode osViModeTable[]; /* Global VI mode table */
-extern OSViMode osViModeNtscLpn1; /* Individual VI NTSC modes */
-extern OSViMode osViModeNtscLpf1;
-extern OSViMode osViModeNtscLan1;
-extern OSViMode osViModeNtscLaf1;
-extern OSViMode osViModeNtscLpn2;
-extern OSViMode osViModeNtscLpf2;
-extern OSViMode osViModeNtscLan2;
-extern OSViMode osViModeNtscLaf2;
-extern OSViMode osViModeNtscHpn1;
-extern OSViMode osViModeNtscHpf1;
-extern OSViMode osViModeNtscHan1;
-extern OSViMode osViModeNtscHaf1;
-extern OSViMode osViModeNtscHpn2;
-extern OSViMode osViModeNtscHpf2;
+extern OSViMode osViModeNtscLpn1; /* Individual VI NTSC modes */
+extern OSViMode osViModeNtscLpf1;
+extern OSViMode osViModeNtscLan1;
+extern OSViMode osViModeNtscLaf1;
+extern OSViMode osViModeNtscLpn2;
+extern OSViMode osViModeNtscLpf2;
+extern OSViMode osViModeNtscLan2;
+extern OSViMode osViModeNtscLaf2;
+extern OSViMode osViModeNtscHpn1;
+extern OSViMode osViModeNtscHpf1;
+extern OSViMode osViModeNtscHan1;
+extern OSViMode osViModeNtscHaf1;
+extern OSViMode osViModeNtscHpn2;
+extern OSViMode osViModeNtscHpf2;
-extern OSViMode osViModePalLpn1; /* Individual VI PAL modes */
-extern OSViMode osViModePalLpf1;
-extern OSViMode osViModePalLan1;
-extern OSViMode osViModePalLaf1;
-extern OSViMode osViModePalLpn2;
-extern OSViMode osViModePalLpf2;
-extern OSViMode osViModePalLan2;
-extern OSViMode osViModePalLaf2;
-extern OSViMode osViModePalHpn1;
-extern OSViMode osViModePalHpf1;
-extern OSViMode osViModePalHan1;
-extern OSViMode osViModePalHaf1;
-extern OSViMode osViModePalHpn2;
-extern OSViMode osViModePalHpf2;
+extern OSViMode osViModePalLpn1; /* Individual VI PAL modes */
+extern OSViMode osViModePalLpf1;
+extern OSViMode osViModePalLan1;
+extern OSViMode osViModePalLaf1;
+extern OSViMode osViModePalLpn2;
+extern OSViMode osViModePalLpf2;
+extern OSViMode osViModePalLan2;
+extern OSViMode osViModePalLaf2;
+extern OSViMode osViModePalHpn1;
+extern OSViMode osViModePalHpf1;
+extern OSViMode osViModePalHan1;
+extern OSViMode osViModePalHaf1;
+extern OSViMode osViModePalHpn2;
+extern OSViMode osViModePalHpf2;
-extern OSViMode osViModeMpalLpn1; /* Individual VI MPAL modes */
-extern OSViMode osViModeMpalLpf1;
-extern OSViMode osViModeMpalLan1;
-extern OSViMode osViModeMpalLaf1;
-extern OSViMode osViModeMpalLpn2;
-extern OSViMode osViModeMpalLpf2;
-extern OSViMode osViModeMpalLan2;
-extern OSViMode osViModeMpalLaf2;
-extern OSViMode osViModeMpalHpn1;
-extern OSViMode osViModeMpalHpf1;
-extern OSViMode osViModeMpalHan1;
-extern OSViMode osViModeMpalHaf1;
-extern OSViMode osViModeMpalHpn2;
-extern OSViMode osViModeMpalHpf2;
+extern OSViMode osViModeMpalLpn1; /* Individual VI MPAL modes */
+extern OSViMode osViModeMpalLpf1;
+extern OSViMode osViModeMpalLan1;
+extern OSViMode osViModeMpalLaf1;
+extern OSViMode osViModeMpalLpn2;
+extern OSViMode osViModeMpalLpf2;
+extern OSViMode osViModeMpalLan2;
+extern OSViMode osViModeMpalLaf2;
+extern OSViMode osViModeMpalHpn1;
+extern OSViMode osViModeMpalHpf1;
+extern OSViMode osViModeMpalHan1;
+extern OSViMode osViModeMpalHaf1;
+extern OSViMode osViModeMpalHpn2;
+extern OSViMode osViModeMpalHpf2;
-extern s32 osRomType; /* Bulk or cartridge ROM. 0=cartridge 1=bulk */
-extern u32 osRomBase; /* Rom base address of the game image */
-extern u32 osTvType; /* 0 = PAL, 1 = NTSC, 2 = MPAL */
-extern u32 osResetType; /* 0 = cold reset, 1 = NMI */
-extern s32 osCicId;
-extern s32 osVersion;
-extern u32 osMemSize; /* Memory Size */
-extern s32 osAppNMIBuffer[];
-
-extern OSIntMask __OSGlobalIntMask; /* global interrupt mask */
-extern OSPiHandle *__osPiTable; /* The head of OSPiHandle link list */
-extern OSPiHandle *__osDiskHandle; /* For exceptasm to get disk info*/
+extern s32 osRomType; /* Bulk or cartridge ROM. 0=cartridge 1=bulk */
+extern u32 osRomBase; /* Rom base address of the game image */
+extern u32 osTvType; /* 0 = PAL, 1 = NTSC, 2 = MPAL */
+extern u32 osResetType; /* 0 = cold reset, 1 = NMI */
+extern s32 osCicId;
+extern s32 osVersion;
+extern u32 osMemSize; /* Memory Size */
+extern s32 osAppNMIBuffer[];
+extern OSIntMask __OSGlobalIntMask; /* global interrupt mask */
+extern OSPiHandle *__osPiTable; /* The head of OSPiHandle link list */
+extern OSPiHandle *__osDiskHandle; /* For exceptasm to get disk info*/
/**************************************************************************
@@ -584,58 +590,59 @@ extern OSPiHandle *__osDiskHandle; /* For exceptasm to get disk info*/
/* Thread operations */
-extern void osCreateThread(OSThread *, OSId, void (*)(void *),
- void *, void *, OSPri);
-extern void osDestroyThread(OSThread *);
-extern void osYieldThread(void);
-extern void osStartThread(OSThread *);
-extern void osStopThread(OSThread *);
-extern OSId osGetThreadId(OSThread *);
-extern void osSetThreadPri(OSThread *, OSPri);
-extern OSPri osGetThreadPri(OSThread *);
+extern void osCreateThread(
+ OSThread *, OSId, void (*)(void *),
+ void *, void *, OSPri);
+extern void osDestroyThread(OSThread *);
+extern void osYieldThread(void);
+extern void osStartThread(OSThread *);
+extern void osStopThread(OSThread *);
+extern OSId osGetThreadId(OSThread *);
+extern void osSetThreadPri(OSThread *, OSPri);
+extern OSPri osGetThreadPri(OSThread *);
/* Message operations */
-extern void osCreateMesgQueue(OSMesgQueue *, OSMesg *, s32);
-extern s32 osSendMesg(OSMesgQueue *, OSMesg, s32);
-extern s32 osJamMesg(OSMesgQueue *, OSMesg, s32);
-extern s32 osRecvMesg(OSMesgQueue *, OSMesg *, s32);
+extern void osCreateMesgQueue(OSMesgQueue *, OSMesg *, s32);
+extern s32 osSendMesg(OSMesgQueue *, OSMesg, s32);
+extern s32 osJamMesg(OSMesgQueue *, OSMesg, s32);
+extern s32 osRecvMesg(OSMesgQueue *, OSMesg *, s32);
/* Event operations */
-extern void osSetEventMesg(OSEvent, OSMesgQueue *, OSMesg);
+extern void osSetEventMesg(OSEvent, OSMesgQueue *, OSMesg);
/* Interrupt operations */
-extern OSIntMask osGetIntMask(void);
-extern OSIntMask osSetIntMask(OSIntMask);
+extern OSIntMask osGetIntMask(void);
+extern OSIntMask osSetIntMask(OSIntMask);
/* RDB port operations */
-extern void osInitRdb(u8 *sendBuf, u32 sendSize);
+extern void osInitRdb(u8 *sendBuf, u32 sendSize);
/* Cache operations and macros */
-extern void osInvalDCache(void *, size_t);
-extern void osInvalICache(void *, size_t);
-extern void osWritebackDCache(void *, size_t);
-extern void osWritebackDCacheAll(void);
+extern void osInvalDCache(void *, size_t);
+extern void osInvalICache(void *, size_t);
+extern void osWritebackDCache(void *, size_t);
+extern void osWritebackDCacheAll(void);
#define OS_DCACHE_ROUNDUP_ADDR(x) (void *)(((((u32)(x)+0xf)/0x10)*0x10))
#define OS_DCACHE_ROUNDUP_SIZE(x) (u32)(((((u32)(x)+0xf)/0x10)*0x10))
/* TLB management routines */
-extern void osMapTLB(s32, OSPageMask, void *, u32, u32, s32);
-extern void osMapTLBRdb(void);
-extern void osUnmapTLB(s32);
-extern void osUnmapTLBAll(void);
-extern void osSetTLBASID(s32);
+extern void osMapTLB(s32, OSPageMask, void *, u32, u32, s32);
+extern void osMapTLBRdb(void);
+extern void osUnmapTLB(s32);
+extern void osUnmapTLBAll(void);
+extern void osSetTLBASID(s32);
/* Address translation routines and macros */
-extern u32 osVirtualToPhysical(void *);
-extern void * osPhysicalToVirtual(u32);
+extern u32 osVirtualToPhysical(void *);
+extern void *osPhysicalToVirtual(u32);
#define OS_K0_TO_PHYSICAL(x) (u32)(((char *)(x)-0x80000000))
#define OS_K1_TO_PHYSICAL(x) (u32)(((char *)(x)-0xa0000000))
@@ -646,66 +653,68 @@ extern void * osPhysicalToVirtual(u32);
/* I/O operations */
/* Audio interface (Ai) */
-extern u32 osAiGetStatus(void);
-extern u32 osAiGetLength(void);
-extern s32 osAiSetFrequency(u32);
-extern s32 osAiSetNextBuffer(void *, u32);
+extern u32 osAiGetStatus(void);
+extern u32 osAiGetLength(void);
+extern s32 osAiSetFrequency(u32);
+extern s32 osAiSetNextBuffer(void *, u32);
/* Display processor interface (Dp) */
-extern u32 osDpGetStatus(void);
-extern void osDpSetStatus(u32);
-extern void osDpGetCounters(u32 *);
-extern s32 osDpSetNextBuffer(void *, u64);
+extern u32 osDpGetStatus(void);
+extern void osDpSetStatus(u32);
+extern void osDpGetCounters(u32 *);
+extern s32 osDpSetNextBuffer(void *, u64);
/* Peripheral interface (Pi) */
-extern u32 osPiGetStatus(void);
-extern s32 osPiGetDeviceType(void);
-extern s32 osPiRawWriteIo(u32, u32);
-extern s32 osPiRawReadIo(u32, u32 *);
-extern s32 osPiRawStartDma(s32, u32, void *, u32);
-extern s32 osPiWriteIo(u32, u32);
-extern s32 osPiReadIo(u32, u32 *);
-extern s32 osPiStartDma(OSIoMesg *, s32, s32, u32, void *, u32,
- OSMesgQueue *);
-extern void osCreatePiManager(OSPri, OSMesgQueue *, OSMesg *, s32);
+extern u32 osPiGetStatus(void);
+extern s32 osPiGetDeviceType(void);
+extern s32 osPiRawWriteIo(u32, u32);
+extern s32 osPiRawReadIo(u32, u32 *);
+extern s32 osPiRawStartDma(s32, u32, void *, u32);
+extern s32 osPiWriteIo(u32, u32);
+extern s32 osPiReadIo(u32, u32 *);
+extern s32 osPiStartDma(
+ OSIoMesg *, s32, s32, u32, void *, u32,
+ OSMesgQueue *);
+extern void osCreatePiManager(OSPri, OSMesgQueue *, OSMesg *, s32);
/* Video interface (Vi) */
-extern u32 osViGetStatus(void);
-extern u32 osViGetCurrentMode(void);
-extern u32 osViGetCurrentLine(void);
-extern u32 osViGetCurrentField(void);
-extern void *osViGetCurrentFramebuffer(void);
-extern void *osViGetNextFramebuffer(void);
-extern void osViSetXScale(f32);
-extern void osViSetYScale(f32);
-extern void osViSetSpecialFeatures(u32);
-extern void osViSetMode(OSViMode *);
-extern void osViSetEvent(OSMesgQueue *, OSMesg, u32);
-extern void osViSwapBuffer(void *);
-extern void osViBlack(u8);
-extern void osViFade(u8, u16);
-extern void osViRepeatLine(u8);
-extern void osCreateViManager(OSPri);
+extern u32 osViGetStatus(void);
+extern u32 osViGetCurrentMode(void);
+extern u32 osViGetCurrentLine(void);
+extern u32 osViGetCurrentField(void);
+extern void *osViGetCurrentFramebuffer(void);
+extern void *osViGetNextFramebuffer(void);
+extern void osViSetXScale(f32);
+extern void osViSetYScale(f32);
+extern void osViSetSpecialFeatures(u32);
+extern void osViSetMode(OSViMode *);
+extern void osViSetEvent(OSMesgQueue *, OSMesg, u32);
+extern void osViSwapBuffer(void *);
+extern void osViBlack(u8);
+extern void osViFade(u8, u16);
+extern void osViRepeatLine(u8);
+extern void osCreateViManager(OSPri);
/* Timer interface */
-extern OSTime osGetTime(void);
-extern void osSetTime(OSTime);
-extern u32 osSetTimer(OSTimer *, OSTime, OSTime,
- OSMesgQueue *, OSMesg);
-extern int osStopTimer(OSTimer *);
+extern OSTime osGetTime(void);
+extern void osSetTime(OSTime);
+extern u32 osSetTimer(
+ OSTimer *, OSTime, OSTime,
+ OSMesgQueue *, OSMesg);
+extern int osStopTimer(OSTimer *);
/* Controller interface */
-extern s32 osContInit(OSMesgQueue *, u8 *, OSContStatus *);
-extern s32 osContReset(OSMesgQueue *, OSContStatus *);
-extern s32 osContStartQuery(OSMesgQueue *);
-extern s32 osContStartReadData(OSMesgQueue *);
+extern s32 osContInit(OSMesgQueue *, u8 *, OSContStatus *);
+extern s32 osContReset(OSMesgQueue *, OSContStatus *);
+extern s32 osContStartQuery(OSMesgQueue *);
+extern s32 osContStartReadData(OSMesgQueue *);
#ifndef _HW_VERSION_1
-extern s32 osContSetCh(u8);
+extern s32 osContSetCh(u8);
#endif
-extern void osContGetQuery(OSContStatus *);
-extern void osContGetReadData(OSContPad *);
+extern void osContGetQuery(OSContStatus *);
+extern void osContGetReadData(OSContPad *);
/* file system interface */
@@ -746,50 +755,50 @@ extern OSPiHandle *osLeoDiskInit(void);
extern OSPiHandle *osDriveRomInit(void);
extern s32 osEPiDeviceType(OSPiHandle *, OSPiInfo *);
-extern s32 osEPiRawWriteIo(OSPiHandle *, u32 , u32);
-extern s32 osEPiRawReadIo(OSPiHandle *, u32 , u32 *);
-extern s32 osEPiRawStartDma(OSPiHandle *, s32 , u32 , void *, u32 );
-extern s32 osEPiWriteIo(OSPiHandle *, u32 , u32 );
-extern s32 osEPiReadIo(OSPiHandle *, u32 , u32 *);
+extern s32 osEPiRawWriteIo(OSPiHandle *, u32, u32);
+extern s32 osEPiRawReadIo(OSPiHandle *, u32, u32 *);
+extern s32 osEPiRawStartDma(OSPiHandle *, s32, u32, void *, u32);
+extern s32 osEPiWriteIo(OSPiHandle *, u32, u32);
+extern s32 osEPiReadIo(OSPiHandle *, u32, u32 *);
extern s32 osEPiStartDma(OSPiHandle *, OSIoMesg *, s32);
extern s32 osEPiLinkHandle(OSPiHandle *);
/* Profiler Interface */
-extern void osProfileInit(OSProf *, u32 profcnt);
-extern void osProfileStart(u32);
-extern void osProfileFlush(void);
-extern void osProfileStop(void);
+extern void osProfileInit(OSProf *, u32 profcnt);
+extern void osProfileStart(u32);
+extern void osProfileFlush(void);
+extern void osProfileStop(void);
/* Game <> Host data transfer functions */
-extern s32 osTestHost(void);
-extern void osReadHost(void *, u32);
-extern void osWriteHost(void *, u32);
-extern void osAckRamromRead(void);
-extern void osAckRamromWrite(void);
+extern s32 osTestHost(void);
+extern void osReadHost(void *, u32);
+extern void osWriteHost(void *, u32);
+extern void osAckRamromRead(void);
+extern void osAckRamromWrite(void);
/* byte string operations */
-extern void bcopy(const void *, void *, size_t);
-extern int bcmp(const void *, const void *, int);
-extern void bzero(void *, size_t);
+extern void bcopy(const void *, void *, size_t);
+extern int bcmp(const void *, const void *, int);
+extern void bzero(void *, size_t);
/* Miscellaneous operations */
-extern void osInitialize(void);
-extern u32 osGetCount(void);
-extern void osExit(void);
-extern u32 osGetMemSize(void);
+extern void osInitialize(void);
+extern u32 osGetCount(void);
+extern void osExit(void);
+extern u32 osGetMemSize(void);
/* Printf */
-extern int sprintf(char *s, const char *fmt, ...);
-extern void osSyncPrintf(const char *fmt, ...);
-extern void osAsyncPrintf(const char *fmt, ...);
-extern int osSyncGetChars(char *buf);
-extern int osAsyncGetChars(char *buf);
+extern int sprintf(char *s, const char *fmt, ...);
+extern void osSyncPrintf(const char *fmt, ...);
+extern void osAsyncPrintf(const char *fmt, ...);
+extern int osSyncGetChars(char *buf);
+extern int osAsyncGetChars(char *buf);
#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */
diff --git a/src/decomp/include/PR/os_ai.h b/src/decomp/include/PR/os_ai.h
index b9df406..a586634 100644
--- a/src/decomp/include/PR/os_ai.h
+++ b/src/decomp/include/PR/os_ai.h
@@ -31,7 +31,10 @@
#define _OS_AI_H_
#ifdef _LANGUAGE_C_PLUS_PLUS
-extern "C" {
+extern "C"
+{
+
+
#endif
#include "ultratypes.h"
@@ -77,10 +80,10 @@ extern "C" {
*/
/* Audio interface (Ai) */
-extern u32 osAiGetStatus(void);
-extern u32 osAiGetLength(void);
-extern s32 osAiSetFrequency(u32);
-extern s32 osAiSetNextBuffer(void *, u32);
+extern u32 osAiGetStatus(void);
+extern u32 osAiGetLength(void);
+extern s32 osAiSetFrequency(u32);
+extern s32 osAiSetNextBuffer(void *, u32);
#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */
diff --git a/src/decomp/include/PR/os_cache.h b/src/decomp/include/PR/os_cache.h
index e313840..ac98525 100644
--- a/src/decomp/include/PR/os_cache.h
+++ b/src/decomp/include/PR/os_cache.h
@@ -31,7 +31,10 @@
#define _OS_CACHE_H_
#ifdef _LANGUAGE_C_PLUS_PLUS
-extern "C" {
+extern "C"
+{
+
+
#endif
#include "ultratypes.h"
@@ -81,10 +84,10 @@ extern "C" {
/* Cache operations and macros */
-extern void osInvalDCache(void *, size_t);
-extern void osInvalICache(void *, size_t);
-extern void osWritebackDCache(void *, size_t);
-extern void osWritebackDCacheAll(void);
+extern void osInvalDCache(void *, size_t);
+extern void osInvalICache(void *, size_t);
+extern void osWritebackDCache(void *, size_t);
+extern void osWritebackDCacheAll(void);
#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */
diff --git a/src/decomp/include/PR/os_cont.h b/src/decomp/include/PR/os_cont.h
index bd6ff1f..95acc68 100644
--- a/src/decomp/include/PR/os_cont.h
+++ b/src/decomp/include/PR/os_cont.h
@@ -31,7 +31,10 @@
#define _OS_CONT_H_
#ifdef _LANGUAGE_C_PLUS_PLUS
-extern "C" {
+extern "C"
+{
+
+
#endif
#include "ultratypes.h"
@@ -47,28 +50,31 @@ extern "C" {
*/
/*
- * Structure for controllers
+ * Structure for controllers
*/
-typedef struct {
- u16 type; /* Controller Type */
- u8 status; /* Controller status */
- u8 errnum;
-}OSContStatus;
+typedef struct
+{
+ u16 type; /* Controller Type */
+ u8 status; /* Controller status */
+ u8 errnum;
+} OSContStatus;
-typedef struct {
- u16 button;
- s8 stick_x; /* -80 <= stick_x <= 80 */
- s8 stick_y; /* -80 <= stick_y <= 80 */
- u8 errnum;
+typedef struct
+{
+ u16 button;
+ s8 stick_x; /* -80 <= stick_x <= 80 */
+ s8 stick_y; /* -80 <= stick_y <= 80 */
+ u8 errnum;
} OSContPad;
-typedef struct {
- void *address; /* Ram pad Address: 11 bits */
- u8 databuffer[32]; /* address of the data buffer */
- u8 addressCrc; /* CRC code for address */
- u8 dataCrc; /* CRC code for data */
- u8 errnum;
+typedef struct
+{
+ void *address; /* Ram pad Address: 11 bits */
+ u8 databuffer[32]; /* address of the data buffer */
+ u8 addressCrc; /* CRC code for address */
+ u8 dataCrc; /* CRC code for data */
+ u8 errnum;
} OSContRamIo;
@@ -96,7 +102,7 @@ typedef struct {
#ifdef _HW_VERSION_1
#define CONT_FRAME_ERROR 0x2
#define CONT_COLLISION_ERROR 0x1
-#endif
+#endif
/* Controller type */
diff --git a/src/decomp/include/PR/os_eeprom.h b/src/decomp/include/PR/os_eeprom.h
index 2a03fb5..64681e0 100644
--- a/src/decomp/include/PR/os_eeprom.h
+++ b/src/decomp/include/PR/os_eeprom.h
@@ -31,7 +31,10 @@
#define _OS_EEPROM_H_
#ifdef _LANGUAGE_C_PLUS_PLUS
-extern "C" {
+extern "C"
+{
+
+
#endif
#include "ultratypes.h"
diff --git a/src/decomp/include/PR/os_exception.h b/src/decomp/include/PR/os_exception.h
index 2750769..fa855d1 100644
--- a/src/decomp/include/PR/os_exception.h
+++ b/src/decomp/include/PR/os_exception.h
@@ -31,7 +31,10 @@
#define _OS_EXCEPTION_H_
#ifdef _LANGUAGE_C_PLUS_PLUS
-extern "C" {
+extern "C"
+{
+
+
#endif
#include "ultratypes.h"
@@ -106,8 +109,8 @@ typedef u32 OSHWIntr;
/* Interrupt operations */
-extern OSIntMask osGetIntMask(void);
-extern OSIntMask osSetIntMask(OSIntMask);
+extern OSIntMask osGetIntMask(void);
+extern OSIntMask osSetIntMask(OSIntMask);
#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */
diff --git a/src/decomp/include/PR/os_libc.h b/src/decomp/include/PR/os_libc.h
index 444ec17..a8fda57 100644
--- a/src/decomp/include/PR/os_libc.h
+++ b/src/decomp/include/PR/os_libc.h
@@ -8,6 +8,7 @@
// Old deprecated functions from strings.h, replaced by memcpy/memset.
extern void bcopy(const void *, void *, size_t);
+
extern void bzero(void *, size_t);
#endif
diff --git a/src/decomp/include/PR/os_message.h b/src/decomp/include/PR/os_message.h
index 51396c0..e319d1c 100644
--- a/src/decomp/include/PR/os_message.h
+++ b/src/decomp/include/PR/os_message.h
@@ -31,7 +31,10 @@
#define _OS_MESSAGE_H_
#ifdef _LANGUAGE_C_PLUS_PLUS
-extern "C" {
+extern "C"
+{
+
+
#endif
#include "ultratypes.h"
@@ -50,20 +53,21 @@ typedef u32 OSEvent;
/*
* Structure for message
*/
-typedef void * OSMesg;
+typedef void *OSMesg;
/*
* Structure for message queue
*/
-typedef struct OSMesgQueue_s {
- OSThread *mtqueue; /* Queue to store threads blocked
+typedef struct OSMesgQueue_s
+{
+ OSThread *mtqueue; /* Queue to store threads blocked
on empty mailboxes (receive) */
- OSThread *fullqueue; /* Queue to store threads blocked
+ OSThread *fullqueue; /* Queue to store threads blocked
on full mailboxes (send) */
- s32 validCount; /* Contains number of valid message */
- s32 first; /* Points to first valid message */
- s32 msgCount; /* Contains total # of messages */
- OSMesg *msg; /* Points to message buffer array */
+ s32 validCount; /* Contains number of valid message */
+ s32 first; /* Points to first valid message */
+ s32 msgCount; /* Contains total # of messages */
+ OSMesg *msg; /* Points to message buffer array */
} OSMesgQueue;
@@ -145,14 +149,14 @@ typedef struct OSMesgQueue_s {
/* Message operations */
-extern void osCreateMesgQueue(OSMesgQueue *, OSMesg *, s32);
-extern s32 osSendMesg(OSMesgQueue *, OSMesg, s32);
-extern s32 osJamMesg(OSMesgQueue *, OSMesg, s32);
-extern s32 osRecvMesg(OSMesgQueue *, OSMesg *, s32);
+extern void osCreateMesgQueue(OSMesgQueue *, OSMesg *, s32);
+extern s32 osSendMesg(OSMesgQueue *, OSMesg, s32);
+extern s32 osJamMesg(OSMesgQueue *, OSMesg, s32);
+extern s32 osRecvMesg(OSMesgQueue *, OSMesg *, s32);
/* Event operations */
-extern void osSetEventMesg(OSEvent, OSMesgQueue *, OSMesg);
+extern void osSetEventMesg(OSEvent, OSMesgQueue *, OSMesg);
#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */
diff --git a/src/decomp/include/PR/os_misc.h b/src/decomp/include/PR/os_misc.h
index eb0c793..418f4b6 100644
--- a/src/decomp/include/PR/os_misc.h
+++ b/src/decomp/include/PR/os_misc.h
@@ -4,6 +4,7 @@
/* Miscellaneous OS functions */
void osInitialize(void);
+
u32 osGetCount(void);
uintptr_t osVirtualToPhysical(void *);
diff --git a/src/decomp/include/PR/os_pi.h b/src/decomp/include/PR/os_pi.h
index 8da37e2..34b1fb7 100644
--- a/src/decomp/include/PR/os_pi.h
+++ b/src/decomp/include/PR/os_pi.h
@@ -6,10 +6,11 @@
/* Types */
-typedef struct {
-#if !defined(VERSION_EU)
+typedef struct
+{
+ #if !defined(VERSION_EU)
u32 errStatus;
-#endif
+ #endif
void *dramAddr;
void *C2Addr;
u32 sectorSize;
@@ -17,21 +18,23 @@ typedef struct {
u32 C1ErrSector[4];
} __OSBlockInfo;
-typedef struct {
- u32 cmdType; // 0
- u16 transferMode; // 4
- u16 blockNum; // 6
- s32 sectorNum; // 8
+typedef struct
+{
+ u32 cmdType; // 0
+ u16 transferMode; // 4
+ u16 blockNum; // 6
+ s32 sectorNum; // 8
uintptr_t devAddr; // c
-#if defined(VERSION_EU)
+ #if defined(VERSION_EU)
u32 errStatus; //error status added moved to blockinfo
-#endif
- u32 bmCtlShadow; // 10
- u32 seqCtlShadow; // 14
+ #endif
+ u32 bmCtlShadow; // 10
+ u32 seqCtlShadow; // 14
__OSBlockInfo block[2]; // 18
} __OSTranxInfo;
-typedef struct OSPiHandle_s {
+typedef struct OSPiHandle_s
+{
struct OSPiHandle_s *next;
u8 type;
u8 latency;
@@ -44,26 +47,33 @@ typedef struct OSPiHandle_s {
__OSTranxInfo transferInfo;
} OSPiHandle;
-typedef struct {
+typedef struct
+{
u8 type;
uintptr_t address;
} OSPiInfo;
-typedef struct {
+typedef struct
+{
u16 type;
u8 pri;
u8 status;
OSMesgQueue *retQueue;
} OSIoMesgHdr;
-typedef struct {
- /*0x00*/ OSIoMesgHdr hdr;
- /*0x08*/ void *dramAddr;
- /*0x0C*/ uintptr_t devAddr;
- /*0x10*/ size_t size;
-#if defined(VERSION_EU) || defined(VERSION_SH)
+typedef struct
+{
+ /*0x00*/
+ OSIoMesgHdr hdr;
+ /*0x08*/
+ void *dramAddr;
+ /*0x0C*/
+ uintptr_t devAddr;
+ /*0x10*/
+ size_t size;
+ #if defined(VERSION_EU) || defined(VERSION_SH)
OSPiHandle *piHandle; // from the official definition
-#endif
+ #endif
} OSIoMesg;
/* Definitions */
@@ -76,13 +86,19 @@ typedef struct {
/* Functions */
-s32 osPiStartDma(OSIoMesg *mb, s32 priority, s32 direction, uintptr_t devAddr, void *vAddr,
- size_t nbytes, OSMesgQueue *mq);
+s32 osPiStartDma(
+ OSIoMesg *mb, s32 priority, s32 direction, uintptr_t devAddr, void *vAddr,
+ size_t nbytes, OSMesgQueue *mq);
+
void osCreatePiManager(OSPri pri, OSMesgQueue *cmdQ, OSMesg *cmdBuf, s32 cmdMsgCnt);
+
OSMesgQueue *osPiGetCmdQueue(void);
+
s32 osPiWriteIo(uintptr_t devAddr, u32 data);
+
s32 osPiReadIo(uintptr_t devAddr, u32 *data);
s32 osPiRawStartDma(s32 dir, u32 cart_addr, void *dram_addr, size_t size);
+
s32 osEPiRawStartDma(OSPiHandle *piHandle, s32 dir, u32 cart_addr, void *dram_addr, size_t size);
#endif
diff --git a/src/decomp/include/PR/os_rdp.h b/src/decomp/include/PR/os_rdp.h
index 76077ba..b24e992 100644
--- a/src/decomp/include/PR/os_rdp.h
+++ b/src/decomp/include/PR/os_rdp.h
@@ -31,7 +31,10 @@
#define _OS_RDP_H_
#ifdef _LANGUAGE_C_PLUS_PLUS
-extern "C" {
+extern "C"
+{
+
+
#endif
#include "ultratypes.h"
@@ -77,10 +80,10 @@ extern "C" {
*/
/* Display processor interface (Dp) */
-extern u32 osDpGetStatus(void);
-extern void osDpSetStatus(u32);
-extern void osDpGetCounters(u32 *);
-extern s32 osDpSetNextBuffer(void *, u64);
+extern u32 osDpGetStatus(void);
+extern void osDpSetStatus(u32);
+extern void osDpGetCounters(u32 *);
+extern s32 osDpSetNextBuffer(void *, u64);
#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */
diff --git a/src/decomp/include/PR/os_thread.h b/src/decomp/include/PR/os_thread.h
index 76e528b..d563187 100644
--- a/src/decomp/include/PR/os_thread.h
+++ b/src/decomp/include/PR/os_thread.h
@@ -23,20 +23,31 @@ typedef s32 OSId;
typedef union
{
- struct {f32 f_odd; f32 f_even;} f;
+ struct
+ {
+ f32 f_odd;
+ f32 f_even;
+ } f;
} __OSfp;
typedef struct
{
/* registers */
- /*0x20*/ u64 at, v0, v1, a0, a1, a2, a3;
- /*0x58*/ u64 t0, t1, t2, t3, t4, t5, t6, t7;
- /*0x98*/ u64 s0, s1, s2, s3, s4, s5, s6, s7;
- /*0xD8*/ u64 t8, t9, gp, sp, s8, ra;
- /*0x108*/ u64 lo, hi;
- /*0x118*/ u32 sr, pc, cause, badvaddr, rcp;
- /*0x12C*/ u32 fpcsr;
- __OSfp fp0, fp2, fp4, fp6, fp8, fp10, fp12, fp14;
+ /*0x20*/
+ u64 at, v0, v1, a0, a1, a2, a3;
+ /*0x58*/
+ u64 t0, t1, t2, t3, t4, t5, t6, t7;
+ /*0x98*/
+ u64 s0, s1, s2, s3, s4, s5, s6, s7;
+ /*0xD8*/
+ u64 t8, t9, gp, sp, s8, ra;
+ /*0x108*/
+ u64 lo, hi;
+ /*0x118*/
+ u32 sr, pc, cause, badvaddr, rcp;
+ /*0x12C*/
+ u32 fpcsr;
+ __OSfp fp0, fp2, fp4, fp6, fp8, fp10, fp12, fp14;
__OSfp fp16, fp18, fp20, fp22, fp24, fp26, fp28, fp30;
} __OSThreadContext;
@@ -49,27 +60,43 @@ typedef struct
typedef struct OSThread_s
{
- /*0x00*/ struct OSThread_s *next;
- /*0x04*/ OSPri priority;
- /*0x08*/ struct OSThread_s **queue;
- /*0x0C*/ struct OSThread_s *tlnext;
- /*0x10*/ u16 state;
- /*0x12*/ u16 flags;
- /*0x14*/ OSId id;
- /*0x18*/ int fp;
- /*0x1C*/ __OSThreadprofile_s *thprof;
- /*0x20*/ __OSThreadContext context;
+ /*0x00*/
+ struct OSThread_s *next;
+ /*0x04*/
+ OSPri priority;
+ /*0x08*/
+ struct OSThread_s **queue;
+ /*0x0C*/
+ struct OSThread_s *tlnext;
+ /*0x10*/
+ u16 state;
+ /*0x12*/
+ u16 flags;
+ /*0x14*/
+ OSId id;
+ /*0x18*/
+ int fp;
+ /*0x1C*/
+ __OSThreadprofile_s *thprof;
+ /*0x20*/
+ __OSThreadContext context;
} OSThread;
/* Functions */
-void osCreateThread(OSThread *thread, OSId id, void (*entry)(void *),
+void osCreateThread(
+ OSThread *thread, OSId id, void (*entry)(void *),
void *arg, void *sp, OSPri pri);
+
OSId osGetThreadId(OSThread *thread);
+
OSPri osGetThreadPri(OSThread *thread);
+
void osSetThreadPri(OSThread *thread, OSPri pri);
+
void osStartThread(OSThread *thread);
+
void osStopThread(OSThread *thread);
#endif
diff --git a/src/decomp/include/PR/os_time.h b/src/decomp/include/PR/os_time.h
index 8c7c65f..c4381c8 100644
--- a/src/decomp/include/PR/os_time.h
+++ b/src/decomp/include/PR/os_time.h
@@ -21,7 +21,9 @@ typedef u64 OSTime;
/* Functions */
OSTime osGetTime(void);
+
void osSetTime(OSTime time);
+
u32 osSetTimer(OSTimer *, OSTime, OSTime, OSMesgQueue *, OSMesg);
#endif
diff --git a/src/decomp/include/PR/os_tlb.h b/src/decomp/include/PR/os_tlb.h
index 15b485a..4167ace 100644
--- a/src/decomp/include/PR/os_tlb.h
+++ b/src/decomp/include/PR/os_tlb.h
@@ -31,7 +31,10 @@
#define _OS_TLB_H_
#ifdef _LANGUAGE_C_PLUS_PLUS
-extern "C" {
+extern "C"
+{
+
+
#endif
#include "ultratypes.h"
@@ -91,11 +94,11 @@ typedef u32 OSPageMask;
/* TLB management routines */
-extern void osMapTLB(s32, OSPageMask, void *, u32, u32, s32);
-extern void osMapTLBRdb(void);
-extern void osUnmapTLB(s32);
-extern void osUnmapTLBAll(void);
-extern void osSetTLBASID(s32);
+extern void osMapTLB(s32, OSPageMask, void *, u32, u32, s32);
+extern void osMapTLBRdb(void);
+extern void osUnmapTLB(s32);
+extern void osUnmapTLBAll(void);
+extern void osSetTLBASID(s32);
#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */
diff --git a/src/decomp/include/PR/os_vi.h b/src/decomp/include/PR/os_vi.h
index b487d1d..fe3fd65 100644
--- a/src/decomp/include/PR/os_vi.h
+++ b/src/decomp/include/PR/os_vi.h
@@ -58,26 +58,44 @@ typedef struct
typedef struct
{
- /* 0x00 */ u16 unk00; //some kind of flags. swap buffer sets to 0x10
- /* 0x02 */ u16 retraceCount;
- /* 0x04 */ void* buffer;
- /* 0x08 */ OSViMode *modep;
- /* 0x0c */ u32 features;
- /* 0x10 */ OSMesgQueue *mq;
- /* 0x14 */ OSMesg *msg;
- /* 0x18 */ u32 unk18;
- /* 0x1c */ u32 unk1c;
- /* 0x20 */ u32 unk20;
- /* 0x24 */ f32 unk24;
- /* 0x28 */ u16 unk28;
- /* 0x2c */ u32 unk2c;
+ /* 0x00 */
+ u16 unk00; //some kind of flags. swap buffer sets to 0x10
+ /* 0x02 */
+ u16 retraceCount;
+ /* 0x04 */
+ void *buffer;
+ /* 0x08 */
+ OSViMode *modep;
+ /* 0x0c */
+ u32 features;
+ /* 0x10 */
+ OSMesgQueue *mq;
+ /* 0x14 */
+ OSMesg *msg;
+ /* 0x18 */
+ u32 unk18;
+ /* 0x1c */
+ u32 unk1c;
+ /* 0x20 */
+ u32 unk20;
+ /* 0x24 */
+ f32 unk24;
+ /* 0x28 */
+ u16 unk28;
+ /* 0x2c */
+ u32 unk2c;
} OSViContext;
void osCreateViManager(OSPri pri);
+
void osViSetMode(OSViMode *mode);
+
void osViSetEvent(OSMesgQueue *mq, OSMesg msg, u32 retraceCount);
+
void osViBlack(u8 active);
+
void osViSetSpecialFeatures(u32 func);
+
void osViSwapBuffer(void *vaddr);
@@ -111,7 +129,7 @@ void osViSwapBuffer(void *vaddr);
#define OS_VI_PAL_HPN2 26
#define OS_VI_PAL_HPF2 27
-extern OSViMode osViModeTable[]; /* Global VI mode table */
+extern OSViMode osViModeTable[]; /* Global VI mode table */
#endif
diff --git a/src/decomp/include/PR/sptask.h b/src/decomp/include/PR/sptask.h
index ec443ef..6939352 100644
--- a/src/decomp/include/PR/sptask.h
+++ b/src/decomp/include/PR/sptask.h
@@ -70,32 +70,49 @@
typedef struct
{
- /*0x00*/ u32 type;
- /*0x04*/ u32 flags;
+ /*0x00*/
+ u32 type;
+ /*0x04*/
+ u32 flags;
- /*0x08*/ u64 *ucode_boot;
- /*0x0C*/ u32 ucode_boot_size;
+ /*0x08*/
+ u64 *ucode_boot;
+ /*0x0C*/
+ u32 ucode_boot_size;
- /*0x10*/ u64 *ucode;
- /*0x14*/ u32 ucode_size;
+ /*0x10*/
+ u64 *ucode;
+ /*0x14*/
+ u32 ucode_size;
- /*0x18*/ u64 *ucode_data;
- /*0x1C*/ u32 ucode_data_size;
+ /*0x18*/
+ u64 *ucode_data;
+ /*0x1C*/
+ u32 ucode_data_size;
- /*0x20*/ u64 *dram_stack;
- /*0x24*/ u32 dram_stack_size;
+ /*0x20*/
+ u64 *dram_stack;
+ /*0x24*/
+ u32 dram_stack_size;
- /*0x28*/ u64 *output_buff;
- /*0x2C*/ u64 *output_buff_size;
+ /*0x28*/
+ u64 *output_buff;
+ /*0x2C*/
+ u64 *output_buff_size;
- /*0x30*/ u64 *data_ptr;
- /*0x34*/ u32 data_size;
+ /*0x30*/
+ u64 *data_ptr;
+ /*0x34*/
+ u32 data_size;
- /*0x38*/ u64 *yield_data_ptr;
- /*0x3C*/ u32 yield_data_size;
+ /*0x38*/
+ u64 *yield_data_ptr;
+ /*0x3C*/
+ u32 yield_data_size;
} OSTask_t; // size = 0x40
-typedef union {
+typedef union
+{
OSTask_t t;
long long int force_structure_alignment;
} OSTask;
@@ -109,8 +126,11 @@ typedef u32 OSYieldResult;
osSpTaskStartGo(p);
void osSpTaskLoad(OSTask *task);
+
void osSpTaskStartGo(OSTask *task);
+
void osSpTaskYield(void);
+
OSYieldResult osSpTaskYielded(OSTask *task);
#endif
diff --git a/src/decomp/include/PR/ultratypes.h b/src/decomp/include/PR/ultratypes.h
index 8a00490..45adee1 100644
--- a/src/decomp/include/PR/ultratypes.h
+++ b/src/decomp/include/PR/ultratypes.h
@@ -8,25 +8,25 @@
#define TRUE 1
#define FALSE 0
-typedef signed char s8;
-typedef unsigned char u8;
-typedef signed short int s16;
-typedef unsigned short int u16;
-typedef signed int s32;
-typedef unsigned int u32;
-typedef signed long long int s64;
+typedef signed char s8;
+typedef unsigned char u8;
+typedef signed short int s16;
+typedef unsigned short int u16;
+typedef signed int s32;
+typedef unsigned int u32;
+typedef signed long long int s64;
typedef unsigned long long int u64;
-typedef volatile u8 vu8;
+typedef volatile u8 vu8;
typedef volatile u16 vu16;
typedef volatile u32 vu32;
typedef volatile u64 vu64;
-typedef volatile s8 vs8;
+typedef volatile s8 vs8;
typedef volatile s16 vs16;
typedef volatile s32 vs32;
typedef volatile s64 vs64;
-typedef float f32;
+typedef float f32;
typedef double f64;
#ifdef TARGET_N64
diff --git a/src/decomp/include/audio_defines.h b/src/decomp/include/audio_defines.h
index 7517191..b3324c7 100644
--- a/src/decomp/include/audio_defines.h
+++ b/src/decomp/include/audio_defines.h
@@ -117,47 +117,72 @@
#define SOUND_ACTION_HANGING_STEP SOUND_ARG_LOAD(0, 4, 0x2D, 0xA0, 8)
#define SOUND_ACTION_QUICKSAND_STEP SOUND_ARG_LOAD(0, 4, 0x2E, 0x00, 8)
#define SOUND_ACTION_METAL_STEP_TIPTOE SOUND_ARG_LOAD(0, 4, 0x2F, 0x90, 8)
-/* not verified */ #define SOUND_ACTION_UNKNOWN430 SOUND_ARG_LOAD(0, 4, 0x30, 0xC0, 8)
-/* not verified */ #define SOUND_ACTION_UNKNOWN431 SOUND_ARG_LOAD(0, 4, 0x31, 0x60, 8)
-/* not verified */ #define SOUND_ACTION_UNKNOWN432 SOUND_ARG_LOAD(0, 4, 0x32, 0x80, 8)
+/* not verified */
+#define SOUND_ACTION_UNKNOWN430 SOUND_ARG_LOAD(0, 4, 0x30, 0xC0, 8)
+/* not verified */
+#define SOUND_ACTION_UNKNOWN431 SOUND_ARG_LOAD(0, 4, 0x31, 0x60, 8)
+/* not verified */
+#define SOUND_ACTION_UNKNOWN432 SOUND_ARG_LOAD(0, 4, 0x32, 0x80, 8)
#define SOUND_ACTION_SWIM SOUND_ARG_LOAD(0, 4, 0x33, 0x80, 8)
-/* not verified */ #define SOUND_ACTION_UNKNOWN434 SOUND_ARG_LOAD(0, 4, 0x34, 0x80, 8)
+/* not verified */
+#define SOUND_ACTION_UNKNOWN434 SOUND_ARG_LOAD(0, 4, 0x34, 0x80, 8)
#define SOUND_ACTION_THROW SOUND_ARG_LOAD(0, 4, 0x35, 0x80, 8)
#define SOUND_ACTION_KEY_SWISH SOUND_ARG_LOAD(0, 4, 0x36, 0x80, 8)
#define SOUND_ACTION_SPIN SOUND_ARG_LOAD(0, 4, 0x37, 0x80, 8)
#define SOUND_ACTION_TWIRL SOUND_ARG_LOAD(0, 4, 0x38, 0x80, 8) // same sound as spin
-/* not verified */ #define SOUND_ACTION_CLIMB_UP_TREE SOUND_ARG_LOAD(0, 4, 0x3A, 0x80, 8)
-/* not verified */ #define SOUND_ACTION_CLIMB_DOWN_TREE 0x003B
-/* not verified */ #define SOUND_ACTION_UNK3C 0x003C
-/* not verified */ #define SOUND_ACTION_UNKNOWN43D SOUND_ARG_LOAD(0, 4, 0x3D, 0x80, 8)
-/* not verified */ #define SOUND_ACTION_UNKNOWN43E SOUND_ARG_LOAD(0, 4, 0x3E, 0x80, 8)
-/* not verified */ #define SOUND_ACTION_PAT_BACK SOUND_ARG_LOAD(0, 4, 0x3F, 0x80, 8)
+/* not verified */
+#define SOUND_ACTION_CLIMB_UP_TREE SOUND_ARG_LOAD(0, 4, 0x3A, 0x80, 8)
+/* not verified */
+#define SOUND_ACTION_CLIMB_DOWN_TREE 0x003B
+/* not verified */
+#define SOUND_ACTION_UNK3C 0x003C
+/* not verified */
+#define SOUND_ACTION_UNKNOWN43D SOUND_ARG_LOAD(0, 4, 0x3D, 0x80, 8)
+/* not verified */
+#define SOUND_ACTION_UNKNOWN43E SOUND_ARG_LOAD(0, 4, 0x3E, 0x80, 8)
+/* not verified */
+#define SOUND_ACTION_PAT_BACK SOUND_ARG_LOAD(0, 4, 0x3F, 0x80, 8)
#define SOUND_ACTION_BRUSH_HAIR SOUND_ARG_LOAD(0, 4, 0x40, 0x80, 8)
-/* not verified */ #define SOUND_ACTION_CLIMB_UP_POLE SOUND_ARG_LOAD(0, 4, 0x41, 0x80, 8)
+/* not verified */
+#define SOUND_ACTION_CLIMB_UP_POLE SOUND_ARG_LOAD(0, 4, 0x41, 0x80, 8)
#define SOUND_ACTION_METAL_BONK SOUND_ARG_LOAD(0, 4, 0x42, 0x80, 8)
#define SOUND_ACTION_UNSTUCK_FROM_GROUND SOUND_ARG_LOAD(0, 4, 0x43, 0x80, 8)
-/* not verified */ #define SOUND_ACTION_HIT SOUND_ARG_LOAD(0, 4, 0x44, 0xC0, 8)
-/* not verified */ #define SOUND_ACTION_HIT_2 SOUND_ARG_LOAD(0, 4, 0x44, 0xB0, 8)
-/* not verified */ #define SOUND_ACTION_HIT_3 SOUND_ARG_LOAD(0, 4, 0x44, 0xA0, 8)
+/* not verified */
+#define SOUND_ACTION_HIT SOUND_ARG_LOAD(0, 4, 0x44, 0xC0, 8)
+/* not verified */
+#define SOUND_ACTION_HIT_2 SOUND_ARG_LOAD(0, 4, 0x44, 0xB0, 8)
+/* not verified */
+#define SOUND_ACTION_HIT_3 SOUND_ARG_LOAD(0, 4, 0x44, 0xA0, 8)
#define SOUND_ACTION_BONK SOUND_ARG_LOAD(0, 4, 0x45, 0xA0, 8)
#define SOUND_ACTION_SHRINK_INTO_BBH SOUND_ARG_LOAD(0, 4, 0x46, 0xA0, 8)
#define SOUND_ACTION_SWIM_FAST SOUND_ARG_LOAD(0, 4, 0x47, 0xA0, 8)
#define SOUND_ACTION_METAL_JUMP_WATER SOUND_ARG_LOAD(0, 4, 0x50, 0x90, 8)
#define SOUND_ACTION_METAL_LAND_WATER SOUND_ARG_LOAD(0, 4, 0x51, 0x90, 8)
#define SOUND_ACTION_METAL_STEP_WATER SOUND_ARG_LOAD(0, 4, 0x52, 0x90, 8)
-/* not verified */ #define SOUND_ACTION_UNK53 0x0053
-/* not verified */ #define SOUND_ACTION_UNK54 0x0054
-/* not verified */ #define SOUND_ACTION_UNK55 0x0055
-/* not verified */ #define SOUND_ACTION_FLYING_FAST SOUND_ARG_LOAD(0, 4, 0x56, 0x80, 8) // "swoop"?
+/* not verified */
+#define SOUND_ACTION_UNK53 0x0053
+/* not verified */
+#define SOUND_ACTION_UNK54 0x0054
+/* not verified */
+#define SOUND_ACTION_UNK55 0x0055
+/* not verified */
+#define SOUND_ACTION_FLYING_FAST SOUND_ARG_LOAD(0, 4, 0x56, 0x80, 8) // "swoop"?
#define SOUND_ACTION_TELEPORT SOUND_ARG_LOAD(0, 4, 0x57, 0xC0, 8)
-/* not verified */ #define SOUND_ACTION_UNKNOWN458 SOUND_ARG_LOAD(0, 4, 0x58, 0xA0, 8)
-/* not verified */ #define SOUND_ACTION_BOUNCE_OFF_OBJECT SOUND_ARG_LOAD(0, 4, 0x59, 0xB0, 8)
-/* not verified */ #define SOUND_ACTION_SIDE_FLIP_UNK SOUND_ARG_LOAD(0, 4, 0x5A, 0x80, 8)
+/* not verified */
+#define SOUND_ACTION_UNKNOWN458 SOUND_ARG_LOAD(0, 4, 0x58, 0xA0, 8)
+/* not verified */
+#define SOUND_ACTION_BOUNCE_OFF_OBJECT SOUND_ARG_LOAD(0, 4, 0x59, 0xB0, 8)
+/* not verified */
+#define SOUND_ACTION_SIDE_FLIP_UNK SOUND_ARG_LOAD(0, 4, 0x5A, 0x80, 8)
#define SOUND_ACTION_READ_SIGN SOUND_ARG_LOAD(0, 4, 0x5B, 0xFF, 8)
-/* not verified */ #define SOUND_ACTION_UNKNOWN45C SOUND_ARG_LOAD(0, 4, 0x5C, 0x80, 8)
-/* not verified */ #define SOUND_ACTION_UNK5D 0x005D
-/* not verified */ #define SOUND_ACTION_INTRO_UNK45E SOUND_ARG_LOAD(0, 4, 0x5E, 0x80, 8)
-/* not verified */ #define SOUND_ACTION_INTRO_UNK45F SOUND_ARG_LOAD(0, 4, 0x5F, 0x80, 8)
+/* not verified */
+#define SOUND_ACTION_UNKNOWN45C SOUND_ARG_LOAD(0, 4, 0x5C, 0x80, 8)
+/* not verified */
+#define SOUND_ACTION_UNK5D 0x005D
+/* not verified */
+#define SOUND_ACTION_INTRO_UNK45E SOUND_ARG_LOAD(0, 4, 0x5E, 0x80, 8)
+/* not verified */
+#define SOUND_ACTION_INTRO_UNK45F SOUND_ARG_LOAD(0, 4, 0x5F, 0x80, 8)
/* Moving Sound Effects */
@@ -180,27 +205,45 @@
/* Mario Sound Effects */
// A random number 0-2 is added to the sound ID before playing, producing Yah/Wah/Hoo
#define SOUND_MARIO_YAH_WAH_HOO SOUND_ARG_LOAD(2, 4, 0x00, 0x80, 8)
-/* not verified */ #define SOUND_MARIO_HOOHOO SOUND_ARG_LOAD(2, 4, 0x03, 0x80, 8)
-/* not verified */ #define SOUND_MARIO_YAHOO SOUND_ARG_LOAD(2, 4, 0x04, 0x80, 8)
-/* not verified */ #define SOUND_MARIO_UH SOUND_ARG_LOAD(2, 4, 0x05, 0x80, 8)
-/* not verified */ #define SOUND_MARIO_HRMM SOUND_ARG_LOAD(2, 4, 0x06, 0x80, 8)
-/* not verified */ #define SOUND_MARIO_WAH2 SOUND_ARG_LOAD(2, 4, 0x07, 0x80, 8)
-/* not verified */ #define SOUND_MARIO_WHOA SOUND_ARG_LOAD(2, 4, 0x08, 0xC0, 8)
-/* not verified */ #define SOUND_MARIO_EEUH SOUND_ARG_LOAD(2, 4, 0x09, 0x80, 8)
-/* not verified */ #define SOUND_MARIO_ATTACKED SOUND_ARG_LOAD(2, 4, 0x0A, 0xFF, 8)
-/* not verified */ #define SOUND_MARIO_OOOF SOUND_ARG_LOAD(2, 4, 0x0B, 0x80, 8)
-/* not verified */ #define SOUND_MARIO_OOOF2 SOUND_ARG_LOAD(2, 4, 0x0B, 0xD0, 8)
+/* not verified */
+#define SOUND_MARIO_HOOHOO SOUND_ARG_LOAD(2, 4, 0x03, 0x80, 8)
+/* not verified */
+#define SOUND_MARIO_YAHOO SOUND_ARG_LOAD(2, 4, 0x04, 0x80, 8)
+/* not verified */
+#define SOUND_MARIO_UH SOUND_ARG_LOAD(2, 4, 0x05, 0x80, 8)
+/* not verified */
+#define SOUND_MARIO_HRMM SOUND_ARG_LOAD(2, 4, 0x06, 0x80, 8)
+/* not verified */
+#define SOUND_MARIO_WAH2 SOUND_ARG_LOAD(2, 4, 0x07, 0x80, 8)
+/* not verified */
+#define SOUND_MARIO_WHOA SOUND_ARG_LOAD(2, 4, 0x08, 0xC0, 8)
+/* not verified */
+#define SOUND_MARIO_EEUH SOUND_ARG_LOAD(2, 4, 0x09, 0x80, 8)
+/* not verified */
+#define SOUND_MARIO_ATTACKED SOUND_ARG_LOAD(2, 4, 0x0A, 0xFF, 8)
+/* not verified */
+#define SOUND_MARIO_OOOF SOUND_ARG_LOAD(2, 4, 0x0B, 0x80, 8)
+/* not verified */
+#define SOUND_MARIO_OOOF2 SOUND_ARG_LOAD(2, 4, 0x0B, 0xD0, 8)
#define SOUND_MARIO_HERE_WE_GO SOUND_ARG_LOAD(2, 4, 0x0C, 0x80, 8)
-/* not verified */ #define SOUND_MARIO_YAWNING SOUND_ARG_LOAD(2, 4, 0x0D, 0x80, 8)
+/* not verified */
+#define SOUND_MARIO_YAWNING SOUND_ARG_LOAD(2, 4, 0x0D, 0x80, 8)
#define SOUND_MARIO_SNORING1 SOUND_ARG_LOAD(2, 4, 0x0E, 0x80, 8)
#define SOUND_MARIO_SNORING2 SOUND_ARG_LOAD(2, 4, 0x0F, 0x80, 8)
-/* not verified */ #define SOUND_MARIO_WAAAOOOW SOUND_ARG_LOAD(2, 4, 0x10, 0xC0, 8)
-/* not verified */ #define SOUND_MARIO_HAHA SOUND_ARG_LOAD(2, 4, 0x11, 0x80, 8)
-/* not verified */ #define SOUND_MARIO_HAHA_2 SOUND_ARG_LOAD(2, 4, 0x11, 0xF0, 8)
-/* not verified */ #define SOUND_MARIO_UH2 SOUND_ARG_LOAD(2, 4, 0x13, 0xD0, 8)
-/* not verified */ #define SOUND_MARIO_UH2_2 SOUND_ARG_LOAD(2, 4, 0x13, 0x80, 8)
-/* not verified */ #define SOUND_MARIO_ON_FIRE SOUND_ARG_LOAD(2, 4, 0x14, 0xA0, 8)
-/* not verified */ #define SOUND_MARIO_DYING SOUND_ARG_LOAD(2, 4, 0x15, 0xFF, 8)
+/* not verified */
+#define SOUND_MARIO_WAAAOOOW SOUND_ARG_LOAD(2, 4, 0x10, 0xC0, 8)
+/* not verified */
+#define SOUND_MARIO_HAHA SOUND_ARG_LOAD(2, 4, 0x11, 0x80, 8)
+/* not verified */
+#define SOUND_MARIO_HAHA_2 SOUND_ARG_LOAD(2, 4, 0x11, 0xF0, 8)
+/* not verified */
+#define SOUND_MARIO_UH2 SOUND_ARG_LOAD(2, 4, 0x13, 0xD0, 8)
+/* not verified */
+#define SOUND_MARIO_UH2_2 SOUND_ARG_LOAD(2, 4, 0x13, 0x80, 8)
+/* not verified */
+#define SOUND_MARIO_ON_FIRE SOUND_ARG_LOAD(2, 4, 0x14, 0xA0, 8)
+/* not verified */
+#define SOUND_MARIO_DYING SOUND_ARG_LOAD(2, 4, 0x15, 0xFF, 8)
#define SOUND_MARIO_PANTING_COLD SOUND_ARG_LOAD(2, 4, 0x16, 0x80, 8)
// A random number 0-2 is added to the sound ID before playing
@@ -245,147 +288,268 @@
/* General Sound Effects */
#define SOUND_GENERAL_ACTIVATE_CAP_SWITCH SOUND_ARG_LOAD(3, 0, 0x00, 0x80, 8)
-/* not verified */ #define SOUND_GENERAL_FLAME_OUT SOUND_ARG_LOAD(3, 0, 0x03, 0x80, 8)
-/* not verified */ #define SOUND_GENERAL_OPEN_WOOD_DOOR SOUND_ARG_LOAD(3, 0, 0x04, 0xC0, 8)
-/* not verified */ #define SOUND_GENERAL_CLOSE_WOOD_DOOR SOUND_ARG_LOAD(3, 0, 0x05, 0xC0, 8)
-/* not verified */ #define SOUND_GENERAL_OPEN_IRON_DOOR SOUND_ARG_LOAD(3, 0, 0x06, 0xC0, 8)
-/* not verified */ #define SOUND_GENERAL_CLOSE_IRON_DOOR SOUND_ARG_LOAD(3, 0, 0x07, 0xC0, 8)
-/* not verified */ #define SOUND_GENERAL_BUBBLES 0x3008
-/* not verified */ #define SOUND_GENERAL_MOVING_WATER SOUND_ARG_LOAD(3, 0, 0x09, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_SWISH_WATER SOUND_ARG_LOAD(3, 0, 0x0A, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_QUIET_BUBBLE SOUND_ARG_LOAD(3, 0, 0x0B, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_FLAME_OUT SOUND_ARG_LOAD(3, 0, 0x03, 0x80, 8)
+/* not verified */
+#define SOUND_GENERAL_OPEN_WOOD_DOOR SOUND_ARG_LOAD(3, 0, 0x04, 0xC0, 8)
+/* not verified */
+#define SOUND_GENERAL_CLOSE_WOOD_DOOR SOUND_ARG_LOAD(3, 0, 0x05, 0xC0, 8)
+/* not verified */
+#define SOUND_GENERAL_OPEN_IRON_DOOR SOUND_ARG_LOAD(3, 0, 0x06, 0xC0, 8)
+/* not verified */
+#define SOUND_GENERAL_CLOSE_IRON_DOOR SOUND_ARG_LOAD(3, 0, 0x07, 0xC0, 8)
+/* not verified */
+#define SOUND_GENERAL_BUBBLES 0x3008
+/* not verified */
+#define SOUND_GENERAL_MOVING_WATER SOUND_ARG_LOAD(3, 0, 0x09, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_SWISH_WATER SOUND_ARG_LOAD(3, 0, 0x0A, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_QUIET_BUBBLE SOUND_ARG_LOAD(3, 0, 0x0B, 0x00, 8)
#define SOUND_GENERAL_VOLCANO_EXPLOSION SOUND_ARG_LOAD(3, 0, 0x0C, 0x80, 8)
-/* not verified */ #define SOUND_GENERAL_QUIET_BUBBLE2 SOUND_ARG_LOAD(3, 0, 0x0D, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_QUIET_BUBBLE2 SOUND_ARG_LOAD(3, 0, 0x0D, 0x00, 8)
#define SOUND_GENERAL_CASTLE_TRAP_OPEN SOUND_ARG_LOAD(3, 0, 0x0E, 0x80, 8)
#define SOUND_GENERAL_WALL_EXPLOSION SOUND_ARG_LOAD(3, 0, 0x0F, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_COIN SOUND_ARG_LOAD(3, 8, 0x11, 0x80, 8)
-/* not verified */ #define SOUND_GENERAL_COIN_WATER SOUND_ARG_LOAD(3, 8, 0x12, 0x80, 8)
-/* not verified */ #define SOUND_GENERAL_SHORT_STAR SOUND_ARG_LOAD(3, 0, 0x16, 0x00, 9)
-/* not verified */ #define SOUND_GENERAL_BIG_CLOCK SOUND_ARG_LOAD(3, 0, 0x17, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_LOUD_POUND 0x3018 // _TERRAIN?
-/* not verified */ #define SOUND_GENERAL_LOUD_POUND2 0x3019
-/* not verified */ #define SOUND_GENERAL_SHORT_POUND1 0x301A
-/* not verified */ #define SOUND_GENERAL_SHORT_POUND2 0x301B
-/* not verified */ #define SOUND_GENERAL_SHORT_POUND3 0x301C
-/* not verified */ #define SOUND_GENERAL_SHORT_POUND4 0x301D
-/* not verified */ #define SOUND_GENERAL_SHORT_POUND5 0x301E
-/* not verified */ #define SOUND_GENERAL_SHORT_POUND6 0x301F
+/* not verified */
+#define SOUND_GENERAL_COIN SOUND_ARG_LOAD(3, 8, 0x11, 0x80, 8)
+/* not verified */
+#define SOUND_GENERAL_COIN_WATER SOUND_ARG_LOAD(3, 8, 0x12, 0x80, 8)
+/* not verified */
+#define SOUND_GENERAL_SHORT_STAR SOUND_ARG_LOAD(3, 0, 0x16, 0x00, 9)
+/* not verified */
+#define SOUND_GENERAL_BIG_CLOCK SOUND_ARG_LOAD(3, 0, 0x17, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_LOUD_POUND 0x3018 // _TERRAIN?
+/* not verified */
+#define SOUND_GENERAL_LOUD_POUND2 0x3019
+/* not verified */
+#define SOUND_GENERAL_SHORT_POUND1 0x301A
+/* not verified */
+#define SOUND_GENERAL_SHORT_POUND2 0x301B
+/* not verified */
+#define SOUND_GENERAL_SHORT_POUND3 0x301C
+/* not verified */
+#define SOUND_GENERAL_SHORT_POUND4 0x301D
+/* not verified */
+#define SOUND_GENERAL_SHORT_POUND5 0x301E
+/* not verified */
+#define SOUND_GENERAL_SHORT_POUND6 0x301F
#define SOUND_GENERAL_OPEN_CHEST SOUND_ARG_LOAD(3, 1, 0x20, 0x80, 8)
-/* not verified */ #define SOUND_GENERAL_CLAM_SHELL1 SOUND_ARG_LOAD(3, 1, 0x22, 0x80, 8)
-/* not verified */ #define SOUND_GENERAL_BOX_LANDING SOUND_ARG_LOAD(3, 0, 0x24, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_BOX_LANDING_2 SOUND_ARG_LOAD(3, 2, 0x24, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_UNKNOWN1 SOUND_ARG_LOAD(3, 0, 0x25, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_UNKNOWN1_2 SOUND_ARG_LOAD(3, 2, 0x25, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_CLAM_SHELL2 SOUND_ARG_LOAD(3, 0, 0x26, 0x40, 8)
-/* not verified */ #define SOUND_GENERAL_CLAM_SHELL3 SOUND_ARG_LOAD(3, 0, 0x27, 0x40, 8)
+/* not verified */
+#define SOUND_GENERAL_CLAM_SHELL1 SOUND_ARG_LOAD(3, 1, 0x22, 0x80, 8)
+/* not verified */
+#define SOUND_GENERAL_BOX_LANDING SOUND_ARG_LOAD(3, 0, 0x24, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_BOX_LANDING_2 SOUND_ARG_LOAD(3, 2, 0x24, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_UNKNOWN1 SOUND_ARG_LOAD(3, 0, 0x25, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_UNKNOWN1_2 SOUND_ARG_LOAD(3, 2, 0x25, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_CLAM_SHELL2 SOUND_ARG_LOAD(3, 0, 0x26, 0x40, 8)
+/* not verified */
+#define SOUND_GENERAL_CLAM_SHELL3 SOUND_ARG_LOAD(3, 0, 0x27, 0x40, 8)
#ifdef VERSION_JP
#define SOUND_GENERAL_PAINTING_EJECT SOUND_ARG_LOAD(3, 8, 0x28, 0x00, 8)
#else
#define SOUND_GENERAL_PAINTING_EJECT SOUND_ARG_LOAD(3, 9, 0x28, 0x00, 8)
#endif
#define SOUND_GENERAL_LEVEL_SELECT_CHANGE SOUND_ARG_LOAD(3, 0, 0x2B, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_PLATFORM SOUND_ARG_LOAD(3, 0, 0x2D, 0x80, 8)
+/* not verified */
+#define SOUND_GENERAL_PLATFORM SOUND_ARG_LOAD(3, 0, 0x2D, 0x80, 8)
#define SOUND_GENERAL_DONUT_PLATFORM_EXPLOSION SOUND_ARG_LOAD(3, 0, 0x2E, 0x20, 8)
#define SOUND_GENERAL_BOWSER_BOMB_EXPLOSION SOUND_ARG_LOAD(3, 1, 0x2F, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_COIN_SPURT SOUND_ARG_LOAD(3, 0, 0x30, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_COIN_SPURT_2 SOUND_ARG_LOAD(3, 8, 0x30, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_COIN_SPURT_EU SOUND_ARG_LOAD(3, 8, 0x30, 0x20, 8)
+/* not verified */
+#define SOUND_GENERAL_COIN_SPURT SOUND_ARG_LOAD(3, 0, 0x30, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_COIN_SPURT_2 SOUND_ARG_LOAD(3, 8, 0x30, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_COIN_SPURT_EU SOUND_ARG_LOAD(3, 8, 0x30, 0x20, 8)
-/* not verified */ #define SOUND_GENERAL_EXPLOSION6 0x3031
-/* not verified */ #define SOUND_GENERAL_UNK32 0x3032
-/* not verified */ #define SOUND_GENERAL_BOAT_TILT1 SOUND_ARG_LOAD(3, 0, 0x34, 0x40, 8)
-/* not verified */ #define SOUND_GENERAL_BOAT_TILT2 SOUND_ARG_LOAD(3, 0, 0x35, 0x40, 8)
-/* not verified */ #define SOUND_GENERAL_COIN_DROP SOUND_ARG_LOAD(3, 0, 0x36, 0x40, 8)
-/* not verified */ #define SOUND_GENERAL_UNKNOWN3_LOWPRIO SOUND_ARG_LOAD(3, 0, 0x37, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_UNKNOWN3 SOUND_ARG_LOAD(3, 0, 0x37, 0x80, 8)
-/* not verified */ #define SOUND_GENERAL_UNKNOWN3_2 SOUND_ARG_LOAD(3, 8, 0x37, 0x80, 8)
+/* not verified */
+#define SOUND_GENERAL_EXPLOSION6 0x3031
+/* not verified */
+#define SOUND_GENERAL_UNK32 0x3032
+/* not verified */
+#define SOUND_GENERAL_BOAT_TILT1 SOUND_ARG_LOAD(3, 0, 0x34, 0x40, 8)
+/* not verified */
+#define SOUND_GENERAL_BOAT_TILT2 SOUND_ARG_LOAD(3, 0, 0x35, 0x40, 8)
+/* not verified */
+#define SOUND_GENERAL_COIN_DROP SOUND_ARG_LOAD(3, 0, 0x36, 0x40, 8)
+/* not verified */
+#define SOUND_GENERAL_UNKNOWN3_LOWPRIO SOUND_ARG_LOAD(3, 0, 0x37, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_UNKNOWN3 SOUND_ARG_LOAD(3, 0, 0x37, 0x80, 8)
+/* not verified */
+#define SOUND_GENERAL_UNKNOWN3_2 SOUND_ARG_LOAD(3, 8, 0x37, 0x80, 8)
#define SOUND_GENERAL_PENDULUM_SWING SOUND_ARG_LOAD(3, 0, 0x38, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_CHAIN_CHOMP1 SOUND_ARG_LOAD(3, 0, 0x39, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_CHAIN_CHOMP2 SOUND_ARG_LOAD(3, 0, 0x3A, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_CHAIN_CHOMP1 SOUND_ARG_LOAD(3, 0, 0x39, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_CHAIN_CHOMP2 SOUND_ARG_LOAD(3, 0, 0x3A, 0x00, 8)
#define SOUND_GENERAL_DOOR_TURN_KEY SOUND_ARG_LOAD(3, 0, 0x3B, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_MOVING_IN_SAND SOUND_ARG_LOAD(3, 0, 0x3C, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_UNKNOWN4_LOWPRIO SOUND_ARG_LOAD(3, 0, 0x3D, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_UNKNOWN4 SOUND_ARG_LOAD(3, 0, 0x3D, 0x80, 8)
+/* not verified */
+#define SOUND_GENERAL_MOVING_IN_SAND SOUND_ARG_LOAD(3, 0, 0x3C, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_UNKNOWN4_LOWPRIO SOUND_ARG_LOAD(3, 0, 0x3D, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_UNKNOWN4 SOUND_ARG_LOAD(3, 0, 0x3D, 0x80, 8)
#define SOUND_GENERAL_MOVING_PLATFORM_SWITCH SOUND_ARG_LOAD(3, 0, 0x3E, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_CAGE_OPEN SOUND_ARG_LOAD(3, 0, 0x3F, 0xA0, 8)
-/* not verified */ #define SOUND_GENERAL_QUIET_POUND1_LOWPRIO SOUND_ARG_LOAD(3, 0, 0x40, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_QUIET_POUND1 SOUND_ARG_LOAD(3, 0, 0x40, 0x40, 8)
-/* not verified */ #define SOUND_GENERAL_BREAK_BOX SOUND_ARG_LOAD(3, 0, 0x41, 0xC0, 8)
+/* not verified */
+#define SOUND_GENERAL_CAGE_OPEN SOUND_ARG_LOAD(3, 0, 0x3F, 0xA0, 8)
+/* not verified */
+#define SOUND_GENERAL_QUIET_POUND1_LOWPRIO SOUND_ARG_LOAD(3, 0, 0x40, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_QUIET_POUND1 SOUND_ARG_LOAD(3, 0, 0x40, 0x40, 8)
+/* not verified */
+#define SOUND_GENERAL_BREAK_BOX SOUND_ARG_LOAD(3, 0, 0x41, 0xC0, 8)
#define SOUND_GENERAL_DOOR_INSERT_KEY SOUND_ARG_LOAD(3, 0, 0x42, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_QUIET_POUND2 SOUND_ARG_LOAD(3, 0, 0x43, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_BIG_POUND SOUND_ARG_LOAD(3, 0, 0x44, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_UNK45 SOUND_ARG_LOAD(3, 0, 0x45, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_UNK46_LOWPRIO SOUND_ARG_LOAD(3, 0, 0x46, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_UNK46 SOUND_ARG_LOAD(3, 0, 0x46, 0x80, 8)
-/* not verified */ #define SOUND_GENERAL_CANNON_UP SOUND_ARG_LOAD(3, 0, 0x47, 0x80, 8)
-/* not verified */ #define SOUND_GENERAL_GRINDEL_ROLL SOUND_ARG_LOAD(3, 0, 0x48, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_EXPLOSION7 0x3049
-/* not verified */ #define SOUND_GENERAL_SHAKE_COFFIN 0x304A
-/* not verified */ #define SOUND_GENERAL_RACE_GUN_SHOT SOUND_ARG_LOAD(3, 1, 0x4D, 0x40, 8)
-/* not verified */ #define SOUND_GENERAL_STAR_DOOR_OPEN SOUND_ARG_LOAD(3, 0, 0x4E, 0xC0, 8)
-/* not verified */ #define SOUND_GENERAL_STAR_DOOR_CLOSE SOUND_ARG_LOAD(3, 0, 0x4F, 0xC0, 8)
-/* not verified */ #define SOUND_GENERAL_POUND_ROCK SOUND_ARG_LOAD(3, 0, 0x56, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_STAR_APPEARS SOUND_ARG_LOAD(3, 0, 0x57, 0xFF, 9)
+/* not verified */
+#define SOUND_GENERAL_QUIET_POUND2 SOUND_ARG_LOAD(3, 0, 0x43, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_BIG_POUND SOUND_ARG_LOAD(3, 0, 0x44, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_UNK45 SOUND_ARG_LOAD(3, 0, 0x45, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_UNK46_LOWPRIO SOUND_ARG_LOAD(3, 0, 0x46, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_UNK46 SOUND_ARG_LOAD(3, 0, 0x46, 0x80, 8)
+/* not verified */
+#define SOUND_GENERAL_CANNON_UP SOUND_ARG_LOAD(3, 0, 0x47, 0x80, 8)
+/* not verified */
+#define SOUND_GENERAL_GRINDEL_ROLL SOUND_ARG_LOAD(3, 0, 0x48, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_EXPLOSION7 0x3049
+/* not verified */
+#define SOUND_GENERAL_SHAKE_COFFIN 0x304A
+/* not verified */
+#define SOUND_GENERAL_RACE_GUN_SHOT SOUND_ARG_LOAD(3, 1, 0x4D, 0x40, 8)
+/* not verified */
+#define SOUND_GENERAL_STAR_DOOR_OPEN SOUND_ARG_LOAD(3, 0, 0x4E, 0xC0, 8)
+/* not verified */
+#define SOUND_GENERAL_STAR_DOOR_CLOSE SOUND_ARG_LOAD(3, 0, 0x4F, 0xC0, 8)
+/* not verified */
+#define SOUND_GENERAL_POUND_ROCK SOUND_ARG_LOAD(3, 0, 0x56, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_STAR_APPEARS SOUND_ARG_LOAD(3, 0, 0x57, 0xFF, 9)
#define SOUND_GENERAL_COLLECT_1UP SOUND_ARG_LOAD(3, 0, 0x58, 0xFF, 8)
-/* not verified */ #define SOUND_GENERAL_BUTTON_PRESS_LOWPRIO SOUND_ARG_LOAD(3, 0, 0x5A, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_BUTTON_PRESS SOUND_ARG_LOAD(3, 0, 0x5A, 0x40, 8)
-/* not verified */ #define SOUND_GENERAL_BUTTON_PRESS_2_LOWPRIO SOUND_ARG_LOAD(3, 1, 0x5A, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_BUTTON_PRESS_2 SOUND_ARG_LOAD(3, 1, 0x5A, 0x40, 8)
-/* not verified */ #define SOUND_GENERAL_ELEVATOR_MOVE SOUND_ARG_LOAD(3, 0, 0x5B, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_ELEVATOR_MOVE_2 SOUND_ARG_LOAD(3, 1, 0x5B, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_SWISH_AIR SOUND_ARG_LOAD(3, 0, 0x5C, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_SWISH_AIR_2 SOUND_ARG_LOAD(3, 1, 0x5C, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_HAUNTED_CHAIR SOUND_ARG_LOAD(3, 0, 0x5D, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_SOFT_LANDING SOUND_ARG_LOAD(3, 0, 0x5E, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_HAUNTED_CHAIR_MOVE SOUND_ARG_LOAD(3, 0, 0x5F, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_BOWSER_PLATFORM SOUND_ARG_LOAD(3, 0, 0x62, 0x80, 8)
-/* not verified */ #define SOUND_GENERAL_BOWSER_PLATFORM_2 SOUND_ARG_LOAD(3, 1, 0x62, 0x80, 8)
-/* not verified */ #define SOUND_GENERAL_HEART_SPIN SOUND_ARG_LOAD(3, 0, 0x64, 0xC0, 8)
-/* not verified */ #define SOUND_GENERAL_POUND_WOOD_POST SOUND_ARG_LOAD(3, 0, 0x65, 0xC0, 8)
-/* not verified */ #define SOUND_GENERAL_WATER_LEVEL_TRIG SOUND_ARG_LOAD(3, 0, 0x66, 0x80, 8)
-/* not verified */ #define SOUND_GENERAL_SWITCH_DOOR_OPEN SOUND_ARG_LOAD(3, 0, 0x67, 0xA0, 8)
-/* not verified */ #define SOUND_GENERAL_RED_COIN SOUND_ARG_LOAD(3, 0, 0x68, 0x90, 8)
-/* not verified */ #define SOUND_GENERAL_BIRDS_FLY_AWAY SOUND_ARG_LOAD(3, 0, 0x69, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_METAL_POUND SOUND_ARG_LOAD(3, 0, 0x6B, 0x80, 8)
-/* not verified */ #define SOUND_GENERAL_BOING1 SOUND_ARG_LOAD(3, 0, 0x6C, 0x40, 8)
-/* not verified */ #define SOUND_GENERAL_BOING2_LOWPRIO SOUND_ARG_LOAD(3, 0, 0x6D, 0x20, 8)
-/* not verified */ #define SOUND_GENERAL_BOING2 SOUND_ARG_LOAD(3, 0, 0x6D, 0x40, 8)
-/* not verified */ #define SOUND_GENERAL_YOSHI_WALK SOUND_ARG_LOAD(3, 0, 0x6E, 0x20, 8)
-/* not verified */ #define SOUND_GENERAL_ENEMY_ALERT1 SOUND_ARG_LOAD(3, 0, 0x6F, 0x30, 8)
-/* not verified */ #define SOUND_GENERAL_YOSHI_TALK SOUND_ARG_LOAD(3, 0, 0x70, 0x30, 8)
-/* not verified */ #define SOUND_GENERAL_SPLATTERING SOUND_ARG_LOAD(3, 0, 0x71, 0x30, 8)
-/* not verified */ #define SOUND_GENERAL_BOING3 0x3072
-/* not verified */ #define SOUND_GENERAL_GRAND_STAR SOUND_ARG_LOAD(3, 0, 0x73, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_GRAND_STAR_JUMP SOUND_ARG_LOAD(3, 0, 0x74, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_BOAT_ROCK SOUND_ARG_LOAD(3, 0, 0x75, 0x00, 8)
-/* not verified */ #define SOUND_GENERAL_VANISH_SFX SOUND_ARG_LOAD(3, 0, 0x76, 0x20, 8)
+/* not verified */
+#define SOUND_GENERAL_BUTTON_PRESS_LOWPRIO SOUND_ARG_LOAD(3, 0, 0x5A, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_BUTTON_PRESS SOUND_ARG_LOAD(3, 0, 0x5A, 0x40, 8)
+/* not verified */
+#define SOUND_GENERAL_BUTTON_PRESS_2_LOWPRIO SOUND_ARG_LOAD(3, 1, 0x5A, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_BUTTON_PRESS_2 SOUND_ARG_LOAD(3, 1, 0x5A, 0x40, 8)
+/* not verified */
+#define SOUND_GENERAL_ELEVATOR_MOVE SOUND_ARG_LOAD(3, 0, 0x5B, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_ELEVATOR_MOVE_2 SOUND_ARG_LOAD(3, 1, 0x5B, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_SWISH_AIR SOUND_ARG_LOAD(3, 0, 0x5C, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_SWISH_AIR_2 SOUND_ARG_LOAD(3, 1, 0x5C, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_HAUNTED_CHAIR SOUND_ARG_LOAD(3, 0, 0x5D, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_SOFT_LANDING SOUND_ARG_LOAD(3, 0, 0x5E, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_HAUNTED_CHAIR_MOVE SOUND_ARG_LOAD(3, 0, 0x5F, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_BOWSER_PLATFORM SOUND_ARG_LOAD(3, 0, 0x62, 0x80, 8)
+/* not verified */
+#define SOUND_GENERAL_BOWSER_PLATFORM_2 SOUND_ARG_LOAD(3, 1, 0x62, 0x80, 8)
+/* not verified */
+#define SOUND_GENERAL_HEART_SPIN SOUND_ARG_LOAD(3, 0, 0x64, 0xC0, 8)
+/* not verified */
+#define SOUND_GENERAL_POUND_WOOD_POST SOUND_ARG_LOAD(3, 0, 0x65, 0xC0, 8)
+/* not verified */
+#define SOUND_GENERAL_WATER_LEVEL_TRIG SOUND_ARG_LOAD(3, 0, 0x66, 0x80, 8)
+/* not verified */
+#define SOUND_GENERAL_SWITCH_DOOR_OPEN SOUND_ARG_LOAD(3, 0, 0x67, 0xA0, 8)
+/* not verified */
+#define SOUND_GENERAL_RED_COIN SOUND_ARG_LOAD(3, 0, 0x68, 0x90, 8)
+/* not verified */
+#define SOUND_GENERAL_BIRDS_FLY_AWAY SOUND_ARG_LOAD(3, 0, 0x69, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_METAL_POUND SOUND_ARG_LOAD(3, 0, 0x6B, 0x80, 8)
+/* not verified */
+#define SOUND_GENERAL_BOING1 SOUND_ARG_LOAD(3, 0, 0x6C, 0x40, 8)
+/* not verified */
+#define SOUND_GENERAL_BOING2_LOWPRIO SOUND_ARG_LOAD(3, 0, 0x6D, 0x20, 8)
+/* not verified */
+#define SOUND_GENERAL_BOING2 SOUND_ARG_LOAD(3, 0, 0x6D, 0x40, 8)
+/* not verified */
+#define SOUND_GENERAL_YOSHI_WALK SOUND_ARG_LOAD(3, 0, 0x6E, 0x20, 8)
+/* not verified */
+#define SOUND_GENERAL_ENEMY_ALERT1 SOUND_ARG_LOAD(3, 0, 0x6F, 0x30, 8)
+/* not verified */
+#define SOUND_GENERAL_YOSHI_TALK SOUND_ARG_LOAD(3, 0, 0x70, 0x30, 8)
+/* not verified */
+#define SOUND_GENERAL_SPLATTERING SOUND_ARG_LOAD(3, 0, 0x71, 0x30, 8)
+/* not verified */
+#define SOUND_GENERAL_BOING3 0x3072
+/* not verified */
+#define SOUND_GENERAL_GRAND_STAR SOUND_ARG_LOAD(3, 0, 0x73, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_GRAND_STAR_JUMP SOUND_ARG_LOAD(3, 0, 0x74, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_BOAT_ROCK SOUND_ARG_LOAD(3, 0, 0x75, 0x00, 8)
+/* not verified */
+#define SOUND_GENERAL_VANISH_SFX SOUND_ARG_LOAD(3, 0, 0x76, 0x20, 8)
/* Environment Sound Effects */
-/* not verified */ #define SOUND_ENV_WATERFALL1 SOUND_ARG_LOAD(4, 0, 0x00, 0x00, 0)
-/* not verified */ #define SOUND_ENV_WATERFALL2 SOUND_ARG_LOAD(4, 0, 0x01, 0x00, 0)
-/* not verified */ #define SOUND_ENV_ELEVATOR1 SOUND_ARG_LOAD(4, 0, 0x02, 0x00, 0)
-/* not verified */ #define SOUND_ENV_DRONING1 SOUND_ARG_LOAD(4, 1, 0x03, 0x00, 0)
-/* not verified */ #define SOUND_ENV_DRONING2 SOUND_ARG_LOAD(4, 0, 0x04, 0x00, 0)
-/* not verified */ #define SOUND_ENV_WIND1 SOUND_ARG_LOAD(4, 0, 0x05, 0x00, 0)
-/* not verified */ #define SOUND_ENV_MOVING_SAND_SNOW 0x4006
-/* not verified */ #define SOUND_ENV_UNK07 0x4007
-/* not verified */ #define SOUND_ENV_ELEVATOR2 SOUND_ARG_LOAD(4, 0, 0x08, 0x00, 0)
-/* not verified */ #define SOUND_ENV_WATER SOUND_ARG_LOAD(4, 0, 0x09, 0x00, 0)
-/* not verified */ #define SOUND_ENV_UNKNOWN2 SOUND_ARG_LOAD(4, 0, 0x0A, 0x00, 0)
-/* not verified */ #define SOUND_ENV_BOAT_ROCKING1 SOUND_ARG_LOAD(4, 0, 0x0B, 0x00, 0)
-/* not verified */ #define SOUND_ENV_ELEVATOR3 SOUND_ARG_LOAD(4, 0, 0x0C, 0x00, 0)
-/* not verified */ #define SOUND_ENV_ELEVATOR4 SOUND_ARG_LOAD(4, 0, 0x0D, 0x00, 0)
-/* not verified */ #define SOUND_ENV_ELEVATOR4_2 SOUND_ARG_LOAD(4, 1, 0x0D, 0x00, 0)
-/* not verified */ #define SOUND_ENV_MOVINGSAND SOUND_ARG_LOAD(4, 0, 0x0E, 0x00, 0)
-/* not verified */ #define SOUND_ENV_MERRY_GO_ROUND_CREAKING SOUND_ARG_LOAD(4, 0, 0x0F, 0x40, 0)
-/* not verified */ #define SOUND_ENV_WIND2 SOUND_ARG_LOAD(4, 0, 0x10, 0x80, 0)
-/* not verified */ #define SOUND_ENV_UNK12 0x4012
-/* not verified */ #define SOUND_ENV_SLIDING SOUND_ARG_LOAD(4, 0, 0x13, 0x00, 0)
-/* not verified */ #define SOUND_ENV_STAR SOUND_ARG_LOAD(4, 0, 0x14, 0x00, 1)
-/* not verified */ #define SOUND_ENV_UNKNOWN4 SOUND_ARG_LOAD(4, 1, 0x15, 0x00, 0)
-/* not verified */ #define SOUND_ENV_WATER_DRAIN SOUND_ARG_LOAD(4, 1, 0x16, 0x00, 0)
-/* not verified */ #define SOUND_ENV_METAL_BOX_PUSH SOUND_ARG_LOAD(4, 0, 0x17, 0x80, 0)
-/* not verified */ #define SOUND_ENV_SINK_QUICKSAND SOUND_ARG_LOAD(4, 0, 0x18, 0x80, 0)
+/* not verified */
+#define SOUND_ENV_WATERFALL1 SOUND_ARG_LOAD(4, 0, 0x00, 0x00, 0)
+/* not verified */
+#define SOUND_ENV_WATERFALL2 SOUND_ARG_LOAD(4, 0, 0x01, 0x00, 0)
+/* not verified */
+#define SOUND_ENV_ELEVATOR1 SOUND_ARG_LOAD(4, 0, 0x02, 0x00, 0)
+/* not verified */
+#define SOUND_ENV_DRONING1 SOUND_ARG_LOAD(4, 1, 0x03, 0x00, 0)
+/* not verified */
+#define SOUND_ENV_DRONING2 SOUND_ARG_LOAD(4, 0, 0x04, 0x00, 0)
+/* not verified */
+#define SOUND_ENV_WIND1 SOUND_ARG_LOAD(4, 0, 0x05, 0x00, 0)
+/* not verified */
+#define SOUND_ENV_MOVING_SAND_SNOW 0x4006
+/* not verified */
+#define SOUND_ENV_UNK07 0x4007
+/* not verified */
+#define SOUND_ENV_ELEVATOR2 SOUND_ARG_LOAD(4, 0, 0x08, 0x00, 0)
+/* not verified */
+#define SOUND_ENV_WATER SOUND_ARG_LOAD(4, 0, 0x09, 0x00, 0)
+/* not verified */
+#define SOUND_ENV_UNKNOWN2 SOUND_ARG_LOAD(4, 0, 0x0A, 0x00, 0)
+/* not verified */
+#define SOUND_ENV_BOAT_ROCKING1 SOUND_ARG_LOAD(4, 0, 0x0B, 0x00, 0)
+/* not verified */
+#define SOUND_ENV_ELEVATOR3 SOUND_ARG_LOAD(4, 0, 0x0C, 0x00, 0)
+/* not verified */
+#define SOUND_ENV_ELEVATOR4 SOUND_ARG_LOAD(4, 0, 0x0D, 0x00, 0)
+/* not verified */
+#define SOUND_ENV_ELEVATOR4_2 SOUND_ARG_LOAD(4, 1, 0x0D, 0x00, 0)
+/* not verified */
+#define SOUND_ENV_MOVINGSAND SOUND_ARG_LOAD(4, 0, 0x0E, 0x00, 0)
+/* not verified */
+#define SOUND_ENV_MERRY_GO_ROUND_CREAKING SOUND_ARG_LOAD(4, 0, 0x0F, 0x40, 0)
+/* not verified */
+#define SOUND_ENV_WIND2 SOUND_ARG_LOAD(4, 0, 0x10, 0x80, 0)
+/* not verified */
+#define SOUND_ENV_UNK12 0x4012
+/* not verified */
+#define SOUND_ENV_SLIDING SOUND_ARG_LOAD(4, 0, 0x13, 0x00, 0)
+/* not verified */
+#define SOUND_ENV_STAR SOUND_ARG_LOAD(4, 0, 0x14, 0x00, 1)
+/* not verified */
+#define SOUND_ENV_UNKNOWN4 SOUND_ARG_LOAD(4, 1, 0x15, 0x00, 0)
+/* not verified */
+#define SOUND_ENV_WATER_DRAIN SOUND_ARG_LOAD(4, 1, 0x16, 0x00, 0)
+/* not verified */
+#define SOUND_ENV_METAL_BOX_PUSH SOUND_ARG_LOAD(4, 0, 0x17, 0x80, 0)
+/* not verified */
+#define SOUND_ENV_SINK_QUICKSAND SOUND_ARG_LOAD(4, 0, 0x18, 0x80, 0)
/* Object Sound Effects */
#define SOUND_OBJ_SUSHI_SHARK_WATER_SOUND SOUND_ARG_LOAD(5, 0, 0x00, 0x80, 8)
@@ -400,45 +564,69 @@
#define SOUND_OBJ_BOO_BOUNCE_TOP SOUND_ARG_LOAD(5, 0, 0x0A, 0x00, 8)
#define SOUND_OBJ_BOO_LAUGH_SHORT SOUND_ARG_LOAD(5, 0, 0x0B, 0x00, 8)
#define SOUND_OBJ_THWOMP SOUND_ARG_LOAD(5, 0, 0x0C, 0xA0, 8)
-/* not verified */ #define SOUND_OBJ_CANNON1 SOUND_ARG_LOAD(5, 0, 0x0D, 0xF0, 8)
-/* not verified */ #define SOUND_OBJ_CANNON2 SOUND_ARG_LOAD(5, 0, 0x0E, 0xF0, 8)
-/* not verified */ #define SOUND_OBJ_CANNON3 SOUND_ARG_LOAD(5, 0, 0x0F, 0xF0, 8)
-/* not verified */ #define SOUND_OBJ_JUMP_WALK_WATER 0x5012
-/* not verified */ #define SOUND_OBJ_UNKNOWN2 SOUND_ARG_LOAD(5, 0, 0x13, 0x00, 8)
+/* not verified */
+#define SOUND_OBJ_CANNON1 SOUND_ARG_LOAD(5, 0, 0x0D, 0xF0, 8)
+/* not verified */
+#define SOUND_OBJ_CANNON2 SOUND_ARG_LOAD(5, 0, 0x0E, 0xF0, 8)
+/* not verified */
+#define SOUND_OBJ_CANNON3 SOUND_ARG_LOAD(5, 0, 0x0F, 0xF0, 8)
+/* not verified */
+#define SOUND_OBJ_JUMP_WALK_WATER 0x5012
+/* not verified */
+#define SOUND_OBJ_UNKNOWN2 SOUND_ARG_LOAD(5, 0, 0x13, 0x00, 8)
#define SOUND_OBJ_MRI_DEATH SOUND_ARG_LOAD(5, 0, 0x14, 0x00, 8)
-/* not verified */ #define SOUND_OBJ_POUNDING1 SOUND_ARG_LOAD(5, 0, 0x15, 0x50, 8)
-/* not verified */ #define SOUND_OBJ_POUNDING1_HIGHPRIO SOUND_ARG_LOAD(5, 0, 0x15, 0x80, 8)
+/* not verified */
+#define SOUND_OBJ_POUNDING1 SOUND_ARG_LOAD(5, 0, 0x15, 0x50, 8)
+/* not verified */
+#define SOUND_OBJ_POUNDING1_HIGHPRIO SOUND_ARG_LOAD(5, 0, 0x15, 0x80, 8)
#define SOUND_OBJ_WHOMP_LOWPRIO SOUND_ARG_LOAD(5, 0, 0x16, 0x60, 8)
#define SOUND_OBJ_KING_BOBOMB SOUND_ARG_LOAD(5, 0, 0x16, 0x80, 8)
-/* not verified */ #define SOUND_OBJ_BULLY_METAL SOUND_ARG_LOAD(5, 0, 0x17, 0x80, 8)
-/* not verified */ #define SOUND_OBJ_BULLY_EXPLODE SOUND_ARG_LOAD(5, 0, 0x18, 0xA0, 8)
-/* not verified */ #define SOUND_OBJ_BULLY_EXPLODE_2 SOUND_ARG_LOAD(5, 1, 0x18, 0xA0, 8)
-/* not verified */ #define SOUND_OBJ_POUNDING_CANNON SOUND_ARG_LOAD(5, 0, 0x1A, 0x50, 8)
-/* not verified */ #define SOUND_OBJ_BULLY_WALK SOUND_ARG_LOAD(5, 0, 0x1B, 0x30, 8)
-/* not verified */ #define SOUND_OBJ_UNKNOWN3 SOUND_ARG_LOAD(5, 0, 0x1D, 0x80, 8)
-/* not verified */ #define SOUND_OBJ_UNKNOWN4 SOUND_ARG_LOAD(5, 0, 0x1E, 0xA0, 8)
+/* not verified */
+#define SOUND_OBJ_BULLY_METAL SOUND_ARG_LOAD(5, 0, 0x17, 0x80, 8)
+/* not verified */
+#define SOUND_OBJ_BULLY_EXPLODE SOUND_ARG_LOAD(5, 0, 0x18, 0xA0, 8)
+/* not verified */
+#define SOUND_OBJ_BULLY_EXPLODE_2 SOUND_ARG_LOAD(5, 1, 0x18, 0xA0, 8)
+/* not verified */
+#define SOUND_OBJ_POUNDING_CANNON SOUND_ARG_LOAD(5, 0, 0x1A, 0x50, 8)
+/* not verified */
+#define SOUND_OBJ_BULLY_WALK SOUND_ARG_LOAD(5, 0, 0x1B, 0x30, 8)
+/* not verified */
+#define SOUND_OBJ_UNKNOWN3 SOUND_ARG_LOAD(5, 0, 0x1D, 0x80, 8)
+/* not verified */
+#define SOUND_OBJ_UNKNOWN4 SOUND_ARG_LOAD(5, 0, 0x1E, 0xA0, 8)
#define SOUND_OBJ_BABY_PENGUIN_DIVE SOUND_ARG_LOAD(5, 0, 0x1F, 0x40, 8)
#define SOUND_OBJ_GOOMBA_WALK SOUND_ARG_LOAD(5, 0, 0x20, 0x00, 8)
#define SOUND_OBJ_UKIKI_CHATTER_LONG SOUND_ARG_LOAD(5, 0, 0x21, 0x00, 8)
#define SOUND_OBJ_MONTY_MOLE_ATTACK SOUND_ARG_LOAD(5, 0, 0x22, 0x00, 8)
#define SOUND_OBJ_EVIL_LAKITU_THROW SOUND_ARG_LOAD(5, 0, 0x22, 0x20, 8)
-/* not verified */ #define SOUND_OBJ_UNK23 0x5023
+/* not verified */
+#define SOUND_OBJ_UNK23 0x5023
#define SOUND_OBJ_DYING_ENEMY1 SOUND_ARG_LOAD(5, 0, 0x24, 0x40, 8)
-/* not verified */ #define SOUND_OBJ_CANNON4 SOUND_ARG_LOAD(5, 0, 0x25, 0x40, 8)
-/* not verified */ #define SOUND_OBJ_DYING_ENEMY2 0x5026
+/* not verified */
+#define SOUND_OBJ_CANNON4 SOUND_ARG_LOAD(5, 0, 0x25, 0x40, 8)
+/* not verified */
+#define SOUND_OBJ_DYING_ENEMY2 0x5026
#define SOUND_OBJ_BOBOMB_WALK SOUND_ARG_LOAD(5, 0, 0x27, 0x00, 8)
-/* not verified */ #define SOUND_OBJ_SOMETHING_LANDING SOUND_ARG_LOAD(5, 0, 0x28, 0x80, 8)
-/* not verified */ #define SOUND_OBJ_DIVING_IN_WATER SOUND_ARG_LOAD(5, 0, 0x29, 0xA0, 8)
-/* not verified */ #define SOUND_OBJ_SNOW_SAND1 SOUND_ARG_LOAD(5, 0, 0x2A, 0x00, 8)
-/* not verified */ #define SOUND_OBJ_SNOW_SAND2 SOUND_ARG_LOAD(5, 0, 0x2B, 0x00, 8)
+/* not verified */
+#define SOUND_OBJ_SOMETHING_LANDING SOUND_ARG_LOAD(5, 0, 0x28, 0x80, 8)
+/* not verified */
+#define SOUND_OBJ_DIVING_IN_WATER SOUND_ARG_LOAD(5, 0, 0x29, 0xA0, 8)
+/* not verified */
+#define SOUND_OBJ_SNOW_SAND1 SOUND_ARG_LOAD(5, 0, 0x2A, 0x00, 8)
+/* not verified */
+#define SOUND_OBJ_SNOW_SAND2 SOUND_ARG_LOAD(5, 0, 0x2B, 0x00, 8)
#define SOUND_OBJ_DEFAULT_DEATH SOUND_ARG_LOAD(5, 0, 0x2C, 0x80, 8)
#define SOUND_OBJ_BIG_PENGUIN_YELL SOUND_ARG_LOAD(5, 0, 0x2D, 0x00, 8)
#define SOUND_OBJ_WATER_BOMB_BOUNCING SOUND_ARG_LOAD(5, 0, 0x2E, 0x80, 8)
#define SOUND_OBJ_GOOMBA_ALERT SOUND_ARG_LOAD(5, 0, 0x2F, 0x00, 8)
#define SOUND_OBJ_WIGGLER_JUMP SOUND_ARG_LOAD(5, 0, 0x2F, 0x60, 8)
-/* not verified */ #define SOUND_OBJ_STOMPED SOUND_ARG_LOAD(5, 0, 0x30, 0x80, 8)
-/* not verified */ #define SOUND_OBJ_UNKNOWN6 SOUND_ARG_LOAD(5, 0, 0x31, 0x00, 8)
-/* not verified */ #define SOUND_OBJ_DIVING_INTO_WATER SOUND_ARG_LOAD(5, 0, 0x32, 0x40, 8)
+/* not verified */
+#define SOUND_OBJ_STOMPED SOUND_ARG_LOAD(5, 0, 0x30, 0x80, 8)
+/* not verified */
+#define SOUND_OBJ_UNKNOWN6 SOUND_ARG_LOAD(5, 0, 0x31, 0x00, 8)
+/* not verified */
+#define SOUND_OBJ_DIVING_INTO_WATER SOUND_ARG_LOAD(5, 0, 0x32, 0x40, 8)
#define SOUND_OBJ_PIRANHA_PLANT_SHRINK SOUND_ARG_LOAD(5, 0, 0x33, 0x40, 8)
#define SOUND_OBJ_KOOPA_THE_QUICK_WALK SOUND_ARG_LOAD(5, 0, 0x34, 0x20, 8)
#define SOUND_OBJ_KOOPA_WALK SOUND_ARG_LOAD(5, 0, 0x35, 0x00, 8)
@@ -451,39 +639,52 @@
#define SOUND_OBJ_UKIKI_STEP_LEAVES SOUND_ARG_LOAD(5, 0, 0x3C, 0x00, 8)
#define SOUND_OBJ_KOOPA_TALK SOUND_ARG_LOAD(5, 0, 0x3D, 0xA0, 8)
#define SOUND_OBJ_KOOPA_DAMAGE SOUND_ARG_LOAD(5, 0, 0x3E, 0xA0, 8)
-/* not verified */ #define SOUND_OBJ_KLEPTO1 SOUND_ARG_LOAD(5, 0, 0x3F, 0x40, 8)
-/* not verified */ #define SOUND_OBJ_KLEPTO2 SOUND_ARG_LOAD(5, 0, 0x40, 0x60, 8)
+/* not verified */
+#define SOUND_OBJ_KLEPTO1 SOUND_ARG_LOAD(5, 0, 0x3F, 0x40, 8)
+/* not verified */
+#define SOUND_OBJ_KLEPTO2 SOUND_ARG_LOAD(5, 0, 0x40, 0x60, 8)
#define SOUND_OBJ_KING_BOBOMB_TALK SOUND_ARG_LOAD(5, 0, 0x41, 0x00, 8)
#define SOUND_OBJ_KING_BOBOMB_JUMP SOUND_ARG_LOAD(5, 0, 0x46, 0x80, 8)
#define SOUND_OBJ_KING_WHOMP_DEATH SOUND_ARG_LOAD(5, 1, 0x47, 0xC0, 8)
#define SOUND_OBJ_BOO_LAUGH_LONG SOUND_ARG_LOAD(5, 0, 0x48, 0x00, 8)
-/* not verified */ #define SOUND_OBJ_EEL SOUND_ARG_LOAD(5, 0, 0x4A, 0x00, 8)
-/* not verified */ #define SOUND_OBJ_EEL_2 SOUND_ARG_LOAD(5, 2, 0x4A, 0x00, 8)
+/* not verified */
+#define SOUND_OBJ_EEL SOUND_ARG_LOAD(5, 0, 0x4A, 0x00, 8)
+/* not verified */
+#define SOUND_OBJ_EEL_2 SOUND_ARG_LOAD(5, 2, 0x4A, 0x00, 8)
#define SOUND_OBJ_EYEROK_SHOW_EYE SOUND_ARG_LOAD(5, 2, 0x4B, 0x00, 8)
#define SOUND_OBJ_MR_BLIZZARD_ALERT SOUND_ARG_LOAD(5, 0, 0x4C, 0x00, 8)
#define SOUND_OBJ_SNUFIT_SHOOT SOUND_ARG_LOAD(5, 0, 0x4D, 0x00, 8)
#define SOUND_OBJ_SKEETER_WALK SOUND_ARG_LOAD(5, 0, 0x4E, 0x00, 8)
-/* not verified */ #define SOUND_OBJ_WALKING_WATER SOUND_ARG_LOAD(5, 0, 0x4F, 0x00, 8)
+/* not verified */
+#define SOUND_OBJ_WALKING_WATER SOUND_ARG_LOAD(5, 0, 0x4F, 0x00, 8)
#define SOUND_OBJ_BIRD_CHIRP3 SOUND_ARG_LOAD(5, 0, 0x51, 0x40, 0)
#define SOUND_OBJ_PIRANHA_PLANT_APPEAR SOUND_ARG_LOAD(5, 0, 0x54, 0x20, 8)
#define SOUND_OBJ_FLAME_BLOWN SOUND_ARG_LOAD(5, 0, 0x55, 0x80, 8)
#define SOUND_OBJ_MAD_PIANO_CHOMPING SOUND_ARG_LOAD(5, 2, 0x56, 0x40, 8)
#define SOUND_OBJ_BOBOMB_BUDDY_TALK SOUND_ARG_LOAD(5, 0, 0x58, 0x40, 8)
-/* not verified */ #define SOUND_OBJ_SPINY_UNK59 SOUND_ARG_LOAD(5, 0, 0x59, 0x10, 8)
+/* not verified */
+#define SOUND_OBJ_SPINY_UNK59 SOUND_ARG_LOAD(5, 0, 0x59, 0x10, 8)
#define SOUND_OBJ_WIGGLER_HIGH_PITCH SOUND_ARG_LOAD(5, 0, 0x5C, 0x40, 8)
#define SOUND_OBJ_HEAVEHO_TOSSED SOUND_ARG_LOAD(5, 0, 0x5D, 0x40, 8)
-/* not verified */ #define SOUND_OBJ_WIGGLER_DEATH 0x505E
+/* not verified */
+#define SOUND_OBJ_WIGGLER_DEATH 0x505E
#define SOUND_OBJ_BOWSER_INTRO_LAUGH SOUND_ARG_LOAD(5, 0, 0x5F, 0x80, 9)
-/* not verified */ #define SOUND_OBJ_ENEMY_DEATH_HIGH SOUND_ARG_LOAD(5, 0, 0x60, 0xB0, 8)
-/* not verified */ #define SOUND_OBJ_ENEMY_DEATH_LOW SOUND_ARG_LOAD(5, 0, 0x61, 0xB0, 8)
+/* not verified */
+#define SOUND_OBJ_ENEMY_DEATH_HIGH SOUND_ARG_LOAD(5, 0, 0x60, 0xB0, 8)
+/* not verified */
+#define SOUND_OBJ_ENEMY_DEATH_LOW SOUND_ARG_LOAD(5, 0, 0x61, 0xB0, 8)
#define SOUND_OBJ_SWOOP_DEATH SOUND_ARG_LOAD(5, 0, 0x62, 0xB0, 8)
#define SOUND_OBJ_KOOPA_FLYGUY_DEATH SOUND_ARG_LOAD(5, 0, 0x63, 0xB0, 8)
#define SOUND_OBJ_POKEY_DEATH SOUND_ARG_LOAD(5, 0, 0x63, 0xC0, 8)
-/* not verified */ #define SOUND_OBJ_SNOWMAN_BOUNCE SOUND_ARG_LOAD(5, 0, 0x64, 0xC0, 8)
+/* not verified */
+#define SOUND_OBJ_SNOWMAN_BOUNCE SOUND_ARG_LOAD(5, 0, 0x64, 0xC0, 8)
#define SOUND_OBJ_SNOWMAN_EXPLODE SOUND_ARG_LOAD(5, 0, 0x65, 0xD0, 8)
-/* not verified */ #define SOUND_OBJ_POUNDING_LOUD SOUND_ARG_LOAD(5, 0, 0x68, 0x40, 8)
-/* not verified */ #define SOUND_OBJ_MIPS_RABBIT SOUND_ARG_LOAD(5, 0, 0x6A, 0x00, 8)
-/* not verified */ #define SOUND_OBJ_MIPS_RABBIT_WATER SOUND_ARG_LOAD(5, 0, 0x6C, 0x00, 8)
+/* not verified */
+#define SOUND_OBJ_POUNDING_LOUD SOUND_ARG_LOAD(5, 0, 0x68, 0x40, 8)
+/* not verified */
+#define SOUND_OBJ_MIPS_RABBIT SOUND_ARG_LOAD(5, 0, 0x6A, 0x00, 8)
+/* not verified */
+#define SOUND_OBJ_MIPS_RABBIT_WATER SOUND_ARG_LOAD(5, 0, 0x6C, 0x00, 8)
#define SOUND_OBJ_EYEROK_EXPLODE SOUND_ARG_LOAD(5, 0, 0x6D, 0x00, 8)
#define SOUND_OBJ_CHUCKYA_DEATH SOUND_ARG_LOAD(5, 1, 0x6E, 0x00, 8)
#define SOUND_OBJ_WIGGLER_TALK SOUND_ARG_LOAD(5, 0, 0x6F, 0x00, 8)
@@ -511,7 +712,8 @@
/* Menu Sound Effects */
#define SOUND_MENU_CHANGE_SELECT SOUND_ARG_LOAD(7, 0, 0x00, 0xF8, 8)
-/* not verified */ #define SOUND_MENU_REVERSE_PAUSE 0x7001
+/* not verified */
+#define SOUND_MENU_REVERSE_PAUSE 0x7001
#define SOUND_MENU_PAUSE SOUND_ARG_LOAD(7, 0, 0x02, 0xF0, 8)
#define SOUND_MENU_PAUSE_HIGHPRIO SOUND_ARG_LOAD(7, 0, 0x02, 0xFF, 8)
#define SOUND_MENU_PAUSE_2 SOUND_ARG_LOAD(7, 0, 0x03, 0xFF, 8)
@@ -523,28 +725,39 @@
#define SOUND_MENU_LET_GO_MARIO_FACE SOUND_ARG_LOAD(7, 0, 0x09, 0x00, 8)
#define SOUND_MENU_HAND_APPEAR SOUND_ARG_LOAD(7, 0, 0x0A, 0x00, 8)
#define SOUND_MENU_HAND_DISAPPEAR SOUND_ARG_LOAD(7, 0, 0x0B, 0x00, 8)
-/* not verified */ #define SOUND_MENU_UNK0C SOUND_ARG_LOAD(7, 0, 0x0C, 0x00, 8)
-/* not verified */ #define SOUND_MENU_POWER_METER SOUND_ARG_LOAD(7, 0, 0x0D, 0x00, 8)
+/* not verified */
+#define SOUND_MENU_UNK0C SOUND_ARG_LOAD(7, 0, 0x0C, 0x00, 8)
+/* not verified */
+#define SOUND_MENU_POWER_METER SOUND_ARG_LOAD(7, 0, 0x0D, 0x00, 8)
#define SOUND_MENU_CAMERA_BUZZ SOUND_ARG_LOAD(7, 0, 0x0E, 0x00, 8)
#define SOUND_MENU_CAMERA_TURN SOUND_ARG_LOAD(7, 0, 0x0F, 0x00, 8)
-/* not verified */ #define SOUND_MENU_UNK10 0x7010
+/* not verified */
+#define SOUND_MENU_UNK10 0x7010
#define SOUND_MENU_CLICK_FILE_SELECT SOUND_ARG_LOAD(7, 0, 0x11, 0x00, 8)
-/* not verified */ #define SOUND_MENU_MESSAGE_NEXT_PAGE SOUND_ARG_LOAD(7, 0, 0x13, 0x00, 8)
+/* not verified */
+#define SOUND_MENU_MESSAGE_NEXT_PAGE SOUND_ARG_LOAD(7, 0, 0x13, 0x00, 8)
#define SOUND_MENU_COIN_ITS_A_ME_MARIO SOUND_ARG_LOAD(7, 0, 0x14, 0x00, 8)
#define SOUND_MENU_YOSHI_GAIN_LIVES SOUND_ARG_LOAD(7, 0, 0x15, 0x00, 8)
#define SOUND_MENU_ENTER_PIPE SOUND_ARG_LOAD(7, 0, 0x16, 0xA0, 8)
#define SOUND_MENU_EXIT_PIPE SOUND_ARG_LOAD(7, 0, 0x17, 0xA0, 8)
#define SOUND_MENU_BOWSER_LAUGH SOUND_ARG_LOAD(7, 0, 0x18, 0x80, 8)
#define SOUND_MENU_ENTER_HOLE SOUND_ARG_LOAD(7, 1, 0x19, 0x80, 8)
-/* not verified */ #define SOUND_MENU_CLICK_CHANGE_VIEW SOUND_ARG_LOAD(7, 0, 0x1A, 0x80, 8)
-/* not verified */ #define SOUND_MENU_CAMERA_UNUSED1 0x701B
-/* not verified */ #define SOUND_MENU_CAMERA_UNUSED2 0x701C
-/* not verified */ #define SOUND_MENU_MARIO_CASTLE_WARP SOUND_ARG_LOAD(7, 0, 0x1D, 0xB0, 8)
+/* not verified */
+#define SOUND_MENU_CLICK_CHANGE_VIEW SOUND_ARG_LOAD(7, 0, 0x1A, 0x80, 8)
+/* not verified */
+#define SOUND_MENU_CAMERA_UNUSED1 0x701B
+/* not verified */
+#define SOUND_MENU_CAMERA_UNUSED2 0x701C
+/* not verified */
+#define SOUND_MENU_MARIO_CASTLE_WARP SOUND_ARG_LOAD(7, 0, 0x1D, 0xB0, 8)
#define SOUND_MENU_STAR_SOUND SOUND_ARG_LOAD(7, 0, 0x1E, 0xFF, 8)
#define SOUND_MENU_THANK_YOU_PLAYING_MY_GAME SOUND_ARG_LOAD(7, 0, 0x1F, 0xFF, 8)
-/* not verified */ #define SOUND_MENU_READ_A_SIGN 0x7020
-/* not verified */ #define SOUND_MENU_EXIT_A_SIGN 0x7021
-/* not verified */ #define SOUND_MENU_MARIO_CASTLE_WARP2 SOUND_ARG_LOAD(7, 0, 0x22, 0x20, 8)
+/* not verified */
+#define SOUND_MENU_READ_A_SIGN 0x7020
+/* not verified */
+#define SOUND_MENU_EXIT_A_SIGN 0x7021
+/* not verified */
+#define SOUND_MENU_MARIO_CASTLE_WARP2 SOUND_ARG_LOAD(7, 0, 0x22, 0x20, 8)
#define SOUND_MENU_STAR_SOUND_OKEY_DOKEY SOUND_ARG_LOAD(7, 0, 0x23, 0xFF, 8)
#define SOUND_MENU_STAR_SOUND_LETS_A_GO SOUND_ARG_LOAD(7, 0, 0x24, 0xFF, 8)
diff --git a/src/decomp/include/mario_animation_ids.h b/src/decomp/include/mario_animation_ids.h
index 1d22d3d..efbc864 100644
--- a/src/decomp/include/mario_animation_ids.h
+++ b/src/decomp/include/mario_animation_ids.h
@@ -5,215 +5,436 @@
enum MarioAnimID
{
- /* 0x00 */ MARIO_ANIM_SLOW_LEDGE_GRAB,
- /* 0x01 */ MARIO_ANIM_FALL_OVER_BACKWARDS,
- /* 0x02 */ MARIO_ANIM_BACKWARD_AIR_KB,
- /* 0x03 */ MARIO_ANIM_DYING_ON_BACK,
- /* 0x04 */ MARIO_ANIM_BACKFLIP,
- /* 0x05 */ MARIO_ANIM_CLIMB_UP_POLE,
- /* 0x06 */ MARIO_ANIM_GRAB_POLE_SHORT,
- /* 0x07 */ MARIO_ANIM_GRAB_POLE_SWING_PART1,
- /* 0x08 */ MARIO_ANIM_GRAB_POLE_SWING_PART2,
- /* 0x09 */ MARIO_ANIM_HANDSTAND_IDLE,
- /* 0x0A */ MARIO_ANIM_HANDSTAND_JUMP,
- /* 0x0B */ MARIO_ANIM_START_HANDSTAND,
- /* 0x0C */ MARIO_ANIM_RETURN_FROM_HANDSTAND,
- /* 0x0D */ MARIO_ANIM_IDLE_ON_POLE,
- /* 0x0E */ MARIO_ANIM_A_POSE,
- /* 0x0F */ MARIO_ANIM_SKID_ON_GROUND,
- /* 0x10 */ MARIO_ANIM_STOP_SKID,
- /* 0x11 */ MARIO_ANIM_CROUCH_FROM_FAST_LONGJUMP,
- /* 0x12 */ MARIO_ANIM_CROUCH_FROM_SLOW_LONGJUMP,
- /* 0x13 */ MARIO_ANIM_FAST_LONGJUMP,
- /* 0x14 */ MARIO_ANIM_SLOW_LONGJUMP,
- /* 0x15 */ MARIO_ANIM_AIRBORNE_ON_STOMACH,
- /* 0x16 */ MARIO_ANIM_WALK_WITH_LIGHT_OBJ,
- /* 0x17 */ MARIO_ANIM_RUN_WITH_LIGHT_OBJ,
- /* 0x18 */ MARIO_ANIM_SLOW_WALK_WITH_LIGHT_OBJ,
- /* 0x19 */ MARIO_ANIM_SHIVERING_WARMING_HAND,
- /* 0x1A */ MARIO_ANIM_SHIVERING_RETURN_TO_IDLE,
- /* 0x1B */ MARIO_ANIM_SHIVERING,
- /* 0x1C */ MARIO_ANIM_CLIMB_DOWN_LEDGE,
- /* 0x1D */ MARIO_ANIM_CREDITS_WAVING,
- /* 0x1E */ MARIO_ANIM_CREDITS_LOOK_UP,
- /* 0x1F */ MARIO_ANIM_CREDITS_RETURN_FROM_LOOK_UP,
- /* 0x20 */ MARIO_ANIM_CREDITS_RAISE_HAND,
- /* 0x21 */ MARIO_ANIM_CREDITS_LOWER_HAND,
- /* 0x22 */ MARIO_ANIM_CREDITS_TAKE_OFF_CAP,
- /* 0x23 */ MARIO_ANIM_CREDITS_START_WALK_LOOK_UP,
- /* 0x24 */ MARIO_ANIM_CREDITS_LOOK_BACK_THEN_RUN,
- /* 0x25 */ MARIO_ANIM_FINAL_BOWSER_RAISE_HAND_SPIN,
- /* 0x26 */ MARIO_ANIM_FINAL_BOWSER_WING_CAP_TAKE_OFF,
- /* 0x27 */ MARIO_ANIM_CREDITS_PEACE_SIGN,
- /* 0x28 */ MARIO_ANIM_STAND_UP_FROM_LAVA_BOOST,
- /* 0x29 */ MARIO_ANIM_FIRE_LAVA_BURN,
- /* 0x2A */ MARIO_ANIM_WING_CAP_FLY,
- /* 0x2B */ MARIO_ANIM_HANG_ON_OWL,
- /* 0x2C */ MARIO_ANIM_LAND_ON_STOMACH,
- /* 0x2D */ MARIO_ANIM_AIR_FORWARD_KB,
- /* 0x2E */ MARIO_ANIM_DYING_ON_STOMACH,
- /* 0x2F */ MARIO_ANIM_SUFFOCATING,
- /* 0x30 */ MARIO_ANIM_COUGHING,
- /* 0x31 */ MARIO_ANIM_THROW_CATCH_KEY,
- /* 0x32 */ MARIO_ANIM_DYING_FALL_OVER,
- /* 0x33 */ MARIO_ANIM_IDLE_ON_LEDGE,
- /* 0x34 */ MARIO_ANIM_FAST_LEDGE_GRAB,
- /* 0x35 */ MARIO_ANIM_HANG_ON_CEILING,
- /* 0x36 */ MARIO_ANIM_PUT_CAP_ON,
- /* 0x37 */ MARIO_ANIM_TAKE_CAP_OFF_THEN_ON,
- /* 0x38 */ MARIO_ANIM_QUICKLY_PUT_CAP_ON, // unused
- /* 0x39 */ MARIO_ANIM_HEAD_STUCK_IN_GROUND,
- /* 0x3A */ MARIO_ANIM_GROUND_POUND_LANDING,
- /* 0x3B */ MARIO_ANIM_TRIPLE_JUMP_GROUND_POUND,
- /* 0x3C */ MARIO_ANIM_START_GROUND_POUND,
- /* 0x3D */ MARIO_ANIM_GROUND_POUND,
- /* 0x3E */ MARIO_ANIM_BOTTOM_STUCK_IN_GROUND,
- /* 0x3F */ MARIO_ANIM_IDLE_WITH_LIGHT_OBJ,
- /* 0x40 */ MARIO_ANIM_JUMP_LAND_WITH_LIGHT_OBJ,
- /* 0x41 */ MARIO_ANIM_JUMP_WITH_LIGHT_OBJ,
- /* 0x42 */ MARIO_ANIM_FALL_LAND_WITH_LIGHT_OBJ,
- /* 0x43 */ MARIO_ANIM_FALL_WITH_LIGHT_OBJ,
- /* 0x44 */ MARIO_ANIM_FALL_FROM_SLIDING_WITH_LIGHT_OBJ,
- /* 0x45 */ MARIO_ANIM_SLIDING_ON_BOTTOM_WITH_LIGHT_OBJ,
- /* 0x46 */ MARIO_ANIM_STAND_UP_FROM_SLIDING_WITH_LIGHT_OBJ,
- /* 0x47 */ MARIO_ANIM_RIDING_SHELL,
- /* 0x48 */ MARIO_ANIM_WALKING,
- /* 0x49 */ MARIO_ANIM_FORWARD_FLIP, // unused
- /* 0x4A */ MARIO_ANIM_JUMP_RIDING_SHELL,
- /* 0x4B */ MARIO_ANIM_LAND_FROM_DOUBLE_JUMP,
- /* 0x4C */ MARIO_ANIM_DOUBLE_JUMP_FALL,
- /* 0x4D */ MARIO_ANIM_SINGLE_JUMP,
- /* 0x4E */ MARIO_ANIM_LAND_FROM_SINGLE_JUMP,
- /* 0x4F */ MARIO_ANIM_AIR_KICK,
- /* 0x50 */ MARIO_ANIM_DOUBLE_JUMP_RISE,
- /* 0x51 */ MARIO_ANIM_START_FORWARD_SPINNING, // unused
- /* 0x52 */ MARIO_ANIM_THROW_LIGHT_OBJECT,
- /* 0x53 */ MARIO_ANIM_FALL_FROM_SLIDE_KICK,
- /* 0x54 */ MARIO_ANIM_BEND_KNESS_RIDING_SHELL, // unused
- /* 0x55 */ MARIO_ANIM_LEGS_STUCK_IN_GROUND,
- /* 0x56 */ MARIO_ANIM_GENERAL_FALL,
- /* 0x57 */ MARIO_ANIM_GENERAL_LAND,
- /* 0x58 */ MARIO_ANIM_BEING_GRABBED,
- /* 0x59 */ MARIO_ANIM_GRAB_HEAVY_OBJECT,
- /* 0x5A */ MARIO_ANIM_SLOW_LAND_FROM_DIVE,
- /* 0x5B */ MARIO_ANIM_FLY_FROM_CANNON,
- /* 0x5C */ MARIO_ANIM_MOVE_ON_WIRE_NET_RIGHT,
- /* 0x5D */ MARIO_ANIM_MOVE_ON_WIRE_NET_LEFT,
- /* 0x5E */ MARIO_ANIM_MISSING_CAP,
- /* 0x5F */ MARIO_ANIM_PULL_DOOR_WALK_IN,
- /* 0x60 */ MARIO_ANIM_PUSH_DOOR_WALK_IN,
- /* 0x61 */ MARIO_ANIM_UNLOCK_DOOR,
- /* 0x62 */ MARIO_ANIM_START_REACH_POCKET, // unused, reaching keys maybe?
- /* 0x63 */ MARIO_ANIM_REACH_POCKET, // unused
- /* 0x64 */ MARIO_ANIM_STOP_REACH_POCKET, // unused
- /* 0x65 */ MARIO_ANIM_GROUND_THROW,
- /* 0x66 */ MARIO_ANIM_GROUND_KICK,
- /* 0x67 */ MARIO_ANIM_FIRST_PUNCH,
- /* 0x68 */ MARIO_ANIM_SECOND_PUNCH,
- /* 0x69 */ MARIO_ANIM_FIRST_PUNCH_FAST,
- /* 0x6A */ MARIO_ANIM_SECOND_PUNCH_FAST,
- /* 0x6B */ MARIO_ANIM_PICK_UP_LIGHT_OBJ,
- /* 0x6C */ MARIO_ANIM_PUSHING,
- /* 0x6D */ MARIO_ANIM_START_RIDING_SHELL,
- /* 0x6E */ MARIO_ANIM_PLACE_LIGHT_OBJ,
- /* 0x6F */ MARIO_ANIM_FORWARD_SPINNING,
- /* 0x70 */ MARIO_ANIM_BACKWARD_SPINNING,
- /* 0x71 */ MARIO_ANIM_BREAKDANCE,
- /* 0x72 */ MARIO_ANIM_RUNNING,
- /* 0x73 */ MARIO_ANIM_RUNNING_UNUSED, // unused duplicate, originally part 2?
- /* 0x74 */ MARIO_ANIM_SOFT_BACK_KB,
- /* 0x75 */ MARIO_ANIM_SOFT_FRONT_KB,
- /* 0x76 */ MARIO_ANIM_DYING_IN_QUICKSAND,
- /* 0x77 */ MARIO_ANIM_IDLE_IN_QUICKSAND,
- /* 0x78 */ MARIO_ANIM_MOVE_IN_QUICKSAND,
- /* 0x79 */ MARIO_ANIM_ELECTROCUTION,
- /* 0x7A */ MARIO_ANIM_SHOCKED,
- /* 0x7B */ MARIO_ANIM_BACKWARD_KB,
- /* 0x7C */ MARIO_ANIM_FORWARD_KB,
- /* 0x7D */ MARIO_ANIM_IDLE_HEAVY_OBJ,
- /* 0x7E */ MARIO_ANIM_STAND_AGAINST_WALL,
- /* 0x7F */ MARIO_ANIM_SIDESTEP_LEFT,
- /* 0x80 */ MARIO_ANIM_SIDESTEP_RIGHT,
- /* 0x81 */ MARIO_ANIM_START_SLEEP_IDLE,
- /* 0x82 */ MARIO_ANIM_START_SLEEP_SCRATCH,
- /* 0x83 */ MARIO_ANIM_START_SLEEP_YAWN,
- /* 0x84 */ MARIO_ANIM_START_SLEEP_SITTING,
- /* 0x85 */ MARIO_ANIM_SLEEP_IDLE,
- /* 0x86 */ MARIO_ANIM_SLEEP_START_LYING,
- /* 0x87 */ MARIO_ANIM_SLEEP_LYING,
- /* 0x88 */ MARIO_ANIM_DIVE,
- /* 0x89 */ MARIO_ANIM_SLIDE_DIVE,
- /* 0x8A */ MARIO_ANIM_GROUND_BONK,
- /* 0x8B */ MARIO_ANIM_STOP_SLIDE_LIGHT_OBJ,
- /* 0x8C */ MARIO_ANIM_SLIDE_KICK,
- /* 0x8D */ MARIO_ANIM_CROUCH_FROM_SLIDE_KICK,
- /* 0x8E */ MARIO_ANIM_SLIDE_MOTIONLESS, // unused
- /* 0x8F */ MARIO_ANIM_STOP_SLIDE,
- /* 0x90 */ MARIO_ANIM_FALL_FROM_SLIDE,
- /* 0x91 */ MARIO_ANIM_SLIDE,
- /* 0x92 */ MARIO_ANIM_TIPTOE,
- /* 0x93 */ MARIO_ANIM_TWIRL_LAND,
- /* 0x94 */ MARIO_ANIM_TWIRL,
- /* 0x95 */ MARIO_ANIM_START_TWIRL,
- /* 0x96 */ MARIO_ANIM_STOP_CROUCHING,
- /* 0x97 */ MARIO_ANIM_START_CROUCHING,
- /* 0x98 */ MARIO_ANIM_CROUCHING,
- /* 0x99 */ MARIO_ANIM_CRAWLING,
- /* 0x9A */ MARIO_ANIM_STOP_CRAWLING,
- /* 0x9B */ MARIO_ANIM_START_CRAWLING,
- /* 0x9C */ MARIO_ANIM_SUMMON_STAR,
- /* 0x9D */ MARIO_ANIM_RETURN_STAR_APPROACH_DOOR,
- /* 0x9E */ MARIO_ANIM_BACKWARDS_WATER_KB,
- /* 0x9F */ MARIO_ANIM_SWIM_WITH_OBJ_PART1,
- /* 0xA0 */ MARIO_ANIM_SWIM_WITH_OBJ_PART2,
- /* 0xA1 */ MARIO_ANIM_FLUTTERKICK_WITH_OBJ,
- /* 0xA2 */ MARIO_ANIM_WATER_ACTION_END_WITH_OBJ, // either swimming or flutterkicking
- /* 0xA3 */ MARIO_ANIM_STOP_GRAB_OBJ_WATER,
- /* 0xA4 */ MARIO_ANIM_WATER_IDLE_WITH_OBJ,
- /* 0xA5 */ MARIO_ANIM_DROWNING_PART1,
- /* 0xA6 */ MARIO_ANIM_DROWNING_PART2,
- /* 0xA7 */ MARIO_ANIM_WATER_DYING,
- /* 0xA8 */ MARIO_ANIM_WATER_FORWARD_KB,
- /* 0xA9 */ MARIO_ANIM_FALL_FROM_WATER,
- /* 0xAA */ MARIO_ANIM_SWIM_PART1,
- /* 0xAB */ MARIO_ANIM_SWIM_PART2,
- /* 0xAC */ MARIO_ANIM_FLUTTERKICK,
- /* 0xAD */ MARIO_ANIM_WATER_ACTION_END, // either swimming or flutterkicking
- /* 0xAE */ MARIO_ANIM_WATER_PICK_UP_OBJ,
- /* 0xAF */ MARIO_ANIM_WATER_GRAB_OBJ_PART2,
- /* 0xB0 */ MARIO_ANIM_WATER_GRAB_OBJ_PART1,
- /* 0xB1 */ MARIO_ANIM_WATER_THROW_OBJ,
- /* 0xB2 */ MARIO_ANIM_WATER_IDLE,
- /* 0xB3 */ MARIO_ANIM_WATER_STAR_DANCE,
- /* 0xB4 */ MARIO_ANIM_RETURN_FROM_WATER_STAR_DANCE,
- /* 0xB5 */ MARIO_ANIM_GRAB_BOWSER,
- /* 0xB6 */ MARIO_ANIM_SWINGING_BOWSER,
- /* 0xB7 */ MARIO_ANIM_RELEASE_BOWSER,
- /* 0xB8 */ MARIO_ANIM_HOLDING_BOWSER,
- /* 0xB9 */ MARIO_ANIM_HEAVY_THROW,
- /* 0xBA */ MARIO_ANIM_WALK_PANTING,
- /* 0xBB */ MARIO_ANIM_WALK_WITH_HEAVY_OBJ,
- /* 0xBC */ MARIO_ANIM_TURNING_PART1,
- /* 0xBD */ MARIO_ANIM_TURNING_PART2,
- /* 0xBE */ MARIO_ANIM_SLIDEFLIP_LAND,
- /* 0XBF */ MARIO_ANIM_SLIDEFLIP,
- /* 0xC0 */ MARIO_ANIM_TRIPLE_JUMP_LAND,
- /* 0xC1 */ MARIO_ANIM_TRIPLE_JUMP,
- /* 0xC2 */ MARIO_ANIM_FIRST_PERSON,
- /* 0xC3 */ MARIO_ANIM_IDLE_HEAD_LEFT,
- /* 0xC4 */ MARIO_ANIM_IDLE_HEAD_RIGHT,
- /* 0xC5 */ MARIO_ANIM_IDLE_HEAD_CENTER,
- /* 0xC6 */ MARIO_ANIM_HANDSTAND_LEFT,
- /* 0xC7 */ MARIO_ANIM_HANDSTAND_RIGHT,
- /* 0xC8 */ MARIO_ANIM_WAKE_FROM_SLEEP,
- /* 0xC9 */ MARIO_ANIM_WAKE_FROM_LYING,
- /* 0xCA */ MARIO_ANIM_START_TIPTOE,
- /* 0xCB */ MARIO_ANIM_SLIDEJUMP, // pole jump and wall kick
- /* 0xCC */ MARIO_ANIM_START_WALLKICK,
- /* 0xCD */ MARIO_ANIM_STAR_DANCE,
- /* 0xCE */ MARIO_ANIM_RETURN_FROM_STAR_DANCE,
- /* 0xCF */ MARIO_ANIM_FORWARD_SPINNING_FLIP,
- /* 0xD0 */ MARIO_ANIM_TRIPLE_JUMP_FLY
+ /* 0x00 */
+ MARIO_ANIM_SLOW_LEDGE_GRAB,
+ /* 0x01 */
+ MARIO_ANIM_FALL_OVER_BACKWARDS,
+ /* 0x02 */
+ MARIO_ANIM_BACKWARD_AIR_KB,
+ /* 0x03 */
+ MARIO_ANIM_DYING_ON_BACK,
+ /* 0x04 */
+ MARIO_ANIM_BACKFLIP,
+ /* 0x05 */
+ MARIO_ANIM_CLIMB_UP_POLE,
+ /* 0x06 */
+ MARIO_ANIM_GRAB_POLE_SHORT,
+ /* 0x07 */
+ MARIO_ANIM_GRAB_POLE_SWING_PART1,
+ /* 0x08 */
+ MARIO_ANIM_GRAB_POLE_SWING_PART2,
+ /* 0x09 */
+ MARIO_ANIM_HANDSTAND_IDLE,
+ /* 0x0A */
+ MARIO_ANIM_HANDSTAND_JUMP,
+ /* 0x0B */
+ MARIO_ANIM_START_HANDSTAND,
+ /* 0x0C */
+ MARIO_ANIM_RETURN_FROM_HANDSTAND,
+ /* 0x0D */
+ MARIO_ANIM_IDLE_ON_POLE,
+ /* 0x0E */
+ MARIO_ANIM_A_POSE,
+ /* 0x0F */
+ MARIO_ANIM_SKID_ON_GROUND,
+ /* 0x10 */
+ MARIO_ANIM_STOP_SKID,
+ /* 0x11 */
+ MARIO_ANIM_CROUCH_FROM_FAST_LONGJUMP,
+ /* 0x12 */
+ MARIO_ANIM_CROUCH_FROM_SLOW_LONGJUMP,
+ /* 0x13 */
+ MARIO_ANIM_FAST_LONGJUMP,
+ /* 0x14 */
+ MARIO_ANIM_SLOW_LONGJUMP,
+ /* 0x15 */
+ MARIO_ANIM_AIRBORNE_ON_STOMACH,
+ /* 0x16 */
+ MARIO_ANIM_WALK_WITH_LIGHT_OBJ,
+ /* 0x17 */
+ MARIO_ANIM_RUN_WITH_LIGHT_OBJ,
+ /* 0x18 */
+ MARIO_ANIM_SLOW_WALK_WITH_LIGHT_OBJ,
+ /* 0x19 */
+ MARIO_ANIM_SHIVERING_WARMING_HAND,
+ /* 0x1A */
+ MARIO_ANIM_SHIVERING_RETURN_TO_IDLE,
+ /* 0x1B */
+ MARIO_ANIM_SHIVERING,
+ /* 0x1C */
+ MARIO_ANIM_CLIMB_DOWN_LEDGE,
+ /* 0x1D */
+ MARIO_ANIM_CREDITS_WAVING,
+ /* 0x1E */
+ MARIO_ANIM_CREDITS_LOOK_UP,
+ /* 0x1F */
+ MARIO_ANIM_CREDITS_RETURN_FROM_LOOK_UP,
+ /* 0x20 */
+ MARIO_ANIM_CREDITS_RAISE_HAND,
+ /* 0x21 */
+ MARIO_ANIM_CREDITS_LOWER_HAND,
+ /* 0x22 */
+ MARIO_ANIM_CREDITS_TAKE_OFF_CAP,
+ /* 0x23 */
+ MARIO_ANIM_CREDITS_START_WALK_LOOK_UP,
+ /* 0x24 */
+ MARIO_ANIM_CREDITS_LOOK_BACK_THEN_RUN,
+ /* 0x25 */
+ MARIO_ANIM_FINAL_BOWSER_RAISE_HAND_SPIN,
+ /* 0x26 */
+ MARIO_ANIM_FINAL_BOWSER_WING_CAP_TAKE_OFF,
+ /* 0x27 */
+ MARIO_ANIM_CREDITS_PEACE_SIGN,
+ /* 0x28 */
+ MARIO_ANIM_STAND_UP_FROM_LAVA_BOOST,
+ /* 0x29 */
+ MARIO_ANIM_FIRE_LAVA_BURN,
+ /* 0x2A */
+ MARIO_ANIM_WING_CAP_FLY,
+ /* 0x2B */
+ MARIO_ANIM_HANG_ON_OWL,
+ /* 0x2C */
+ MARIO_ANIM_LAND_ON_STOMACH,
+ /* 0x2D */
+ MARIO_ANIM_AIR_FORWARD_KB,
+ /* 0x2E */
+ MARIO_ANIM_DYING_ON_STOMACH,
+ /* 0x2F */
+ MARIO_ANIM_SUFFOCATING,
+ /* 0x30 */
+ MARIO_ANIM_COUGHING,
+ /* 0x31 */
+ MARIO_ANIM_THROW_CATCH_KEY,
+ /* 0x32 */
+ MARIO_ANIM_DYING_FALL_OVER,
+ /* 0x33 */
+ MARIO_ANIM_IDLE_ON_LEDGE,
+ /* 0x34 */
+ MARIO_ANIM_FAST_LEDGE_GRAB,
+ /* 0x35 */
+ MARIO_ANIM_HANG_ON_CEILING,
+ /* 0x36 */
+ MARIO_ANIM_PUT_CAP_ON,
+ /* 0x37 */
+ MARIO_ANIM_TAKE_CAP_OFF_THEN_ON,
+ /* 0x38 */
+ MARIO_ANIM_QUICKLY_PUT_CAP_ON,
+ // unused
+ /* 0x39 */
+ MARIO_ANIM_HEAD_STUCK_IN_GROUND,
+ /* 0x3A */
+ MARIO_ANIM_GROUND_POUND_LANDING,
+ /* 0x3B */
+ MARIO_ANIM_TRIPLE_JUMP_GROUND_POUND,
+ /* 0x3C */
+ MARIO_ANIM_START_GROUND_POUND,
+ /* 0x3D */
+ MARIO_ANIM_GROUND_POUND,
+ /* 0x3E */
+ MARIO_ANIM_BOTTOM_STUCK_IN_GROUND,
+ /* 0x3F */
+ MARIO_ANIM_IDLE_WITH_LIGHT_OBJ,
+ /* 0x40 */
+ MARIO_ANIM_JUMP_LAND_WITH_LIGHT_OBJ,
+ /* 0x41 */
+ MARIO_ANIM_JUMP_WITH_LIGHT_OBJ,
+ /* 0x42 */
+ MARIO_ANIM_FALL_LAND_WITH_LIGHT_OBJ,
+ /* 0x43 */
+ MARIO_ANIM_FALL_WITH_LIGHT_OBJ,
+ /* 0x44 */
+ MARIO_ANIM_FALL_FROM_SLIDING_WITH_LIGHT_OBJ,
+ /* 0x45 */
+ MARIO_ANIM_SLIDING_ON_BOTTOM_WITH_LIGHT_OBJ,
+ /* 0x46 */
+ MARIO_ANIM_STAND_UP_FROM_SLIDING_WITH_LIGHT_OBJ,
+ /* 0x47 */
+ MARIO_ANIM_RIDING_SHELL,
+ /* 0x48 */
+ MARIO_ANIM_WALKING,
+ /* 0x49 */
+ MARIO_ANIM_FORWARD_FLIP,
+ // unused
+ /* 0x4A */
+ MARIO_ANIM_JUMP_RIDING_SHELL,
+ /* 0x4B */
+ MARIO_ANIM_LAND_FROM_DOUBLE_JUMP,
+ /* 0x4C */
+ MARIO_ANIM_DOUBLE_JUMP_FALL,
+ /* 0x4D */
+ MARIO_ANIM_SINGLE_JUMP,
+ /* 0x4E */
+ MARIO_ANIM_LAND_FROM_SINGLE_JUMP,
+ /* 0x4F */
+ MARIO_ANIM_AIR_KICK,
+ /* 0x50 */
+ MARIO_ANIM_DOUBLE_JUMP_RISE,
+ /* 0x51 */
+ MARIO_ANIM_START_FORWARD_SPINNING,
+ // unused
+ /* 0x52 */
+ MARIO_ANIM_THROW_LIGHT_OBJECT,
+ /* 0x53 */
+ MARIO_ANIM_FALL_FROM_SLIDE_KICK,
+ /* 0x54 */
+ MARIO_ANIM_BEND_KNESS_RIDING_SHELL,
+ // unused
+ /* 0x55 */
+ MARIO_ANIM_LEGS_STUCK_IN_GROUND,
+ /* 0x56 */
+ MARIO_ANIM_GENERAL_FALL,
+ /* 0x57 */
+ MARIO_ANIM_GENERAL_LAND,
+ /* 0x58 */
+ MARIO_ANIM_BEING_GRABBED,
+ /* 0x59 */
+ MARIO_ANIM_GRAB_HEAVY_OBJECT,
+ /* 0x5A */
+ MARIO_ANIM_SLOW_LAND_FROM_DIVE,
+ /* 0x5B */
+ MARIO_ANIM_FLY_FROM_CANNON,
+ /* 0x5C */
+ MARIO_ANIM_MOVE_ON_WIRE_NET_RIGHT,
+ /* 0x5D */
+ MARIO_ANIM_MOVE_ON_WIRE_NET_LEFT,
+ /* 0x5E */
+ MARIO_ANIM_MISSING_CAP,
+ /* 0x5F */
+ MARIO_ANIM_PULL_DOOR_WALK_IN,
+ /* 0x60 */
+ MARIO_ANIM_PUSH_DOOR_WALK_IN,
+ /* 0x61 */
+ MARIO_ANIM_UNLOCK_DOOR,
+ /* 0x62 */
+ MARIO_ANIM_START_REACH_POCKET,
+ // unused, reaching keys maybe?
+ /* 0x63 */
+ MARIO_ANIM_REACH_POCKET,
+ // unused
+ /* 0x64 */
+ MARIO_ANIM_STOP_REACH_POCKET,
+ // unused
+ /* 0x65 */
+ MARIO_ANIM_GROUND_THROW,
+ /* 0x66 */
+ MARIO_ANIM_GROUND_KICK,
+ /* 0x67 */
+ MARIO_ANIM_FIRST_PUNCH,
+ /* 0x68 */
+ MARIO_ANIM_SECOND_PUNCH,
+ /* 0x69 */
+ MARIO_ANIM_FIRST_PUNCH_FAST,
+ /* 0x6A */
+ MARIO_ANIM_SECOND_PUNCH_FAST,
+ /* 0x6B */
+ MARIO_ANIM_PICK_UP_LIGHT_OBJ,
+ /* 0x6C */
+ MARIO_ANIM_PUSHING,
+ /* 0x6D */
+ MARIO_ANIM_START_RIDING_SHELL,
+ /* 0x6E */
+ MARIO_ANIM_PLACE_LIGHT_OBJ,
+ /* 0x6F */
+ MARIO_ANIM_FORWARD_SPINNING,
+ /* 0x70 */
+ MARIO_ANIM_BACKWARD_SPINNING,
+ /* 0x71 */
+ MARIO_ANIM_BREAKDANCE,
+ /* 0x72 */
+ MARIO_ANIM_RUNNING,
+ /* 0x73 */
+ MARIO_ANIM_RUNNING_UNUSED,
+ // unused duplicate, originally part 2?
+ /* 0x74 */
+ MARIO_ANIM_SOFT_BACK_KB,
+ /* 0x75 */
+ MARIO_ANIM_SOFT_FRONT_KB,
+ /* 0x76 */
+ MARIO_ANIM_DYING_IN_QUICKSAND,
+ /* 0x77 */
+ MARIO_ANIM_IDLE_IN_QUICKSAND,
+ /* 0x78 */
+ MARIO_ANIM_MOVE_IN_QUICKSAND,
+ /* 0x79 */
+ MARIO_ANIM_ELECTROCUTION,
+ /* 0x7A */
+ MARIO_ANIM_SHOCKED,
+ /* 0x7B */
+ MARIO_ANIM_BACKWARD_KB,
+ /* 0x7C */
+ MARIO_ANIM_FORWARD_KB,
+ /* 0x7D */
+ MARIO_ANIM_IDLE_HEAVY_OBJ,
+ /* 0x7E */
+ MARIO_ANIM_STAND_AGAINST_WALL,
+ /* 0x7F */
+ MARIO_ANIM_SIDESTEP_LEFT,
+ /* 0x80 */
+ MARIO_ANIM_SIDESTEP_RIGHT,
+ /* 0x81 */
+ MARIO_ANIM_START_SLEEP_IDLE,
+ /* 0x82 */
+ MARIO_ANIM_START_SLEEP_SCRATCH,
+ /* 0x83 */
+ MARIO_ANIM_START_SLEEP_YAWN,
+ /* 0x84 */
+ MARIO_ANIM_START_SLEEP_SITTING,
+ /* 0x85 */
+ MARIO_ANIM_SLEEP_IDLE,
+ /* 0x86 */
+ MARIO_ANIM_SLEEP_START_LYING,
+ /* 0x87 */
+ MARIO_ANIM_SLEEP_LYING,
+ /* 0x88 */
+ MARIO_ANIM_DIVE,
+ /* 0x89 */
+ MARIO_ANIM_SLIDE_DIVE,
+ /* 0x8A */
+ MARIO_ANIM_GROUND_BONK,
+ /* 0x8B */
+ MARIO_ANIM_STOP_SLIDE_LIGHT_OBJ,
+ /* 0x8C */
+ MARIO_ANIM_SLIDE_KICK,
+ /* 0x8D */
+ MARIO_ANIM_CROUCH_FROM_SLIDE_KICK,
+ /* 0x8E */
+ MARIO_ANIM_SLIDE_MOTIONLESS,
+ // unused
+ /* 0x8F */
+ MARIO_ANIM_STOP_SLIDE,
+ /* 0x90 */
+ MARIO_ANIM_FALL_FROM_SLIDE,
+ /* 0x91 */
+ MARIO_ANIM_SLIDE,
+ /* 0x92 */
+ MARIO_ANIM_TIPTOE,
+ /* 0x93 */
+ MARIO_ANIM_TWIRL_LAND,
+ /* 0x94 */
+ MARIO_ANIM_TWIRL,
+ /* 0x95 */
+ MARIO_ANIM_START_TWIRL,
+ /* 0x96 */
+ MARIO_ANIM_STOP_CROUCHING,
+ /* 0x97 */
+ MARIO_ANIM_START_CROUCHING,
+ /* 0x98 */
+ MARIO_ANIM_CROUCHING,
+ /* 0x99 */
+ MARIO_ANIM_CRAWLING,
+ /* 0x9A */
+ MARIO_ANIM_STOP_CRAWLING,
+ /* 0x9B */
+ MARIO_ANIM_START_CRAWLING,
+ /* 0x9C */
+ MARIO_ANIM_SUMMON_STAR,
+ /* 0x9D */
+ MARIO_ANIM_RETURN_STAR_APPROACH_DOOR,
+ /* 0x9E */
+ MARIO_ANIM_BACKWARDS_WATER_KB,
+ /* 0x9F */
+ MARIO_ANIM_SWIM_WITH_OBJ_PART1,
+ /* 0xA0 */
+ MARIO_ANIM_SWIM_WITH_OBJ_PART2,
+ /* 0xA1 */
+ MARIO_ANIM_FLUTTERKICK_WITH_OBJ,
+ /* 0xA2 */
+ MARIO_ANIM_WATER_ACTION_END_WITH_OBJ,
+ // either swimming or flutterkicking
+ /* 0xA3 */
+ MARIO_ANIM_STOP_GRAB_OBJ_WATER,
+ /* 0xA4 */
+ MARIO_ANIM_WATER_IDLE_WITH_OBJ,
+ /* 0xA5 */
+ MARIO_ANIM_DROWNING_PART1,
+ /* 0xA6 */
+ MARIO_ANIM_DROWNING_PART2,
+ /* 0xA7 */
+ MARIO_ANIM_WATER_DYING,
+ /* 0xA8 */
+ MARIO_ANIM_WATER_FORWARD_KB,
+ /* 0xA9 */
+ MARIO_ANIM_FALL_FROM_WATER,
+ /* 0xAA */
+ MARIO_ANIM_SWIM_PART1,
+ /* 0xAB */
+ MARIO_ANIM_SWIM_PART2,
+ /* 0xAC */
+ MARIO_ANIM_FLUTTERKICK,
+ /* 0xAD */
+ MARIO_ANIM_WATER_ACTION_END,
+ // either swimming or flutterkicking
+ /* 0xAE */
+ MARIO_ANIM_WATER_PICK_UP_OBJ,
+ /* 0xAF */
+ MARIO_ANIM_WATER_GRAB_OBJ_PART2,
+ /* 0xB0 */
+ MARIO_ANIM_WATER_GRAB_OBJ_PART1,
+ /* 0xB1 */
+ MARIO_ANIM_WATER_THROW_OBJ,
+ /* 0xB2 */
+ MARIO_ANIM_WATER_IDLE,
+ /* 0xB3 */
+ MARIO_ANIM_WATER_STAR_DANCE,
+ /* 0xB4 */
+ MARIO_ANIM_RETURN_FROM_WATER_STAR_DANCE,
+ /* 0xB5 */
+ MARIO_ANIM_GRAB_BOWSER,
+ /* 0xB6 */
+ MARIO_ANIM_SWINGING_BOWSER,
+ /* 0xB7 */
+ MARIO_ANIM_RELEASE_BOWSER,
+ /* 0xB8 */
+ MARIO_ANIM_HOLDING_BOWSER,
+ /* 0xB9 */
+ MARIO_ANIM_HEAVY_THROW,
+ /* 0xBA */
+ MARIO_ANIM_WALK_PANTING,
+ /* 0xBB */
+ MARIO_ANIM_WALK_WITH_HEAVY_OBJ,
+ /* 0xBC */
+ MARIO_ANIM_TURNING_PART1,
+ /* 0xBD */
+ MARIO_ANIM_TURNING_PART2,
+ /* 0xBE */
+ MARIO_ANIM_SLIDEFLIP_LAND,
+ /* 0XBF */
+ MARIO_ANIM_SLIDEFLIP,
+ /* 0xC0 */
+ MARIO_ANIM_TRIPLE_JUMP_LAND,
+ /* 0xC1 */
+ MARIO_ANIM_TRIPLE_JUMP,
+ /* 0xC2 */
+ MARIO_ANIM_FIRST_PERSON,
+ /* 0xC3 */
+ MARIO_ANIM_IDLE_HEAD_LEFT,
+ /* 0xC4 */
+ MARIO_ANIM_IDLE_HEAD_RIGHT,
+ /* 0xC5 */
+ MARIO_ANIM_IDLE_HEAD_CENTER,
+ /* 0xC6 */
+ MARIO_ANIM_HANDSTAND_LEFT,
+ /* 0xC7 */
+ MARIO_ANIM_HANDSTAND_RIGHT,
+ /* 0xC8 */
+ MARIO_ANIM_WAKE_FROM_SLEEP,
+ /* 0xC9 */
+ MARIO_ANIM_WAKE_FROM_LYING,
+ /* 0xCA */
+ MARIO_ANIM_START_TIPTOE,
+ /* 0xCB */
+ MARIO_ANIM_SLIDEJUMP,
+ // pole jump and wall kick
+ /* 0xCC */
+ MARIO_ANIM_START_WALLKICK,
+ /* 0xCD */
+ MARIO_ANIM_STAR_DANCE,
+ /* 0xCE */
+ MARIO_ANIM_RETURN_FROM_STAR_DANCE,
+ /* 0xCF */
+ MARIO_ANIM_FORWARD_SPINNING_FLIP,
+ /* 0xD0 */
+ MARIO_ANIM_TRIPLE_JUMP_FLY
};
#endif // MARIO_ANIMATION_IDS_H
diff --git a/src/decomp/include/mario_geo_switch_case_ids.h b/src/decomp/include/mario_geo_switch_case_ids.h
index 007d23b..1437cdc 100644
--- a/src/decomp/include/mario_geo_switch_case_ids.h
+++ b/src/decomp/include/mario_geo_switch_case_ids.h
@@ -5,41 +5,68 @@
enum MarioEyesGSCId
{
- /*0x00*/ MARIO_EYES_BLINK,
- /*0x01*/ MARIO_EYES_OPEN,
- /*0x02*/ MARIO_EYES_HALF_CLOSED,
- /*0x03*/ MARIO_EYES_CLOSED,
- /*0x04*/ MARIO_EYES_LOOK_LEFT, // unused
- /*0x05*/ MARIO_EYES_LOOK_RIGHT, // unused
- /*0x06*/ MARIO_EYES_LOOK_UP, // unused
- /*0x07*/ MARIO_EYES_LOOK_DOWN, // unused
- /*0x08*/ MARIO_EYES_DEAD
+ /*0x00*/
+ MARIO_EYES_BLINK,
+ /*0x01*/
+ MARIO_EYES_OPEN,
+ /*0x02*/
+ MARIO_EYES_HALF_CLOSED,
+ /*0x03*/
+ MARIO_EYES_CLOSED,
+ /*0x04*/
+ MARIO_EYES_LOOK_LEFT,
+ // unused
+ /*0x05*/
+ MARIO_EYES_LOOK_RIGHT,
+ // unused
+ /*0x06*/
+ MARIO_EYES_LOOK_UP,
+ // unused
+ /*0x07*/
+ MARIO_EYES_LOOK_DOWN,
+ // unused
+ /*0x08*/
+ MARIO_EYES_DEAD
};
enum MarioHandGSCId
{
- /*0x00*/ MARIO_HAND_FISTS,
- /*0x01*/ MARIO_HAND_OPEN,
- /*0x02*/ MARIO_HAND_PEACE_SIGN,
- /*0x03*/ MARIO_HAND_HOLDING_CAP,
- /*0x04*/ MARIO_HAND_HOLDING_WING_CAP,
- /*0x05*/ MARIO_HAND_RIGHT_OPEN
+ /*0x00*/
+ MARIO_HAND_FISTS,
+ /*0x01*/
+ MARIO_HAND_OPEN,
+ /*0x02*/
+ MARIO_HAND_PEACE_SIGN,
+ /*0x03*/
+ MARIO_HAND_HOLDING_CAP,
+ /*0x04*/
+ MARIO_HAND_HOLDING_WING_CAP,
+ /*0x05*/
+ MARIO_HAND_RIGHT_OPEN
};
enum MarioCapGSCId
{
- /*0x00*/ MARIO_HAS_DEFAULT_CAP_ON,
- /*0x01*/ MARIO_HAS_DEFAULT_CAP_OFF,
- /*0x02*/ MARIO_HAS_WING_CAP_ON,
- /*0x03*/ MARIO_HAS_WING_CAP_OFF // unused
+ /*0x00*/
+ MARIO_HAS_DEFAULT_CAP_ON,
+ /*0x01*/
+ MARIO_HAS_DEFAULT_CAP_OFF,
+ /*0x02*/
+ MARIO_HAS_WING_CAP_ON,
+ /*0x03*/
+ MARIO_HAS_WING_CAP_OFF // unused
};
enum MarioGrabPosGSCId
{
- /*0x00*/ GRAB_POS_NULL,
- /*0x01*/ GRAB_POS_LIGHT_OBJ,
- /*0x02*/ GRAB_POS_HEAVY_OBJ,
- /*0x03*/ GRAB_POS_BOWSER
+ /*0x00*/
+ GRAB_POS_NULL,
+ /*0x01*/
+ GRAB_POS_LIGHT_OBJ,
+ /*0x02*/
+ GRAB_POS_HEAVY_OBJ,
+ /*0x03*/
+ GRAB_POS_BOWSER
};
#endif // MARIO_GEO_SWITCH_CASE_IDS_H
diff --git a/src/decomp/include/object_fields.h b/src/decomp/include/object_fields.h
index 5914a5a..03bdecf 100644
--- a/src/decomp/include/object_fields.h
+++ b/src/decomp/include/object_fields.h
@@ -586,7 +586,7 @@
#define /*0x0F4*/ oKickableBoardF4 OBJECT_FIELD_S32(0x1B)
#define /*0x0F8*/ oKickableBoardF8 OBJECT_FIELD_S32(0x1C)
- /* King Bob-omb */
+/* King Bob-omb */
#define /*0x088*/ oKingBobombUnk88 OBJECT_FIELD_S32(0x00)
#define /*0x0F8*/ oKingBobombUnkF8 OBJECT_FIELD_S32(0x1C)
#define /*0x0FC*/ oKingBobombUnkFC OBJECT_FIELD_S32(0x1D)
@@ -686,7 +686,7 @@
/* Mips */
#define /*0x0F4*/ oMipsStarStatus OBJECT_FIELD_S32(0x1B)
#define /*0x0F8*/ oMipsStartWaypointIndex OBJECT_FIELD_S32(0x1C)
- // 0x1D-0x21 reserved for pathing
+// 0x1D-0x21 reserved for pathing
#define /*0x1AC*/ oMipsForwardVelocity OBJECT_FIELD_F32(0x49)
/* Moneybag */
diff --git a/src/decomp/include/seq_ids.h b/src/decomp/include/seq_ids.h
index 4e52979..eee8952 100644
--- a/src/decomp/include/seq_ids.h
+++ b/src/decomp/include/seq_ids.h
@@ -3,42 +3,78 @@
#define SEQ_VARIATION 0x80
-enum SeqId {
- SEQ_SOUND_PLAYER, // 0x00
- SEQ_EVENT_CUTSCENE_COLLECT_STAR, // 0x01
- SEQ_MENU_TITLE_SCREEN, // 0x02
- SEQ_LEVEL_GRASS, // 0x03
- SEQ_LEVEL_INSIDE_CASTLE, // 0x04
- SEQ_LEVEL_WATER, // 0x05
- SEQ_LEVEL_HOT, // 0x06
- SEQ_LEVEL_BOSS_KOOPA, // 0x07
- SEQ_LEVEL_SNOW, // 0x08
- SEQ_LEVEL_SLIDE, // 0x09
- SEQ_LEVEL_SPOOKY, // 0x0A
- SEQ_EVENT_PIRANHA_PLANT, // 0x0B
- SEQ_LEVEL_UNDERGROUND, // 0x0C
- SEQ_MENU_STAR_SELECT, // 0x0D
- SEQ_EVENT_POWERUP, // 0x0E
- SEQ_EVENT_METAL_CAP, // 0x0F
- SEQ_EVENT_KOOPA_MESSAGE, // 0x10
- SEQ_LEVEL_KOOPA_ROAD, // 0x11
- SEQ_EVENT_HIGH_SCORE, // 0x12
- SEQ_EVENT_MERRY_GO_ROUND, // 0x13
- SEQ_EVENT_RACE, // 0x14
- SEQ_EVENT_CUTSCENE_STAR_SPAWN, // 0x15
- SEQ_EVENT_BOSS, // 0x16
- SEQ_EVENT_CUTSCENE_COLLECT_KEY, // 0x17
- SEQ_EVENT_ENDLESS_STAIRS, // 0x18
- SEQ_LEVEL_BOSS_KOOPA_FINAL, // 0x19
- SEQ_EVENT_CUTSCENE_CREDITS, // 0x1A
- SEQ_EVENT_SOLVE_PUZZLE, // 0x1B
- SEQ_EVENT_TOAD_MESSAGE, // 0x1C
- SEQ_EVENT_PEACH_MESSAGE, // 0x1D
- SEQ_EVENT_CUTSCENE_INTRO, // 0x1E
- SEQ_EVENT_CUTSCENE_VICTORY, // 0x1F
- SEQ_EVENT_CUTSCENE_ENDING, // 0x20
- SEQ_MENU_FILE_SELECT, // 0x21
- SEQ_EVENT_CUTSCENE_LAKITU, // 0x22 (not in JP)
+enum SeqId
+{
+ SEQ_SOUND_PLAYER,
+ // 0x00
+ SEQ_EVENT_CUTSCENE_COLLECT_STAR,
+ // 0x01
+ SEQ_MENU_TITLE_SCREEN,
+ // 0x02
+ SEQ_LEVEL_GRASS,
+ // 0x03
+ SEQ_LEVEL_INSIDE_CASTLE,
+ // 0x04
+ SEQ_LEVEL_WATER,
+ // 0x05
+ SEQ_LEVEL_HOT,
+ // 0x06
+ SEQ_LEVEL_BOSS_KOOPA,
+ // 0x07
+ SEQ_LEVEL_SNOW,
+ // 0x08
+ SEQ_LEVEL_SLIDE,
+ // 0x09
+ SEQ_LEVEL_SPOOKY,
+ // 0x0A
+ SEQ_EVENT_PIRANHA_PLANT,
+ // 0x0B
+ SEQ_LEVEL_UNDERGROUND,
+ // 0x0C
+ SEQ_MENU_STAR_SELECT,
+ // 0x0D
+ SEQ_EVENT_POWERUP,
+ // 0x0E
+ SEQ_EVENT_METAL_CAP,
+ // 0x0F
+ SEQ_EVENT_KOOPA_MESSAGE,
+ // 0x10
+ SEQ_LEVEL_KOOPA_ROAD,
+ // 0x11
+ SEQ_EVENT_HIGH_SCORE,
+ // 0x12
+ SEQ_EVENT_MERRY_GO_ROUND,
+ // 0x13
+ SEQ_EVENT_RACE,
+ // 0x14
+ SEQ_EVENT_CUTSCENE_STAR_SPAWN,
+ // 0x15
+ SEQ_EVENT_BOSS,
+ // 0x16
+ SEQ_EVENT_CUTSCENE_COLLECT_KEY,
+ // 0x17
+ SEQ_EVENT_ENDLESS_STAIRS,
+ // 0x18
+ SEQ_LEVEL_BOSS_KOOPA_FINAL,
+ // 0x19
+ SEQ_EVENT_CUTSCENE_CREDITS,
+ // 0x1A
+ SEQ_EVENT_SOLVE_PUZZLE,
+ // 0x1B
+ SEQ_EVENT_TOAD_MESSAGE,
+ // 0x1C
+ SEQ_EVENT_PEACH_MESSAGE,
+ // 0x1D
+ SEQ_EVENT_CUTSCENE_INTRO,
+ // 0x1E
+ SEQ_EVENT_CUTSCENE_VICTORY,
+ // 0x1F
+ SEQ_EVENT_CUTSCENE_ENDING,
+ // 0x20
+ SEQ_MENU_FILE_SELECT,
+ // 0x21
+ SEQ_EVENT_CUTSCENE_LAKITU,
+ // 0x22 (not in JP)
SEQ_COUNT
};
diff --git a/src/decomp/include/special_preset_names.h b/src/decomp/include/special_preset_names.h
index 229d287..b8d12bf 100644
--- a/src/decomp/include/special_preset_names.h
+++ b/src/decomp/include/special_preset_names.h
@@ -1,7 +1,8 @@
#ifndef SPECIAL_PRESET_NAMES_H
#define SPECIAL_PRESET_NAMES_H
-enum SpecialPresets {
+enum SpecialPresets
+{
special_null_start,
special_yellow_coin,
special_yellow_coin_2,
@@ -43,7 +44,6 @@ enum SpecialPresets {
special_rotating_counter_clockwise,
special_wf_tumbling_bridge,
special_large_bomp,
-
special_level_geo_03 = 0x65,
special_level_geo_04,
special_level_geo_05,
@@ -86,7 +86,6 @@ enum SpecialPresets {
special_1star_door,
special_3star_door,
special_key_door,
-
special_null_end = 0xFF
};
diff --git a/src/decomp/include/types.h b/src/decomp/include/types.h
index 118b5c6..b7bc2dd 100644
--- a/src/decomp/include/types.h
+++ b/src/decomp/include/types.h
@@ -14,26 +14,33 @@
// avoid on modern GCC. This only impacts -O2 and can matter for both the function
// itself and functions that call it.
#ifdef AVOID_UB
- #define BAD_RETURN(cmd) void
+#define BAD_RETURN(cmd) void
#else
- #define BAD_RETURN(cmd) cmd
+#define BAD_RETURN(cmd) cmd
#endif
struct Controller
{
- /*0x00*/ s16 rawStickX; //
- /*0x02*/ s16 rawStickY; //
- /*0x04*/ float stickX; // [-64, 64] positive is right
- /*0x08*/ float stickY; // [-64, 64] positive is up
- /*0x0C*/ float stickMag; // distance from center [0, 64]
- /*0x10*/ u16 buttonDown;
- /*0x12*/ u16 buttonPressed;
-///*0x14*/ OSContStatus *statusData;
+ /*0x00*/
+ s16 rawStickX; //
+ /*0x02*/
+ s16 rawStickY; //
+ /*0x04*/
+ float stickX; // [-64, 64] positive is right
+ /*0x08*/
+ float stickY; // [-64, 64] positive is up
+ /*0x0C*/
+ float stickMag; // distance from center [0, 64]
+ /*0x10*/
+ u16 buttonDown;
+ /*0x12*/
+ u16 buttonPressed;
+ ///*0x14*/ OSContStatus *statusData;
///*0x18*/ OSContPad *controllerData;
-#ifdef VERSION_SH
- /*0x1C*/ int port;
-#endif
+ #ifdef VERSION_SH
+ /*0x1C*/ int port;
+ #endif
};
typedef f32 Vec2f[2];
@@ -54,7 +61,8 @@ typedef s16 Trajectory;
typedef s16 PaintingData;
typedef uintptr_t BehaviorScript;
-enum SpTaskState {
+enum SpTaskState
+{
SPTASK_STATE_NOT_STARTED,
SPTASK_STATE_RUNNING,
SPTASK_STATE_INTERRUPTED,
@@ -64,10 +72,14 @@ enum SpTaskState {
struct SPTask
{
- /*0x00*/ OSTask task;
- /*0x40*/ OSMesgQueue *msgqueue;
- /*0x44*/ OSMesg msg;
- /*0x48*/ enum SpTaskState state;
+ /*0x00*/
+ OSTask task;
+ /*0x40*/
+ OSMesgQueue *msgqueue;
+ /*0x44*/
+ OSMesg msg;
+ /*0x48*/
+ enum SpTaskState state;
}; // size = 0x4C, align = 0x8
struct VblankHandler
@@ -85,53 +97,87 @@ struct VblankHandler
#define ANIM_FLAG_6 (1 << 6) // 0x40
#define ANIM_FLAG_7 (1 << 7) // 0x80
-struct Animation {
- /*0x00*/ s16 flags;
- /*0x02*/ s16 animYTransDivisor;
- /*0x04*/ s16 startFrame;
- /*0x06*/ s16 loopStart;
- /*0x08*/ s16 loopEnd; /*0x0A*/ s16 unusedBoneCount;
- /*0x0C*/ s16 *values;
- /*0x10*/ u16 *index;
- /*0x14*/ u32 length; // only used with Mario animations to determine how much to load. 0 otherwise.
+struct Animation
+{
+ /*0x00*/
+ s16 flags;
+ /*0x02*/
+ s16 animYTransDivisor;
+ /*0x04*/
+ s16 startFrame;
+ /*0x06*/
+ s16 loopStart;
+ /*0x08*/
+ s16 loopEnd; /*0x0A*/
+ s16 unusedBoneCount;
+ /*0x0C*/
+ s16 *values;
+ /*0x10*/
+ u16 *index;
+ /*0x14*/
+ u32 length; // only used with Mario animations to determine how much to load. 0 otherwise.
};
#define ANIMINDEX_NUMPARTS(animindex) (sizeof(animindex) / sizeof(u16) / 6 - 1)
struct GraphNode
{
- /*0x00*/ s16 type; // structure type
- /*0x02*/ s16 flags; // hi = drawing layer, lo = rendering modes
- /*0x04*/ struct GraphNode *prev;
- /*0x08*/ struct GraphNode *next;
- /*0x0C*/ struct GraphNode *parent;
- /*0x10*/ struct GraphNode *children;
+ /*0x00*/
+ s16 type; // structure type
+ /*0x02*/
+ s16 flags; // hi = drawing layer, lo = rendering modes
+ /*0x04*/
+ struct GraphNode *prev;
+ /*0x08*/
+ struct GraphNode *next;
+ /*0x0C*/
+ struct GraphNode *parent;
+ /*0x10*/
+ struct GraphNode *children;
};
struct AnimInfo
{
- /*0x00 0x38*/ s16 animID;
- /*0x02 0x3A*/ s16 animYTrans;
- /*0x04 0x3C*/ struct Animation *curAnim;
- /*0x08 0x40*/ s16 animFrame;
- /*0x0A 0x42*/ u16 animTimer;
- /*0x0C 0x44*/ s32 animFrameAccelAssist;
- /*0x10 0x48*/ s32 animAccel;
+ /*0x00 0x38*/
+ s16 animID;
+ /*0x02 0x3A*/
+ s16 animYTrans;
+ /*0x04 0x3C*/
+ struct Animation *curAnim;
+ /*0x08 0x40*/
+ s16 animFrame;
+ /*0x0A 0x42*/
+ u16 animTimer;
+ /*0x0C 0x44*/
+ s32 animFrameAccelAssist;
+ /*0x10 0x48*/
+ s32 animAccel;
};
struct GraphNodeObject
{
- /*0x00*/ struct GraphNode node;
- /*0x14*/ struct GraphNode *sharedChild;
- /*0x18*/ s8 areaIndex;
- /*0x19*/ s8 activeAreaIndex;
- /*0x1A*/ Vec3s angle;
- /*0x20*/ Vec3f pos;
- /*0x2C*/ Vec3f scale;
- /*0x38*/ struct AnimInfo animInfo;
- /*0x4C*/ struct SpawnInfo *unk4C;
- /*0x50*/ Mat4 *throwMatrix; // matrix ptr
- /*0x54*/ Vec3f cameraToObject;
+ /*0x00*/
+ struct GraphNode node;
+ /*0x14*/
+ struct GraphNode *sharedChild;
+ /*0x18*/
+ s8 areaIndex;
+ /*0x19*/
+ s8 activeAreaIndex;
+ /*0x1A*/
+ Vec3s angle;
+ /*0x20*/
+ Vec3f pos;
+ /*0x2C*/
+ Vec3f scale;
+ /*0x38*/
+ struct AnimInfo animInfo;
+ /*0x4C*/
+ struct SpawnInfo *unk4C;
+ /*0x50*/
+ Mat4 *throwMatrix; // matrix ptr
+ /*0x54*/
+ Vec3f cameraToObject;
};
struct ObjectNode
@@ -146,13 +192,21 @@ struct ObjectNode
struct Object
{
- /*0x000*/ struct ObjectNode header;
- /*0x068*/ struct Object *parentObj;
- /*0x06C*/ struct Object *prevObj;
- /*0x070*/ u32 collidedObjInteractTypes;
- /*0x074*/ s16 activeFlags;
- /*0x076*/ s16 numCollidedObjs;
- /*0x078*/ struct Object *collidedObjs[4];
+ /*0x000*/
+ struct ObjectNode header;
+ /*0x068*/
+ struct Object *parentObj;
+ /*0x06C*/
+ struct Object *prevObj;
+ /*0x070*/
+ u32 collidedObjInteractTypes;
+ /*0x074*/
+ s16 activeFlags;
+ /*0x076*/
+ s16 numCollidedObjs;
+ /*0x078*/
+ struct Object *collidedObjs[4];
+
/*0x088*/
union
{
@@ -161,7 +215,7 @@ struct Object
s32 asS32[0x50];
s16 asS16[0x50][2];
f32 asF32[0x50];
-#if !IS_64_BIT
+ #if !IS_64_BIT
s16 *asS16P[0x50];
s32 *asS32P[0x50];
struct Animation **asAnims[0x50];
@@ -171,10 +225,11 @@ struct Object
struct SM64SurfaceCollisionData *asSurface[0x50];
void *asVoidPtr[0x50];
const void *asConstVoidPtr[0x50];
-#endif
+ #endif
} rawData;
-#if IS_64_BIT
- union {
+ #if IS_64_BIT
+ union
+ {
s16 *asS16P[0x50];
s32 *asS32P[0x50];
struct Animation **asAnims[0x50];
@@ -185,37 +240,63 @@ struct Object
void *asVoidPtr[0x50];
const void *asConstVoidPtr[0x50];
} ptrData;
-#endif
- /*0x1C8*/ u32 unused1;
- /*0x1CC*/ const BehaviorScript *curBhvCommand;
- /*0x1D0*/ u32 bhvStackIndex;
- /*0x1D4*/ uintptr_t bhvStack[8];
- /*0x1F4*/ s16 bhvDelayTimer;
- /*0x1F6*/ s16 respawnInfoType;
- /*0x1F8*/ f32 hitboxRadius;
- /*0x1FC*/ f32 hitboxHeight;
- /*0x200*/ f32 hurtboxRadius;
- /*0x204*/ f32 hurtboxHeight;
- /*0x208*/ f32 hitboxDownOffset;
- /*0x20C*/ const BehaviorScript *behavior;
- /*0x210*/ u32 unused2;
- /*0x214*/ struct SM64SurfaceObjectTransform *platform; // libsm64: type change from Object*
- /*0x218*/ void *collisionData;
- /*0x21C*/ Mat4 transform;
- /*0x25C*/ void *respawnInfo;
+ #endif
+ /*0x1C8*/
+ u32 unused1;
+ /*0x1CC*/
+ const BehaviorScript *curBhvCommand;
+ /*0x1D0*/
+ u32 bhvStackIndex;
+ /*0x1D4*/
+ uintptr_t bhvStack[8];
+ /*0x1F4*/
+ s16 bhvDelayTimer;
+ /*0x1F6*/
+ s16 respawnInfoType;
+ /*0x1F8*/
+ f32 hitboxRadius;
+ /*0x1FC*/
+ f32 hitboxHeight;
+ /*0x200*/
+ f32 hurtboxRadius;
+ /*0x204*/
+ f32 hurtboxHeight;
+ /*0x208*/
+ f32 hitboxDownOffset;
+ /*0x20C*/
+ const BehaviorScript *behavior;
+ /*0x210*/
+ u32 unused2;
+ /*0x214*/
+ struct SM64SurfaceObjectTransform *platform; // libsm64: type change from Object*
+ /*0x218*/
+ void *collisionData;
+ /*0x21C*/
+ Mat4 transform;
+ /*0x25C*/
+ void *respawnInfo;
};
struct ObjectHitbox
{
- /*0x00*/ u32 interactType;
- /*0x04*/ u8 downOffset;
- /*0x05*/ s8 damageOrCoinValue;
- /*0x06*/ s8 health;
- /*0x07*/ s8 numLootCoins;
- /*0x08*/ s16 radius;
- /*0x0A*/ s16 height;
- /*0x0C*/ s16 hurtboxRadius;
- /*0x0E*/ s16 hurtboxHeight;
+ /*0x00*/
+ u32 interactType;
+ /*0x04*/
+ u8 downOffset;
+ /*0x05*/
+ s8 damageOrCoinValue;
+ /*0x06*/
+ s8 health;
+ /*0x07*/
+ s8 numLootCoins;
+ /*0x08*/
+ s16 radius;
+ /*0x0A*/
+ s16 height;
+ /*0x0C*/
+ s16 hurtboxRadius;
+ /*0x0E*/
+ s16 hurtboxHeight;
};
struct Waypoint
@@ -226,17 +307,28 @@ struct Waypoint
struct MarioBodyState
{
- /*0x00*/ u32 action;
- /*0x04*/ s8 capState; /// see MarioCapGSCId
- /*0x05*/ s8 eyeState;
- /*0x06*/ s8 handState;
- /*0x07*/ s8 wingFlutter; /// whether Mario's wing cap wings are fluttering
- /*0x08*/ s16 modelState;
- /*0x0A*/ s8 grabPos;
- /*0x0B*/ u8 punchState; /// 2 bits for type of punch, 6 bits for punch animation timer
- /*0x0C*/ Vec3s torsoAngle;
- /*0x12*/ Vec3s headAngle;
- /*0x18*/ Vec3f heldObjLastPosition; /// also known as HOLP
+ /*0x00*/
+ u32 action;
+ /*0x04*/
+ s8 capState; /// see MarioCapGSCId
+ /*0x05*/
+ s8 eyeState;
+ /*0x06*/
+ s8 handState;
+ /*0x07*/
+ s8 wingFlutter; /// whether Mario's wing cap wings are fluttering
+ /*0x08*/
+ s16 modelState;
+ /*0x0A*/
+ s8 grabPos;
+ /*0x0B*/
+ u8 punchState; /// 2 bits for type of punch, 6 bits for punch animation timer
+ /*0x0C*/
+ Vec3s torsoAngle;
+ /*0x12*/
+ Vec3s headAngle;
+ /*0x18*/
+ Vec3f heldObjLastPosition; /// also known as HOLP
u8 padding[4];
};
@@ -263,66 +355,125 @@ struct MarioAnimation
struct MarioState
{
- /*0x00*/ u16 unk00;
- /*0x02*/ u16 input;
- /*0x04*/ u32 flags;
- /*0x08*/ u32 particleFlags;
- /*0x0C*/ u32 action;
- /*0x10*/ u32 prevAction;
- /*0x14*/ u32 terrainSoundAddend;
- /*0x18*/ u16 actionState;
- /*0x1A*/ u16 actionTimer;
- /*0x1C*/ u32 actionArg;
- /*0x20*/ f32 intendedMag;
- /*0x24*/ s16 intendedYaw;
- /*0x26*/ s16 invincTimer;
- /*0x28*/ u8 framesSinceA;
- /*0x29*/ u8 framesSinceB;
- /*0x2A*/ u8 wallKickTimer;
- /*0x2B*/ u8 doubleJumpTimer;
- /*0x2C*/ Vec3s faceAngle;
- /*0x32*/ Vec3s angleVel;
- /*0x38*/ s16 slideYaw;
- /*0x3A*/ s16 twirlYaw;
- /*0x3C*/ Vec3f pos;
- /*0x48*/ Vec3f vel;
- /*0x54*/ f32 forwardVel;
- /*0x58*/ f32 slideVelX;
- /*0x5C*/ f32 slideVelZ;
- /*0x60*/ struct SM64SurfaceCollisionData *wall;
- /*0x64*/ struct SM64SurfaceCollisionData *ceil;
- /*0x68*/ struct SM64SurfaceCollisionData *floor;
- /*0x6C*/ f32 ceilHeight;
- /*0x70*/ f32 floorHeight;
- /*0x74*/ s16 floorAngle;
- /*0x76*/ s32 waterLevel; // libsm64: 32 bit (address offsets after this are wrong)
- /*0x78*/ struct Object *interactObj;
- /*0x7C*/ struct Object *heldObj;
- /*0x80*/ struct Object *usedObj;
- /*0x84*/ struct Object *riddenObj;
- /*0x88*/ struct Object *marioObj;
- /*0x8C*/ struct SpawnInfo *spawnInfo;
- /*0x90*/ struct Area *area;
-// /*0x94*/ struct PlayerCameraState *statusForCamera;
- /*0x98*/ struct MarioBodyState *marioBodyState;
- /*0x9C*/ struct Controller *controller;
- /*0xA0*/ struct MarioAnimation *animation;
- /*0xA4*/ u32 collidedObjInteractTypes;
- /*0xA8*/ s16 numCoins;
- /*0xAA*/ s16 numStars;
- /*0xAC*/ s8 numKeys; // Unused key mechanic
- /*0xAD*/ s8 numLives;
- /*0xAE*/ s16 health;
- /*0xB0*/ s16 unkB0;
- /*0xB2*/ u8 hurtCounter;
- /*0xB3*/ u8 healCounter;
- /*0xB4*/ u8 squishTimer;
- /*0xB5*/ u8 fadeWarpOpacity;
- /*0xB6*/ u16 capTimer;
- /*0xB8*/ s16 prevNumStarsForDialog;
- /*0xBC*/ f32 peakHeight;
- /*0xC0*/ f32 quicksandDepth;
- /*0xC4*/ f32 unkC4;
+ /*0x00*/
+ u16 unk00;
+ /*0x02*/
+ u16 input;
+ /*0x04*/
+ u32 flags;
+ /*0x08*/
+ u32 particleFlags;
+ /*0x0C*/
+ u32 action;
+ /*0x10*/
+ u32 prevAction;
+ /*0x14*/
+ u32 terrainSoundAddend;
+ /*0x18*/
+ u16 actionState;
+ /*0x1A*/
+ u16 actionTimer;
+ /*0x1C*/
+ u32 actionArg;
+ /*0x20*/
+ f32 intendedMag;
+ /*0x24*/
+ s16 intendedYaw;
+ /*0x26*/
+ s16 invincTimer;
+ /*0x28*/
+ u8 framesSinceA;
+ /*0x29*/
+ u8 framesSinceB;
+ /*0x2A*/
+ u8 wallKickTimer;
+ /*0x2B*/
+ u8 doubleJumpTimer;
+ /*0x2C*/
+ Vec3s faceAngle;
+ /*0x32*/
+ Vec3s angleVel;
+ /*0x38*/
+ s16 slideYaw;
+ /*0x3A*/
+ s16 twirlYaw;
+ /*0x3C*/
+ Vec3f pos;
+ /*0x48*/
+ Vec3f vel;
+ /*0x54*/
+ f32 forwardVel;
+ /*0x58*/
+ f32 slideVelX;
+ /*0x5C*/
+ f32 slideVelZ;
+ /*0x60*/
+ struct SM64SurfaceCollisionData *wall;
+ /*0x64*/
+ struct SM64SurfaceCollisionData *ceil;
+ /*0x68*/
+ struct SM64SurfaceCollisionData *floor;
+ /*0x6C*/
+ f32 ceilHeight;
+ /*0x70*/
+ f32 floorHeight;
+ /*0x74*/
+ s16 floorAngle;
+ /*0x76*/
+ s32 waterLevel; // libsm64: 32 bit (address offsets after this are wrong)
+ /*0x78*/
+ struct Object *interactObj;
+ /*0x7C*/
+ struct Object *heldObj;
+ /*0x80*/
+ struct Object *usedObj;
+ /*0x84*/
+ struct Object *riddenObj;
+ /*0x88*/
+ struct Object *marioObj;
+ /*0x8C*/
+ struct SpawnInfo *spawnInfo;
+ /*0x90*/
+ struct Area *area;
+ // /*0x94*/ struct PlayerCameraState *statusForCamera;
+ /*0x98*/
+ struct MarioBodyState *marioBodyState;
+ /*0x9C*/
+ struct Controller *controller;
+ /*0xA0*/
+ struct MarioAnimation *animation;
+ /*0xA4*/
+ u32 collidedObjInteractTypes;
+ /*0xA8*/
+ s16 numCoins;
+ /*0xAA*/
+ s16 numStars;
+ /*0xAC*/
+ s8 numKeys; // Unused key mechanic
+ /*0xAD*/
+ s8 numLives;
+ /*0xAE*/
+ s16 health;
+ /*0xB0*/
+ s16 unkB0;
+ /*0xB2*/
+ u8 hurtCounter;
+ /*0xB3*/
+ u8 healCounter;
+ /*0xB4*/
+ u8 squishTimer;
+ /*0xB5*/
+ u8 fadeWarpOpacity;
+ /*0xB6*/
+ u16 capTimer;
+ /*0xB8*/
+ s16 prevNumStarsForDialog;
+ /*0xBC*/
+ f32 peakHeight;
+ /*0xC0*/
+ f32 quicksandDepth;
+ /*0xC4*/
+ f32 unkC4;
u16 curTerrain; // libsm64: added field
s32 gasLevel; // libsm64: added field
diff --git a/src/decomp/memory.c b/src/decomp/memory.c
index 270e96e..b501d1e 100644
--- a/src/decomp/memory.c
+++ b/src/decomp/memory.c
@@ -5,7 +5,7 @@
// TODO don't handle every individual allocation with malloc, it sucks on windows
-struct AllocOnlyPool
+struct AllocOnlyPool
{
size_t allocatedCount;
void **allocatedBlocks;
@@ -20,12 +20,12 @@ void memory_init(void)
void memory_terminate(void)
{
- alloc_only_pool_free( s_display_list_pool );
+ alloc_only_pool_free(s_display_list_pool);
}
struct AllocOnlyPool *alloc_only_pool_init(void)
{
- struct AllocOnlyPool *newPool = malloc( sizeof( struct AllocOnlyPool ));
+ struct AllocOnlyPool *newPool = malloc(sizeof(struct AllocOnlyPool));
newPool->allocatedCount = 0;
newPool->allocatedBlocks = NULL;
return newPool;
@@ -34,26 +34,26 @@ struct AllocOnlyPool *alloc_only_pool_init(void)
void *alloc_only_pool_alloc(struct AllocOnlyPool *pool, s32 size)
{
pool->allocatedCount++;
- pool->allocatedBlocks = realloc( pool->allocatedBlocks, pool->allocatedCount * sizeof( void * ));
- pool->allocatedBlocks[ pool->allocatedCount - 1 ] = malloc( size );
- return pool->allocatedBlocks[ pool->allocatedCount - 1 ];
+ pool->allocatedBlocks = realloc(pool->allocatedBlocks, pool->allocatedCount * sizeof(void *));
+ pool->allocatedBlocks[pool->allocatedCount - 1] = malloc(size);
+ return pool->allocatedBlocks[pool->allocatedCount - 1];
}
void alloc_only_pool_free(struct AllocOnlyPool *pool)
{
- for( int i = 0; i < pool->allocatedCount; ++i )
- free( pool->allocatedBlocks[i] );
- free( pool->allocatedBlocks );
- free( pool );
+ for (int i = 0; i < pool->allocatedCount; ++i)
+ free(pool->allocatedBlocks[i]);
+ free(pool->allocatedBlocks);
+ free(pool);
}
void display_list_pool_reset(void)
{
- alloc_only_pool_free( s_display_list_pool );
+ alloc_only_pool_free(s_display_list_pool);
s_display_list_pool = alloc_only_pool_init();
}
void *alloc_display_list(u32 size)
{
- return alloc_only_pool_alloc( s_display_list_pool, (s32)size );
+ return alloc_only_pool_alloc(s_display_list_pool, (s32)size);
}
\ No newline at end of file
diff --git a/src/decomp/memory.h b/src/decomp/memory.h
index 161624a..85bf11e 100644
--- a/src/decomp/memory.h
+++ b/src/decomp/memory.h
@@ -5,11 +5,15 @@
struct AllocOnlyPool;
extern void memory_init(void);
+
extern void memory_terminate(void);
extern struct AllocOnlyPool *alloc_only_pool_init(void);
+
extern void *alloc_only_pool_alloc(struct AllocOnlyPool *pool, s32 size);
+
extern void alloc_only_pool_free(struct AllocOnlyPool *pool);
extern void display_list_pool_reset(void);
+
extern void *alloc_display_list(u32 size);
\ No newline at end of file
diff --git a/src/decomp/pc/alBnkfNew.c b/src/decomp/pc/alBnkfNew.c
index bb04df3..0f58358 100644
--- a/src/decomp/pc/alBnkfNew.c
+++ b/src/decomp/pc/alBnkfNew.c
@@ -3,29 +3,35 @@
#define PATCH(SRC, BASE, TYPE) //SRC = (TYPE)((uintptr_t) SRC + (uintptr_t) BASE)
-void alSeqFileNew(ALSeqFile *f, u8 *base) {
+void alSeqFileNew(ALSeqFile *f, u8 *base)
+{
int i;
- for (i = 0; i < f->seqCount; i++) {
+ for (i = 0; i < f->seqCount; i++)
+ {
PATCH(f->seqArray[i].offset, base, u8 *);
}
}
-static void _bnkfPatchBank(ALInstrument *inst, ALBankFile *f, u8 *table) {
+static void _bnkfPatchBank(ALInstrument *inst, ALBankFile *f, u8 *table)
+{
int i;
ALSound *sound;
ALWaveTable *wavetable;
u8 *table2;
- if (inst->flags) {
+ if (inst->flags)
+ {
return;
}
inst->flags = 1;
- for (i = 0; i < inst->soundCount; i++) {
+ for (i = 0; i < inst->soundCount; i++)
+ {
PATCH(inst->soundArray[i], f, ALSound *);
sound = inst->soundArray[i];
- if (sound->flags) {
+ if (sound->flags)
+ {
continue;
}
@@ -36,19 +42,25 @@ static void _bnkfPatchBank(ALInstrument *inst, ALBankFile *f, u8 *table) {
PATCH(sound->keyMap, f, ALKeyMap *);
PATCH(sound->wavetable, f, ALWaveTable *);
wavetable = sound->wavetable;
- if (wavetable->flags) {
+ if (wavetable->flags)
+ {
continue;
}
wavetable->flags = 1;
PATCH(wavetable->base, table2, u8 *);
- if (wavetable->type == 0) {
+ if (wavetable->type == 0)
+ {
PATCH(wavetable->waveInfo.adpcmWave.book, f, ALADPCMBook *);
- if (wavetable->waveInfo.adpcmWave.loop != NULL) {
+ if (wavetable->waveInfo.adpcmWave.loop != NULL)
+ {
PATCH(wavetable->waveInfo.adpcmWave.loop, f, ALADPCMloop *);
}
- } else if (wavetable->type == 1) {
- if (wavetable->waveInfo.rawWave.loop != NULL) {
+ }
+ else if (wavetable->type == 1)
+ {
+ if (wavetable->waveInfo.rawWave.loop != NULL)
+ {
PATCH(wavetable->waveInfo.rawWave.loop, f, ALRawLoop *);
}
}
@@ -57,34 +69,43 @@ static void _bnkfPatchBank(ALInstrument *inst, ALBankFile *f, u8 *table) {
// Force adding another jr $ra. Has to be called or it doesn't get put in the
// right place.
-static void unused(void) {
+static void unused(void)
+{
}
-void alBnkfNew(ALBankFile *f, u8 *table) {
+void alBnkfNew(ALBankFile *f, u8 *table)
+{
ALBank *bank;
int i;
int j;
unused();
- if (f->revision != AL_BANK_VERSION) {
+ if (f->revision != AL_BANK_VERSION)
+ {
return;
}
- for (i = 0; i < f->bankCount; i++) {
+ for (i = 0; i < f->bankCount; i++)
+ {
PATCH(f->bankArray[i], f, ALBank *);
- if (f->bankArray[i] == NULL) {
+ if (f->bankArray[i] == NULL)
+ {
continue;
}
bank = f->bankArray[i];
- if (bank->flags == 0) {
+ if (bank->flags == 0)
+ {
bank->flags = 1;
- if (bank->percussion != NULL) {
+ if (bank->percussion != NULL)
+ {
PATCH(bank->percussion, f, ALInstrument *);
_bnkfPatchBank(bank->percussion, f, table);
}
- for (j = 0; j < bank->instCount; j++) {
+ for (j = 0; j < bank->instCount; j++)
+ {
PATCH(bank->instArray[j], f, ALInstrument *);
- if (bank->instArray[j] != NULL) {
+ if (bank->instArray[j] != NULL)
+ {
_bnkfPatchBank(bank->instArray[j], f, table);
}
}
diff --git a/src/decomp/pc/libaudio_internal.h b/src/decomp/pc/libaudio_internal.h
index ea63322..dd6a1d8 100644
--- a/src/decomp/pc/libaudio_internal.h
+++ b/src/decomp/pc/libaudio_internal.h
@@ -9,8 +9,7 @@ typedef s32 ALMicroTime;
/* Possible wavetable types */
enum
{
- AL_ADPCM_WAVE = 0,
- AL_RAW16_WAVE
+ AL_ADPCM_WAVE = 0, AL_RAW16_WAVE
};
typedef struct
@@ -68,10 +67,11 @@ typedef struct
typedef struct ALWaveTable_s
{
u8 *base; /* ptr to start of wave data */
- s32 len; /* length of data in bytes */
- u8 type; /* compression type */
+ s32 len; /* length of data in bytes */
+ u8 type; /* compression type */
u8 flags; /* offset/address flags */
- union {
+ union
+ {
ALADPCMWaveInfo adpcmWave;
ALRAWWaveInfo rawWave;
} waveInfo;
@@ -89,19 +89,19 @@ typedef struct ALSound_s
typedef struct
{
- u8 volume; /* overall volume for this instrument */
- ALPan pan; /* 0 = hard left, 127 = hard right */
+ u8 volume; /* overall volume for this instrument */
+ ALPan pan; /* 0 = hard left, 127 = hard right */
u8 priority; /* voice priority for this instrument */
u8 flags;
- u8 tremType; /* the type of tremelo osc. to use */
- u8 tremRate; /* the rate of the tremelo osc. */
- u8 tremDepth; /* the depth of the tremelo osc */
- u8 tremDelay; /* the delay for the tremelo osc */
- u8 vibType; /* the type of tremelo osc. to use */
- u8 vibRate; /* the rate of the tremelo osc. */
- u8 vibDepth; /* the depth of the tremelo osc */
- u8 vibDelay; /* the delay for the tremelo osc */
- s16 bendRange; /* pitch bend range in cents */
+ u8 tremType; /* the type of tremelo osc. to use */
+ u8 tremRate; /* the rate of the tremelo osc. */
+ u8 tremDepth; /* the depth of the tremelo osc */
+ u8 tremDelay; /* the delay for the tremelo osc */
+ u8 vibType; /* the type of tremelo osc. to use */
+ u8 vibRate; /* the rate of the tremelo osc. */
+ u8 vibDepth; /* the depth of the tremelo osc */
+ u8 vibDelay; /* the delay for the tremelo osc */
+ s16 bendRange; /* pitch bend range in cents */
s16 soundCount; /* number of sounds in this array */
ALSound *soundArray[1];
} ALInstrument;
@@ -111,17 +111,17 @@ typedef struct ALBank_s
s16 instCount; /* number of programs in this bank */
u8 flags;
u8 pad;
- s32 sampleRate; /* e.g. 44100, 22050, etc... */
- ALInstrument *percussion; /* default percussion for GM */
+ s32 sampleRate; /* e.g. 44100, 22050, etc... */
+ ALInstrument *percussion; /* default percussion for GM */
ALInstrument *instArray[1]; /* ARRAY of instruments */
} ALBank;
typedef struct
-{ /* Note: sizeof won't be correct */
- s16 revision; /* format revision of this file */
- s16 bankCount; /* number of banks */
+{ /* Note: sizeof won't be correct */
+ s16 revision; /* format revision of this file */
+ s16 bankCount; /* number of banks */
ALBank *bankArray[1]; /* ARRAY of bank offsets */
} ALBankFile;
-void alBnkfNew(ALBankFile *f, u8 *table);
+void alBnkfNew(ALBankFile * f, u8 * table);
#endif
diff --git a/src/decomp/pc/libultra_internal.h b/src/decomp/pc/libultra_internal.h
index 5639c6a..787f1fd 100644
--- a/src/decomp/pc/libultra_internal.h
+++ b/src/decomp/pc/libultra_internal.h
@@ -11,12 +11,18 @@
#ifdef AVOID_UB
typedef struct OSThread_ListHead_s
{
- /*0x00*/ struct OSThread_s *next;
- /*0x04*/ OSPri priority;
- /*0x08*/ struct OSThread_s *queue;
- /*0x0C*/ struct OSThread_s *tlnext;
- /*0x10*/ struct OSThread_s *unk10;
- /*0x14*/ u32 unk14;
+ /*0x00*/
+ struct OSThread_s *next;
+ /*0x04*/
+ OSPri priority;
+ /*0x08*/
+ struct OSThread_s *queue;
+ /*0x0C*/
+ struct OSThread_s *tlnext;
+ /*0x10*/
+ struct OSThread_s *unk10;
+ /*0x14*/
+ u32 unk14;
} OSThread_ListHead;
// Now fix the symbols to the new one.
@@ -46,54 +52,91 @@ extern u32 D_80365E00[15];
extern u32 D_80365E3C;
#endif
-typedef struct {
+typedef struct
+{
u32 initialized; // probably something like initialized?
OSThread *mgrThread;
OSMesgQueue *cmdQueue;
OSMesgQueue *eventQueue;
OSMesgQueue *accessQueue;
+
s32 (*dma_func)(s32, u32, void *, size_t);
-#if defined(VERSION_EU) || defined(VERSION_SH)
- s32 (*edma_func)(OSPiHandle*, s32, u32, void *, size_t);
-#else
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ s32 (*edma_func)(OSPiHandle *, s32, u32, void *, size_t);
+ #else
u64 force_align;
-#endif
+ #endif
} OSMgrArgs;
s32 __osDisableInt(void);
+
void __osRestoreInt(s32);
+
void __osEnqueueAndYield(OSThread **);
+
void __osDequeueThread(OSThread **, OSThread *);
+
void __osEnqueueThread(OSThread **, OSThread *);
+
OSThread *__osPopThread(OSThread **);
+
s32 __osSiRawStartDma(s32, void *);
+
void __osSiCreateAccessQueue(void);
+
void __osSiGetAccess(void);
+
void __osSiRelAccess(void);
+
u32 __osProbeTLB(void *);
+
void __osPiCreateAccessQueue(void);
+
void __osPiGetAccess(void);
+
void __osSetSR(u32);
+
u32 __osGetSR(void);
+
void __osSetFpcCsr(u32);
+
s32 __osSiRawReadIo(void *, u32 *);
+
s32 __osSiRawWriteIo(void *, u32);
+
s32 osPiRawReadIo(u32 a0, u32 *a1);
+
void __osSpSetStatus(u32);
+
u32 __osSpGetStatus(void);
+
s32 __osSpSetPc(void *);
+
s32 __osSpDeviceBusy(void);
+
s32 __osSiDeviceBusy(void);
+
s32 __osSpRawStartDma(u32 dir, void *sp_ptr, void *dram_ptr, size_t size);
+
void __osViInit(void);
+
OSViContext *__osViGetCurrentContext(void);
+
OSViContext *__osViGetCurrentContext2(void);
+
void __osViSwapContext(void);
+
void __osSetTimerIntr(u64);
+
u64 __osInsertTimer(OSTimer *);
+
void __osSetCompare(u32);
+
s32 __osAiDeviceBusy(void);
+
void __osDispatchThread(void);
+
u32 __osGetCause(void);
+
s32 __osAtomicDec(u32 *);
#endif
diff --git a/src/decomp/pc/mixer.c b/src/decomp/pc/mixer.c
index 8c53ad4..b453b87 100644
--- a/src/decomp/pc/mixer.c
+++ b/src/decomp/pc/mixer.c
@@ -41,17 +41,18 @@
#define BUF_S16(a) (rspa.buf.as_s16 + (a) / sizeof(int16_t))
#endif
-static struct {
+static struct
+{
uint16_t in;
uint16_t out;
uint16_t nbytes;
-#ifdef NEW_AUDIO_UCODE
+ #ifdef NEW_AUDIO_UCODE
uint16_t vol[2];
uint16_t rate[2];
uint16_t vol_wet;
uint16_t rate_wet;
-#else
+ #else
int16_t vol[2];
uint16_t dry_right;
@@ -63,18 +64,19 @@ static struct {
int16_t vol_dry;
int16_t vol_wet;
-#endif
+ #endif
ADPCM_STATE *adpcm_loop_state;
int16_t adpcm_table[8][2][8];
-#ifdef NEW_AUDIO_UCODE
+ #ifdef NEW_AUDIO_UCODE
uint16_t filter_count;
int16_t filter[8];
-#endif
+ #endif
- union {
+ union
+ {
int16_t as_s16[BUF_SIZE / sizeof(int16_t)];
uint8_t as_u8[BUF_SIZE];
} buf;
@@ -115,97 +117,127 @@ static int16_t resample_table[64][4] = {
{0xffd8, 0x0e5f, 0x6696, 0x0b39}, {0xffdf, 0x0d46, 0x66ad, 0x0c39}
};
-static inline int16_t clamp16(int32_t v) {
- if (v < -0x8000) {
+static inline int16_t clamp16(int32_t v)
+{
+ if (v < -0x8000)
+ {
return -0x8000;
- } else if (v > 0x7fff) {
+ }
+ else if (v > 0x7fff)
+ {
return 0x7fff;
}
return (int16_t)v;
}
-static inline int32_t clamp32(int64_t v) {
- if (v < -0x7fffffff - 1) {
+static inline int32_t clamp32(int64_t v)
+{
+ if (v < -0x7fffffff - 1)
+ {
return -0x7fffffff - 1;
- } else if (v > 0x7fffffff) {
+ }
+ else if (v > 0x7fffffff)
+ {
return 0x7fffffff;
}
return (int32_t)v;
}
-void aClearBufferImpl(uint16_t addr, int nbytes) {
+void aClearBufferImpl(uint16_t addr, int nbytes)
+{
nbytes = ROUND_UP_16(nbytes);
memset(BUF_U8(addr), 0, nbytes);
}
#ifdef NEW_AUDIO_UCODE
-void aLoadBufferImpl(const void *source_addr, uint16_t dest_addr, uint16_t nbytes) {
+void aLoadBufferImpl(const void *source_addr, uint16_t dest_addr, uint16_t nbytes)
+{
memcpy(BUF_U8(dest_addr), source_addr, ROUND_DOWN_16(nbytes));
}
-void aSaveBufferImpl(uint16_t source_addr, int16_t *dest_addr, uint16_t nbytes) {
+void aSaveBufferImpl(uint16_t source_addr, int16_t *dest_addr, uint16_t nbytes)
+{
memcpy(dest_addr, BUF_S16(source_addr), ROUND_DOWN_16(nbytes));
}
#else
-void aLoadBufferImpl(const void *source_addr) {
- DEBUG_PRINT("aLoadBufferImpl()");
- DEBUG_PRINT("- source_addr: %x", source_addr);
+void aLoadBufferImpl(const void *source_addr)
+{
+ DEBUG_PRINT("aLoadBufferImpl()");
+ DEBUG_PRINT("- source_addr: %x", source_addr);
memcpy(BUF_U8(rspa.in), source_addr, ROUND_UP_8(rspa.nbytes));
}
-void aSaveBufferImpl(int16_t *dest_addr) {
+void aSaveBufferImpl(int16_t *dest_addr)
+{
memcpy(dest_addr, BUF_S16(rspa.out), ROUND_UP_8(rspa.nbytes));
}
#endif
-void aLoadADPCMImpl(int num_entries_times_16, const int16_t *book_source_addr) {
+void aLoadADPCMImpl(int num_entries_times_16, const int16_t *book_source_addr)
+{
memcpy(rspa.adpcm_table, book_source_addr, num_entries_times_16);
}
-void aSetBufferImpl(uint8_t flags, uint16_t in, uint16_t out, uint16_t nbytes) {
-#ifndef NEW_AUDIO_UCODE
- if (flags & A_AUX) {
+void aSetBufferImpl(uint8_t flags, uint16_t in, uint16_t out, uint16_t nbytes)
+{
+ #ifndef NEW_AUDIO_UCODE
+ if (flags & A_AUX)
+ {
rspa.dry_right = in;
rspa.wet_left = out;
rspa.wet_right = nbytes;
return;
}
-#endif
+ #endif
rspa.in = in;
rspa.out = out;
rspa.nbytes = nbytes;
}
#ifndef NEW_AUDIO_UCODE
-void aSetVolumeImpl(uint8_t flags, int16_t v, int16_t t, int16_t r) {
- if (flags & A_AUX) {
+void aSetVolumeImpl(uint8_t flags, int16_t v, int16_t t, int16_t r)
+{
+ if (flags & A_AUX)
+ {
rspa.vol_dry = v;
rspa.vol_wet = r;
- } else if (flags & A_VOL) {
- if (flags & A_LEFT) {
+ }
+ else if (flags & A_VOL)
+ {
+ if (flags & A_LEFT)
+ {
rspa.vol[0] = v;
- } else {
+ }
+ else
+ {
rspa.vol[1] = v;
}
- } else {
- if (flags & A_LEFT) {
+ }
+ else
+ {
+ if (flags & A_LEFT)
+ {
rspa.target[0] = v;
- rspa.rate[0] = (int32_t)((uint16_t)t << 16 | ((uint16_t)r));
- } else {
+ rspa.rate[0] = (uint16_t)t << 16 | (uint16_t)r;
+ }
+ else
+ {
rspa.target[1] = v;
- rspa.rate[1] = (int32_t)((uint16_t)t << 16 | ((uint16_t)r));
+ rspa.rate[1] = (uint16_t)t << 16 | (uint16_t)r;
}
}
}
#endif
#ifdef NEW_AUDIO_UCODE
-void aInterleaveImpl(uint16_t dest, uint16_t left, uint16_t right, uint16_t c) {
+void aInterleaveImpl(uint16_t dest, uint16_t left, uint16_t right, uint16_t c)
+{
int count = ROUND_UP_8(c) / sizeof(int16_t) / 4;
int16_t *l = BUF_S16(left);
int16_t *r = BUF_S16(right);
int16_t *d = BUF_S16(dest);
- while (count > 0) {
+ while (count > 0)
+ {
int16_t l0 = *l++;
int16_t l1 = *l++;
int16_t l2 = *l++;
@@ -226,12 +258,14 @@ void aInterleaveImpl(uint16_t dest, uint16_t left, uint16_t right, uint16_t c) {
}
}
#else
-void aInterleaveImpl(uint16_t left, uint16_t right) {
+void aInterleaveImpl(uint16_t left, uint16_t right)
+{
int count = ROUND_UP_16(rspa.nbytes) / sizeof(int16_t) / 8;
int16_t *l = BUF_S16(left);
int16_t *r = BUF_S16(right);
int16_t *d = BUF_S16(rspa.out);
- while (count > 0) {
+ while (count > 0)
+ {
int16_t l0 = *l++;
int16_t l1 = *l++;
int16_t l2 = *l++;
@@ -269,23 +303,26 @@ void aInterleaveImpl(uint16_t left, uint16_t right) {
}
#endif
-void aDMEMMoveImpl(uint16_t in_addr, uint16_t out_addr, int nbytes) {
+void aDMEMMoveImpl(uint16_t in_addr, uint16_t out_addr, int nbytes)
+{
nbytes = ROUND_UP_16(nbytes);
memmove(BUF_U8(out_addr), BUF_U8(in_addr), nbytes);
}
-void aSetLoopImpl(ADPCM_STATE *adpcm_loop_state) {
+void aSetLoopImpl(ADPCM_STATE *adpcm_loop_state)
+{
rspa.adpcm_loop_state = adpcm_loop_state;
}
-void aADPCMdecImpl(uint8_t flags, ADPCM_STATE state) {
-#if HAS_SSE41
+void aADPCMdecImpl(uint8_t flags, ADPCM_STATE state)
+{
+ #if HAS_SSE41
const __m128i tblrev = _mm_setr_epi8(12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1, -1, -1);
const __m128i pos0 = _mm_set_epi8(3, -1, 3, -1, 2, -1, 2, -1, 1, -1, 1, -1, 0, -1, 0, -1);
const __m128i pos1 = _mm_set_epi8(7, -1, 7, -1, 6, -1, 6, -1, 5, -1, 5, -1, 4, -1, 4, -1);
const __m128i mult = _mm_set_epi16(0x10, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0x01);
const __m128i mask = _mm_set1_epi16((int16_t)0xf000);
-#elif HAS_NEON
+ #elif HAS_NEON
static const int8_t pos0_data[] = {-1, 0, -1, 0, -1, 1, -1, 1, -1, 2, -1, 2, -1, 3, -1, 3};
static const int8_t pos1_data[] = {-1, 4, -1, 4, -1, 5, -1, 5, -1, 6, -1, 6, -1, 7, -1, 7};
static const int16_t mult_data[] = {0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10};
@@ -295,30 +332,36 @@ void aADPCMdecImpl(uint8_t flags, ADPCM_STATE state) {
const int16x8_t mult = vld1q_s16(mult_data);
const int16x8_t mask = vdupq_n_s16((int16_t)0xf000);
const int16x8_t table_prefix = vld1q_s16(table_prefix_data);
-#endif
+ #endif
uint8_t *in = BUF_U8(rspa.in);
int16_t *out = BUF_S16(rspa.out);
int nbytes = ROUND_UP_32(rspa.nbytes);
- if (flags & A_INIT) {
+ if (flags & A_INIT)
+ {
memset(out, 0, 16 * sizeof(int16_t));
- } else if (flags & A_LOOP) {
+ }
+ else if (flags & A_LOOP)
+ {
memcpy(out, rspa.adpcm_loop_state, 16 * sizeof(int16_t));
- } else {
+ }
+ else
+ {
memcpy(out, state, 16 * sizeof(int16_t));
}
out += 16;
-#if HAS_SSE41
+ #if HAS_SSE41
__m128i prev_interleaved = _mm_set1_epi32((uint16_t)out[-2] | ((uint16_t)out[-1] << 16));
//__m128i prev_interleaved = _mm_shuffle_epi32(_mm_loadu_si32(out - 2), 0); // GCC misses this?
-#elif HAS_NEON
+ #elif HAS_NEON
int16x8_t result = vld1q_s16(out - 8);
-#endif
- while (nbytes > 0) {
+ #endif
+ while (nbytes > 0)
+ {
int shift = *in >> 4; // should be in 0..12
int table_index = *in++ & 0xf; // should be in 0..7
- int16_t (*tbl)[8] = rspa.adpcm_table[table_index];
+ int16_t(*tbl)[8] = rspa.adpcm_table[table_index];
int i;
-#if HAS_SSE41
+ #if HAS_SSE41
// The _mm_loadu_si64 instruction was added in GCC 9, and results in the same
// asm as the following instructions, so better be compatible with old GCC.
//__m128i inv = _mm_loadu_si64(in);
@@ -341,7 +384,8 @@ void aADPCMdecImpl(uint8_t flags, ADPCM_STATE state) {
tblvec1_rev[6] = _mm_bsrli_si128(tblvec1_rev[0], 12);
tblvec1_rev[7] = _mm_bsrli_si128(tblvec1_rev[0], 14);
in += 8;
- for (i = 0; i < 2; i++) {
+ for (i = 0; i < 2; i++)
+ {
__m128i acc0 = _mm_madd_epi16(prev_interleaved, tbllo);
__m128i acc1 = _mm_madd_epi16(prev_interleaved, tblhi);
__m128i muls[8];
@@ -369,13 +413,15 @@ void aADPCMdecImpl(uint8_t flags, ADPCM_STATE state) {
prev_interleaved = _mm_shuffle_epi32(result, _MM_SHUFFLE(3, 3, 3, 3));
}
-#elif HAS_NEON
+ #elif HAS_NEON
int8x8_t inv = vld1_s8((int8_t *)in);
int16x8_t tblvec[2] = {vld1q_s16(tbl[0]), vld1q_s16(tbl[1])};
- int16x8_t invec[2] = {vreinterpretq_s16_s8(vcombine_s8(vtbl1_s8(inv, vget_low_s8(pos0)),
- vtbl1_s8(inv, vget_high_s8(pos0)))),
- vreinterpretq_s16_s8(vcombine_s8(vtbl1_s8(inv, vget_low_s8(pos1)),
- vtbl1_s8(inv, vget_high_s8(pos1))))};
+ int16x8_t invec[2] = {
+ vreinterpretq_s16_s8(vcombine_s8(vtbl1_s8(inv, vget_low_s8(pos0)),
+ vtbl1_s8(inv, vget_high_s8(pos0)))),
+ vreinterpretq_s16_s8(vcombine_s8(vtbl1_s8(inv, vget_low_s8(pos1)),
+ vtbl1_s8(inv, vget_high_s8(pos1))))
+ };
int16x8_t shiftcount = vdupq_n_s16(shift - 12); // negative means right shift
int16x8_t tblvec1[8];
@@ -394,7 +440,8 @@ void aADPCMdecImpl(uint8_t flags, ADPCM_STATE state) {
invec[0] = vqshlq_s16(invec[0], shiftcount);
invec[1] = vqshlq_s16(invec[1], shiftcount);
tblvec1[7] = table_prefix;
- for (i = 0; i < 2; i++) {
+ for (i = 0; i < 2; i++)
+ {
int32x4_t acc0;
int32x4_t acc1;
@@ -421,32 +468,37 @@ void aADPCMdecImpl(uint8_t flags, ADPCM_STATE state) {
vst1q_s16(out, result);
out += 8;
}
-#else
- for (i = 0; i < 2; i++) {
+ #else
+ for (i = 0; i < 2; i++)
+ {
int16_t ins[8];
int16_t prev1 = out[-1];
int16_t prev2 = out[-2];
int j, k;
- for (j = 0; j < 4; j++) {
+ for (j = 0; j < 4; j++)
+ {
ins[j * 2] = (((*in >> 4) << 28) >> 28) << shift;
ins[j * 2 + 1] = (((*in++ & 0xf) << 28) >> 28) << shift;
}
- for (j = 0; j < 8; j++) {
+ for (j = 0; j < 8; j++)
+ {
int32_t acc = tbl[0][j] * prev2 + tbl[1][j] * prev1 + (ins[j] << 11);
- for (k = 0; k < j; k++) {
- acc += tbl[1][((j - k) - 1)] * ins[k];
+ for (k = 0; k < j; k++)
+ {
+ acc += tbl[1][(j - k - 1)] * ins[k];
}
acc >>= 11;
*out++ = clamp16(acc);
}
}
-#endif
+ #endif
nbytes -= 16 * sizeof(int16_t);
}
memcpy(state, out - 16, 16 * sizeof(int16_t));
}
-void aResampleImpl(uint8_t flags, uint16_t pitch, RESAMPLE_STATE state) {
+void aResampleImpl(uint8_t flags, uint16_t pitch, RESAMPLE_STATE state)
+{
int16_t tmp[16];
int16_t *in_initial = BUF_S16(rspa.in);
int16_t *in = in_initial;
@@ -454,16 +506,20 @@ void aResampleImpl(uint8_t flags, uint16_t pitch, RESAMPLE_STATE state) {
int nbytes = ROUND_UP_16(rspa.nbytes);
uint32_t pitch_accumulator;
int i;
-#if !HAS_SSE41 && !HAS_NEON
+ #if !HAS_SSE41 && !HAS_NEON
int16_t *tbl;
int32_t sample;
-#endif
- if (flags & A_INIT) {
+ #endif
+ if (flags & A_INIT)
+ {
memset(tmp, 0, 5 * sizeof(int16_t));
- } else {
+ }
+ else
+ {
memcpy(tmp, state, 16 * sizeof(int16_t));
}
- if (flags & 2) {
+ if (flags & 2)
+ {
memcpy(in - 8, tmp + 8, 8 * sizeof(int16_t));
in -= tmp[5] / sizeof(int16_t);
}
@@ -471,7 +527,7 @@ void aResampleImpl(uint8_t flags, uint16_t pitch, RESAMPLE_STATE state) {
pitch_accumulator = (uint16_t)tmp[4];
memcpy(in, tmp, 4 * sizeof(int16_t));
-#if HAS_SSE41
+ #if HAS_SSE41
__m128i multiples = _mm_setr_epi16(0, 2, 4, 6, 8, 10, 12, 14);
__m128i pitchvec = _mm_set1_epi16((int16_t)pitch);
__m128i pitchvec_8_steps = _mm_set1_epi32((pitch << 1) * 8);
@@ -481,10 +537,11 @@ void aResampleImpl(uint8_t flags, uint16_t pitch, RESAMPLE_STATE state) {
__m128i acc_a = _mm_add_epi32(_mm_unpacklo_epi16(pl, ph), pitchacclo_vec);
__m128i acc_b = _mm_add_epi32(_mm_unpackhi_epi16(pl, ph), pitchacclo_vec);
- do {
+ do
+ {
__m128i tbl_positions = _mm_srli_epi16(_mm_packus_epi32(
- _mm_and_si128(acc_a, _mm_set1_epi32(0xffff)),
- _mm_and_si128(acc_b, _mm_set1_epi32(0xffff))), 10);
+ _mm_and_si128(acc_a, _mm_set1_epi32(0xffff)),
+ _mm_and_si128(acc_b, _mm_set1_epi32(0xffff))), 10);
__m128i in_positions = _mm_packus_epi32(_mm_srli_epi32(acc_a, 16), _mm_srli_epi32(acc_b, 16));
__m128i tbl_entries[4];
@@ -518,10 +575,11 @@ void aResampleImpl(uint8_t flags, uint16_t pitch, RESAMPLE_STATE state) {
acc_b = _mm_add_epi32(acc_b, pitchvec_8_steps);
out += 8;
nbytes -= 8 * sizeof(int16_t);
- } while (nbytes > 0);
+ }
+ while (nbytes > 0);
in += (uint16_t)_mm_extract_epi16(acc_a, 1);
pitch_accumulator = (uint16_t)_mm_extract_epi16(acc_a, 0);
-#elif HAS_NEON
+ #elif HAS_NEON
static const uint16_t multiples_data[8] = {0, 2, 4, 6, 8, 10, 12, 14};
uint16x8_t multiples = vld1q_u16(multiples_data);
uint32x4_t pitchvec_8_steps = vdupq_n_u32((pitch << 1) * 8);
@@ -529,7 +587,8 @@ void aResampleImpl(uint8_t flags, uint16_t pitch, RESAMPLE_STATE state) {
uint32x4_t acc_a = vmlal_n_u16(pitchacclo_vec, vget_low_u16(multiples), pitch);
uint32x4_t acc_b = vmlal_n_u16(pitchacclo_vec, vget_high_u16(multiples), pitch);
- do {
+ do
+ {
uint16x8x2_t unzipped = vuzpq_u16(vreinterpretq_u16_u32(acc_a), vreinterpretq_u16_u32(acc_b));
uint16x8_t tbl_positions = vshrq_n_u16(unzipped.val[0], 10);
uint16x8_t in_positions = unzipped.val[1];
@@ -564,12 +623,15 @@ void aResampleImpl(uint8_t flags, uint16_t pitch, RESAMPLE_STATE state) {
acc_b = vaddq_u32(acc_b, pitchvec_8_steps);
out += 8;
nbytes -= 8 * sizeof(int16_t);
- } while (nbytes > 0);
+ }
+ while (nbytes > 0);
in += vgetq_lane_u16(vreinterpretq_u16_u32(acc_a), 1);
pitch_accumulator = vgetq_lane_u16(vreinterpretq_u16_u32(acc_a), 0);
-#else
- do {
- for (i = 0; i < 8; i++) {
+ #else
+ do
+ {
+ for (i = 0; i < 8; i++)
+ {
tbl = resample_table[pitch_accumulator * 64 >> 16];
sample = ((in[0] * tbl[0] + 0x4000) >> 15) +
((in[1] * tbl[1] + 0x4000) >> 15) +
@@ -577,19 +639,21 @@ void aResampleImpl(uint8_t flags, uint16_t pitch, RESAMPLE_STATE state) {
((in[3] * tbl[3] + 0x4000) >> 15);
*out++ = clamp16(sample);
- pitch_accumulator += (pitch << 1);
+ pitch_accumulator += pitch << 1;
in += pitch_accumulator >> 16;
pitch_accumulator %= 0x10000;
}
nbytes -= 8 * sizeof(int16_t);
- } while (nbytes > 0);
-#endif
+ }
+ while (nbytes > 0);
+ #endif
state[4] = (int16_t)pitch_accumulator;
memcpy(state, in, 4 * sizeof(int16_t));
- i = (in - in_initial + 4) & 7;
+ i = in - in_initial + 4 & 7;
in -= i;
- if (i != 0) {
+ if (i != 0)
+ {
i = -8 - i;
}
state[5] = i;
@@ -597,22 +661,25 @@ void aResampleImpl(uint8_t flags, uint16_t pitch, RESAMPLE_STATE state) {
}
#ifdef NEW_AUDIO_UCODE
-void aEnvSetup1Impl(uint8_t initial_vol_wet, uint16_t rate_wet, uint16_t rate_left, uint16_t rate_right) {
+void aEnvSetup1Impl(uint8_t initial_vol_wet, uint16_t rate_wet, uint16_t rate_left, uint16_t rate_right)
+{
rspa.vol_wet = (uint16_t)(initial_vol_wet << 8);
rspa.rate_wet = rate_wet;
rspa.rate[0] = rate_left;
rspa.rate[1] = rate_right;
}
-void aEnvSetup2Impl(uint16_t initial_vol_left, uint16_t initial_vol_right) {
+void aEnvSetup2Impl(uint16_t initial_vol_left, uint16_t initial_vol_right)
+{
rspa.vol[0] = initial_vol_left;
rspa.vol[1] = initial_vol_right;
}
-void aEnvMixerImpl(uint16_t in_addr, uint16_t n_samples, bool swap_reverb,
- bool neg_left, bool neg_right,
- uint16_t dry_left_addr, uint16_t dry_right_addr,
- uint16_t wet_left_addr, uint16_t wet_right_addr)
+void aEnvMixerImpl(
+ uint16_t in_addr, uint16_t n_samples, bool swap_reverb,
+ bool neg_left, bool neg_right,
+ uint16_t dry_left_addr, uint16_t dry_right_addr,
+ uint16_t wet_left_addr, uint16_t wet_right_addr)
{
int16_t *in = BUF_S16(in_addr);
int16_t *dry[2] = {BUF_S16(dry_left_addr), BUF_S16(dry_right_addr)};
@@ -626,13 +693,19 @@ void aEnvMixerImpl(uint16_t in_addr, uint16_t n_samples, bool swap_reverb,
uint16_t vol_wet = rspa.vol_wet;
uint16_t rate_wet = rspa.rate_wet;
- do {
- for (int i = 0; i < 8; i++) {
- int16_t samples[2] = {*in, *in}; in++;
- for (int j = 0; j < 2; j++) {
+ do
+ {
+ for (int i = 0; i < 8; i++)
+ {
+ int16_t samples[2] = {*in, *in};
+ in++;
+ for (int j = 0; j < 2; j++)
+ {
samples[j] = (samples[j] * vols[j] >> 16) ^ negs[j];
- *dry[j] = clamp16(*dry[j] + samples[j]); dry[j]++;
- *wet[j] = clamp16(*wet[j] + (samples[swapped[j]] * vol_wet >> 16)); wet[j]++;
+ *dry[j] = clamp16(*dry[j] + samples[j]);
+ dry[j]++;
+ *wet[j] = clamp16(*wet[j] + (samples[swapped[j]] * vol_wet >> 16));
+ wet[j]++;
}
}
vols[0] += rates[0];
@@ -640,16 +713,18 @@ void aEnvMixerImpl(uint16_t in_addr, uint16_t n_samples, bool swap_reverb,
vol_wet += rate_wet;
n -= 8;
- } while (n > 0);
+ }
+ while (n > 0);
}
#else
-void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state) {
+void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state)
+{
int16_t *in = BUF_S16(rspa.in);
int16_t *dry[2] = {BUF_S16(rspa.out), BUF_S16(rspa.dry_right)};
int16_t *wet[2] = {BUF_S16(rspa.wet_left), BUF_S16(rspa.wet_right)};
int nbytes = ROUND_UP_16(rspa.nbytes);
-#if HAS_SSE41
+ #if HAS_SSE41
__m128 vols[2][2];
__m128i dry_factor;
__m128i wet_factor;
@@ -661,12 +736,14 @@ void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state) {
int c;
- if (flags & A_INIT) {
+ if (flags & A_INIT)
+ {
float vol_init[2] = {rspa.vol[0], rspa.vol[1]};
float rate_float[2] = {(float)rspa.rate[0] * (1.0f / 65536.0f), (float)rspa.rate[1] * (1.0f / 65536.0f)};
float step_diff[2] = {vol_init[0] * (rate_float[0] - 1.0f), vol_init[1] * (rate_float[1] - 1.0f)};
- for (c = 0; c < 2; c++) {
+ for (c = 0; c < 2; c++)
+ {
vols[c][0] = _mm_add_ps(
_mm_set_ps1(vol_init[c]),
_mm_mul_ps(_mm_set1_ps(step_diff[c]), _mm_setr_ps(1.0f / 8.0f, 2.0f / 8.0f, 3.0f / 8.0f, 4.0f / 8.0f)));
@@ -688,7 +765,9 @@ void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state) {
state[37] = rspa.target[1];
state[38] = rspa.vol_dry;
state[39] = rspa.vol_wet;
- } else {
+ }
+ else
+ {
float floats[2];
vols[0][0] = _mm_loadu_ps((const float *)state);
vols[0][1] = _mm_loadu_ps((const float *)(state + 8));
@@ -704,14 +783,19 @@ void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state) {
dry_factor = _mm_set1_epi16(state[38]);
wet_factor = _mm_set1_epi16(state[39]);
}
- do {
+ do
+ {
in_loaded = _mm_loadu_si128((const __m128i *)in);
in += 8;
- for (c = 0; c < 2; c++) {
- if (increasing[c]) {
+ for (c = 0; c < 2; c++)
+ {
+ if (increasing[c])
+ {
vols[c][0] = _mm_min_ps(vols[c][0], target[c]);
vols[c][1] = _mm_min_ps(vols[c][1], target[c]);
- } else {
+ }
+ else
+ {
vols[c][0] = _mm_max_ps(vols[c][0], target[c]);
vols[c][1] = _mm_max_ps(vols[c][1], target[c]);
}
@@ -723,7 +807,8 @@ void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state) {
_mm_mulhrs_epi16(in_loaded, _mm_mulhrs_epi16(vol_s16, dry_factor))));
dry[c] += 8;
- if (flags & A_AUX) {
+ if (flags & A_AUX)
+ {
_mm_storeu_si128((__m128i *)wet[c],
_mm_adds_epi16(
_mm_loadu_si128((const __m128i *)wet[c]),
@@ -736,13 +821,14 @@ void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state) {
}
nbytes -= 8 * sizeof(int16_t);
- } while (nbytes > 0);
+ }
+ while (nbytes > 0);
_mm_storeu_ps((float *)state, vols[0][0]);
_mm_storeu_ps((float *)(state + 8), vols[0][1]);
_mm_storeu_ps((float *)(state + 16), vols[1][0]);
_mm_storeu_ps((float *)(state + 24), vols[1][1]);
-#elif HAS_NEON
+ #elif HAS_NEON
float32x4_t vols[2][2];
int16_t dry_factor;
int16_t wet_factor;
@@ -754,15 +840,19 @@ void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state) {
int c;
- if (flags & A_INIT) {
+ if (flags & A_INIT)
+ {
float vol_init[2] = {rspa.vol[0], rspa.vol[1]};
float rate_float[2] = {(float)rspa.rate[0] * (1.0f / 65536.0f), (float)rspa.rate[1] * (1.0f / 65536.0f)};
float step_diff[2] = {vol_init[0] * (rate_float[0] - 1.0f), vol_init[1] * (rate_float[1] - 1.0f)};
- static const float step_dividers_data[2][4] = {{1.0f / 8.0f, 2.0f / 8.0f, 3.0f / 8.0f, 4.0f / 8.0f},
- {5.0f / 8.0f, 6.0f / 8.0f, 7.0f / 8.0f, 8.0f / 8.0f}};
+ static const float step_dividers_data[2][4] = {
+ {1.0f / 8.0f, 2.0f / 8.0f, 3.0f / 8.0f, 4.0f / 8.0f},
+ {5.0f / 8.0f, 6.0f / 8.0f, 7.0f / 8.0f, 8.0f / 8.0f}
+ };
float32x4_t step_dividers[2] = {vld1q_f32(step_dividers_data[0]), vld1q_f32(step_dividers_data[1])};
- for (c = 0; c < 2; c++) {
+ for (c = 0; c < 2; c++)
+ {
vols[c][0] = vaddq_f32(vdupq_n_f32(vol_init[c]), vmulq_n_f32(step_dividers[0], step_diff[c]));
vols[c][1] = vaddq_f32(vdupq_n_f32(vol_init[c]), vmulq_n_f32(step_dividers[1], step_diff[c]));
increasing[c] = rate_float[c] >= 1.0f;
@@ -779,7 +869,9 @@ void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state) {
state[37] = rspa.target[1];
state[38] = rspa.vol_dry;
state[39] = rspa.vol_wet;
- } else {
+ }
+ else
+ {
vols[0][0] = vreinterpretq_f32_s16(vld1q_s16(state));
vols[0][1] = vreinterpretq_f32_s16(vld1q_s16(state + 8));
vols[1][0] = vreinterpretq_f32_s16(vld1q_s16(state + 16));
@@ -794,14 +886,19 @@ void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state) {
wet_factor = state[39];
}
- do {
+ do
+ {
in_loaded = vld1q_s16(in);
in += 8;
- for (c = 0; c < 2; c++) {
- if (increasing[c]) {
+ for (c = 0; c < 2; c++)
+ {
+ if (increasing[c])
+ {
vols[c][0] = vminq_f32(vols[c][0], target[c]);
vols[c][1] = vminq_f32(vols[c][1], target[c]);
- } else {
+ }
+ else
+ {
vols[c][0] = vmaxq_f32(vols[c][0], target[c]);
vols[c][1] = vmaxq_f32(vols[c][1], target[c]);
}
@@ -809,7 +906,8 @@ void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state) {
vol_s16 = vcombine_s16(vqmovn_s32(vcvtq_s32_f32(vols[c][0])), vqmovn_s32(vcvtq_s32_f32(vols[c][1])));
vst1q_s16(dry[c], vqaddq_s16(vld1q_s16(dry[c]), vqrdmulhq_s16(in_loaded, vqrdmulhq_n_s16(vol_s16, dry_factor))));
dry[c] += 8;
- if (flags & A_AUX) {
+ if (flags & A_AUX)
+ {
vst1q_s16(wet[c], vqaddq_s16(vld1q_s16(wet[c]), vqrdmulhq_s16(in_loaded, vqrdmulhq_n_s16(vol_s16, wet_factor))));
wet[c] += 8;
}
@@ -818,13 +916,14 @@ void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state) {
}
nbytes -= 8 * sizeof(int16_t);
- } while (nbytes > 0);
+ }
+ while (nbytes > 0);
vst1q_s16(state, vreinterpretq_s16_f32(vols[0][0]));
vst1q_s16(state + 8, vreinterpretq_s16_f32(vols[0][1]));
vst1q_s16(state + 16, vreinterpretq_s16_f32(vols[1][0]));
vst1q_s16(state + 24, vreinterpretq_s16_f32(vols[1][1]));
-#else
+ #else
int16_t target[2];
int32_t rate[2];
int16_t vol_dry, vol_wet;
@@ -834,7 +933,8 @@ void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state) {
int c, i;
- if (flags & A_INIT) {
+ if (flags & A_INIT)
+ {
target[0] = rspa.target[0];
target[1] = rspa.target[1];
rate[0] = rspa.rate[0];
@@ -844,51 +944,65 @@ void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state) {
step_diff[0] = rspa.vol[0] * (rate[0] - 0x10000) / 8;
step_diff[1] = rspa.vol[0] * (rate[1] - 0x10000) / 8;
- for (i = 0; i < 8; i++) {
+ for (i = 0; i < 8; i++)
+ {
vols[0][i] = clamp32((int64_t)(rspa.vol[0] << 16) + step_diff[0] * (i + 1));
vols[1][i] = clamp32((int64_t)(rspa.vol[1] << 16) + step_diff[1] * (i + 1));
}
- } else {
+ }
+ else
+ {
memcpy(vols[0], state, 32);
memcpy(vols[1], state + 16, 32);
target[0] = state[32];
target[1] = state[35];
- rate[0] = (state[33] << 16) | (uint16_t)state[34];
- rate[1] = (state[36] << 16) | (uint16_t)state[37];
+ rate[0] = state[33] << 16 | (uint16_t)state[34];
+ rate[1] = state[36] << 16 | (uint16_t)state[37];
vol_dry = state[38];
vol_wet = state[39];
}
- do {
- for (c = 0; c < 2; c++) {
- for (i = 0; i < 8; i++) {
- if ((rate[c] >> 16) > 0) {
+ do
+ {
+ for (c = 0; c < 2; c++)
+ {
+ for (i = 0; i < 8; i++)
+ {
+ if (rate[c] >> 16 > 0)
+ {
// Increasing volume
- if ((vols[c][i] >> 16) > target[c]) {
+ if (vols[c][i] >> 16 > target[c])
+ {
vols[c][i] = target[c] << 16;
}
- } else {
+ }
+ else
+ {
// Decreasing volume
- if ((vols[c][i] >> 16) < target[c]) {
+ if (vols[c][i] >> 16 < target[c])
+ {
vols[c][i] = target[c] << 16;
}
}
dry[c][i] = clamp16((dry[c][i] * 0x7fff + in[i] * (((vols[c][i] >> 16) * vol_dry + 0x4000) >> 15) + 0x4000) >> 15);
- if (flags & A_AUX) {
+ if (flags & A_AUX)
+ {
wet[c][i] = clamp16((wet[c][i] * 0x7fff + in[i] * (((vols[c][i] >> 16) * vol_wet + 0x4000) >> 15) + 0x4000) >> 15);
}
vols[c][i] = clamp32((int64_t)vols[c][i] * rate[c] >> 16);
}
dry[c] += 8;
- if (flags & A_AUX) {
+ if (flags & A_AUX)
+ {
wet[c] += 8;
}
}
nbytes -= 16;
in += 8;
- } while (nbytes > 0);
+ }
+ while (nbytes > 0);
memcpy(state, vols[0], 32);
memcpy(state + 16, vols[1], 32);
@@ -900,30 +1014,34 @@ void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state) {
state[37] = (int16_t)rate[1];
state[38] = vol_dry;
state[39] = vol_wet;
-#endif
+ #endif
}
#endif
#ifdef NEW_AUDIO_UCODE
-void aMixImpl(int16_t gain, uint16_t in_addr, uint16_t out_addr, uint16_t count) {
+void aMixImpl(int16_t gain, uint16_t in_addr, uint16_t out_addr, uint16_t count)
+{
int nbytes = ROUND_UP_32(ROUND_DOWN_16(count));
#else
-void aMixImpl(int16_t gain, uint16_t in_addr, uint16_t out_addr) {
+void aMixImpl(int16_t gain, uint16_t in_addr, uint16_t out_addr)
+{
int nbytes = ROUND_UP_32(rspa.nbytes);
-#endif
+ #endif
int16_t *in = BUF_S16(in_addr);
int16_t *out = BUF_S16(out_addr);
-#if HAS_SSE41
+ #if HAS_SSE41
__m128i gain_vec = _mm_set1_epi16(gain);
-#elif !HAS_NEON
+ #elif !HAS_NEON
int i;
int32_t sample;
-#endif
+ #endif
-#if !HAS_NEON
- if (gain == -0x8000) {
- while (nbytes > 0) {
-#if HAS_SSE41
+ #if !HAS_NEON
+ if (gain == -0x8000)
+ {
+ while (nbytes > 0)
+ {
+ #if HAS_SSE41
__m128i out1, out2, in1, in2;
out1 = _mm_loadu_si128((const __m128i *)out);
out2 = _mm_loadu_si128((const __m128i *)(out + 8));
@@ -938,20 +1056,22 @@ void aMixImpl(int16_t gain, uint16_t in_addr, uint16_t out_addr) {
out += 16;
in += 16;
-#else
- for (i = 0; i < 16; i++) {
+ #else
+ for (i = 0; i < 16; i++)
+ {
sample = *out - *in++;
*out++ = clamp16(sample);
}
-#endif
+ #endif
nbytes -= 16 * sizeof(int16_t);
}
}
-#endif
+ #endif
- while (nbytes > 0) {
-#if HAS_SSE41
+ while (nbytes > 0)
+ {
+ #if HAS_SSE41
__m128i out1, out2, in1, in2;
out1 = _mm_loadu_si128((const __m128i *)out);
out2 = _mm_loadu_si128((const __m128i *)(out + 8));
@@ -966,7 +1086,7 @@ void aMixImpl(int16_t gain, uint16_t in_addr, uint16_t out_addr) {
out += 16;
in += 16;
-#elif HAS_NEON
+ #elif HAS_NEON
int16x8_t out1, out2, in1, in2;
out1 = vld1q_s16(out);
out2 = vld1q_s16(out + 8);
@@ -981,32 +1101,40 @@ void aMixImpl(int16_t gain, uint16_t in_addr, uint16_t out_addr) {
out += 16;
in += 16;
-#else
- for (i = 0; i < 16; i++) {
- sample = ((*out * 0x7fff + *in++ * gain) + 0x4000) >> 15;
+ #else
+ for (i = 0; i < 16; i++)
+ {
+ sample = (*out * 0x7fff + *in++ * gain + 0x4000) >> 15;
*out++ = clamp16(sample);
}
-#endif
+ #endif
nbytes -= 16 * sizeof(int16_t);
}
}
#ifdef NEW_AUDIO_UCODE
-void aS8DecImpl(uint8_t flags, ADPCM_STATE state) {
+void aS8DecImpl(uint8_t flags, ADPCM_STATE state)
+{
uint8_t *in = BUF_U8(rspa.in);
int16_t *out = BUF_S16(rspa.out);
int nbytes = ROUND_UP_32(rspa.nbytes);
- if (flags & A_INIT) {
+ if (flags & A_INIT)
+ {
memset(out, 0, 16 * sizeof(int16_t));
- } else if (flags & A_LOOP) {
+ }
+ else if (flags & A_LOOP)
+ {
memcpy(out, rspa.adpcm_loop_state, 16 * sizeof(int16_t));
- } else {
+ }
+ else
+ {
memcpy(out, state, 16 * sizeof(int16_t));
}
out += 16;
- while (nbytes > 0) {
+ while (nbytes > 0)
+ {
*out++ = (int16_t)(*in++ << 8);
*out++ = (int16_t)(*in++ << 8);
*out++ = (int16_t)(*in++ << 8);
@@ -1030,114 +1158,167 @@ void aS8DecImpl(uint8_t flags, ADPCM_STATE state) {
memcpy(state, out - 16, 16 * sizeof(int16_t));
}
-void aAddMixerImpl(uint16_t in_addr, uint16_t out_addr, uint16_t count) {
+void aAddMixerImpl(uint16_t in_addr, uint16_t out_addr, uint16_t count)
+{
int16_t *in = BUF_S16(in_addr);
int16_t *out = BUF_S16(out_addr);
int nbytes = ROUND_UP_64(ROUND_DOWN_16(count));
- do {
- *out = clamp16(*out + *in++); out++;
- *out = clamp16(*out + *in++); out++;
- *out = clamp16(*out + *in++); out++;
- *out = clamp16(*out + *in++); out++;
- *out = clamp16(*out + *in++); out++;
- *out = clamp16(*out + *in++); out++;
- *out = clamp16(*out + *in++); out++;
- *out = clamp16(*out + *in++); out++;
- *out = clamp16(*out + *in++); out++;
- *out = clamp16(*out + *in++); out++;
- *out = clamp16(*out + *in++); out++;
- *out = clamp16(*out + *in++); out++;
- *out = clamp16(*out + *in++); out++;
- *out = clamp16(*out + *in++); out++;
- *out = clamp16(*out + *in++); out++;
- *out = clamp16(*out + *in++); out++;
+ do
+ {
+ *out = clamp16(*out + *in++);
+ out++;
+ *out = clamp16(*out + *in++);
+ out++;
+ *out = clamp16(*out + *in++);
+ out++;
+ *out = clamp16(*out + *in++);
+ out++;
+ *out = clamp16(*out + *in++);
+ out++;
+ *out = clamp16(*out + *in++);
+ out++;
+ *out = clamp16(*out + *in++);
+ out++;
+ *out = clamp16(*out + *in++);
+ out++;
+ *out = clamp16(*out + *in++);
+ out++;
+ *out = clamp16(*out + *in++);
+ out++;
+ *out = clamp16(*out + *in++);
+ out++;
+ *out = clamp16(*out + *in++);
+ out++;
+ *out = clamp16(*out + *in++);
+ out++;
+ *out = clamp16(*out + *in++);
+ out++;
+ *out = clamp16(*out + *in++);
+ out++;
+ *out = clamp16(*out + *in++);
+ out++;
nbytes -= 16 * sizeof(int16_t);
- } while (nbytes > 0);
+ }
+ while (nbytes > 0);
}
-void aDuplicateImpl(uint16_t in_addr, uint16_t out_addr, uint16_t count) {
+void aDuplicateImpl(uint16_t in_addr, uint16_t out_addr, uint16_t count)
+{
uint8_t *in = BUF_U8(in_addr);
uint8_t *out = BUF_U8(out_addr);
uint8_t tmp[128];
memcpy(tmp, in, 128);
- do {
+ do
+ {
memcpy(out, tmp, 128);
out += 128;
- } while (count-- > 0);
+ }
+ while (count-- > 0);
}
-void aDMEMMove2Impl(uint8_t t, uint16_t in_addr, uint16_t out_addr, uint16_t count) {
+void aDMEMMove2Impl(uint8_t t, uint16_t in_addr, uint16_t out_addr, uint16_t count)
+{
uint8_t *in = BUF_U8(in_addr);
uint8_t *out = BUF_U8(out_addr);
int nbytes = ROUND_UP_32(count);
- do {
+ do
+ {
memmove(out, in, nbytes);
in += nbytes;
out += nbytes;
- } while (t-- > 0);
+ }
+ while (t-- > 0);
}
-void aResampleZohImpl(uint16_t pitch, uint16_t start_fract) {
+void aResampleZohImpl(uint16_t pitch, uint16_t start_fract)
+{
int16_t *in = BUF_S16(rspa.in);
int16_t *out = BUF_S16(rspa.out);
int nbytes = ROUND_UP_8(rspa.nbytes);
uint32_t pos = start_fract;
uint32_t pitch_add = pitch << 2;
- do {
- *out++ = in[pos >> 17]; pos += pitch_add;
- *out++ = in[pos >> 17]; pos += pitch_add;
- *out++ = in[pos >> 17]; pos += pitch_add;
- *out++ = in[pos >> 17]; pos += pitch_add;
+ do
+ {
+ *out++ = in[pos >> 17];
+ pos += pitch_add;
+ *out++ = in[pos >> 17];
+ pos += pitch_add;
+ *out++ = in[pos >> 17];
+ pos += pitch_add;
+ *out++ = in[pos >> 17];
+ pos += pitch_add;
nbytes -= 4 * sizeof(int16_t);
- } while (nbytes > 0);
+ }
+ while (nbytes > 0);
}
-void aDownsampleHalfImpl(uint16_t n_samples, uint16_t in_addr, uint16_t out_addr) {
+void aDownsampleHalfImpl(uint16_t n_samples, uint16_t in_addr, uint16_t out_addr)
+{
int16_t *in = BUF_S16(in_addr);
int16_t *out = BUF_S16(out_addr);
int n = ROUND_UP_8(n_samples);
- do {
- *out++ = *in++; in++;
- *out++ = *in++; in++;
- *out++ = *in++; in++;
- *out++ = *in++; in++;
- *out++ = *in++; in++;
- *out++ = *in++; in++;
- *out++ = *in++; in++;
- *out++ = *in++; in++;
+ do
+ {
+ *out++ = *in++;
+ in++;
+ *out++ = *in++;
+ in++;
+ *out++ = *in++;
+ in++;
+ *out++ = *in++;
+ in++;
+ *out++ = *in++;
+ in++;
+ *out++ = *in++;
+ in++;
+ *out++ = *in++;
+ in++;
+ *out++ = *in++;
+ in++;
n -= 8;
- } while (n > 0);
+ }
+ while (n > 0);
}
-void aFilterImpl(uint8_t flags, uint16_t count_or_buf, int16_t state_or_filter[8]) {
- if (flags > A_INIT) {
+void aFilterImpl(uint8_t flags, uint16_t count_or_buf, int16_t state_or_filter[8])
+{
+ if (flags > A_INIT)
+ {
rspa.filter_count = ROUND_UP_16(count_or_buf);
memcpy(rspa.filter, state_or_filter, sizeof(rspa.filter));
- } else {
+ }
+ else
+ {
int16_t tmp[16];
int count = rspa.filter_count;
int16_t *buf = BUF_S16(count_or_buf);
- if (flags == A_INIT) {
+ if (flags == A_INIT)
+ {
memset(tmp, 0, 8 * sizeof(int16_t));
- } else {
+ }
+ else
+ {
memcpy(tmp, state_or_filter, 8 * sizeof(int16_t));
}
- do {
+ do
+ {
memcpy(tmp + 8, buf, 8 * sizeof(int16_t));
- for (int i = 0; i < 8; i++) {
+ for (int i = 0; i < 8; i++)
+ {
int64_t sample = 0x4000; // round term
int16_t in = tmp[8 + i];
- for (int j = 1; j <= 8; j++) {
+ for (int j = 1; j <= 8; j++)
+ {
sample += in * tmp[8 + i - j];
}
buf[i] = clamp16((int32_t)(sample >> 15));
@@ -1146,43 +1327,59 @@ void aFilterImpl(uint8_t flags, uint16_t count_or_buf, int16_t state_or_filter[8
buf += 8;
count -= 8 * sizeof(int16_t);
- } while (count > 0);
+ }
+ while (count > 0);
memcpy(state_or_filter, tmp, 8 * sizeof(int16_t));
}
}
-void aHiLoGainImpl(uint8_t g, uint16_t count, uint16_t addr) {
+void aHiLoGainImpl(uint8_t g, uint16_t count, uint16_t addr)
+{
int16_t *samples = BUF_S16(addr);
int nbytes = ROUND_UP_32(count);
- do {
- *samples = clamp16((*samples * g) >> 4); samples++;
- *samples = clamp16((*samples * g) >> 4); samples++;
- *samples = clamp16((*samples * g) >> 4); samples++;
- *samples = clamp16((*samples * g) >> 4); samples++;
- *samples = clamp16((*samples * g) >> 4); samples++;
- *samples = clamp16((*samples * g) >> 4); samples++;
- *samples = clamp16((*samples * g) >> 4); samples++;
- *samples = clamp16((*samples * g) >> 4); samples++;
+ do
+ {
+ *samples = clamp16((*samples * g) >> 4);
+ samples++;
+ *samples = clamp16((*samples * g) >> 4);
+ samples++;
+ *samples = clamp16((*samples * g) >> 4);
+ samples++;
+ *samples = clamp16((*samples * g) >> 4);
+ samples++;
+ *samples = clamp16((*samples * g) >> 4);
+ samples++;
+ *samples = clamp16((*samples * g) >> 4);
+ samples++;
+ *samples = clamp16((*samples * g) >> 4);
+ samples++;
+ *samples = clamp16((*samples * g) >> 4);
+ samples++;
nbytes -= 8;
- } while (nbytes > 0);
+ }
+ while (nbytes > 0);
}
-void aUnknown25Impl(uint8_t f, uint16_t count, uint16_t out_addr, uint16_t in_addr) {
+void aUnknown25Impl(uint8_t f, uint16_t count, uint16_t out_addr, uint16_t in_addr)
+{
int nbytes = ROUND_UP_64(count);
int16_t *in = BUF_S16(in_addr + f);
int16_t *out = BUF_S16(out_addr);
int16_t tbl[32];
memcpy(tbl, in, 32 * sizeof(int16_t));
- do {
- for (int i = 0; i < 32; i++) {
+ do
+ {
+ for (int i = 0; i < 32; i++)
+ {
out[i] = clamp16(out[i] * tbl[i]);
}
out += 32;
nbytes -= 32 * sizeof(int16_t);
- } while (nbytes > 0);
+ }
+ while (nbytes > 0);
}
#endif
diff --git a/src/decomp/pc/mixer.h b/src/decomp/pc/mixer.h
index 5debc7f..4eba7b1 100644
--- a/src/decomp/pc/mixer.h
+++ b/src/decomp/pc/mixer.h
@@ -37,19 +37,30 @@
#undef aUnknown25
void aClearBufferImpl(uint16_t addr, int nbytes);
+
void aLoadADPCMImpl(int num_entries_times_16, const int16_t *book_source_addr);
+
void aSetBufferImpl(uint8_t flags, uint16_t in, uint16_t out, uint16_t nbytes);
+
void aDMEMMoveImpl(uint16_t in_addr, uint16_t out_addr, int nbytes);
-void aSetLoopImpl(ADPCM_STATE *adpcm_loop_state);
+
+void aSetLoopImpl(ADPCM_STATE * adpcm_loop_state);
+
void aADPCMdecImpl(uint8_t flags, ADPCM_STATE state);
+
void aResampleImpl(uint8_t flags, uint16_t pitch, RESAMPLE_STATE state);
#ifndef NEW_AUDIO_UCODE
void aSetVolumeImpl(uint8_t flags, int16_t v, int16_t t, int16_t r);
+
void aLoadBufferImpl(const void *source_addr);
-void aSaveBufferImpl(int16_t *dest_addr);
+
+void aSaveBufferImpl(int16_t * dest_addr);
+
void aInterleaveImpl(uint16_t left, uint16_t right);
+
void aMixImpl(int16_t gain, uint16_t in_addr, uint16_t out_addr);
+
void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state);
#else
void aLoadBufferImpl(const void *source_addr, uint16_t dest_addr, uint16_t nbytes);
@@ -58,10 +69,11 @@ void aInterleaveImpl(uint16_t dest, uint16_t left, uint16_t right, uint16_t c);
void aMixImpl(int16_t gain, uint16_t in_addr, uint16_t out_addr, uint16_t count);
void aEnvSetup1Impl(uint8_t initial_vol_wet, uint16_t rate_wet, uint16_t rate_left, uint16_t rate_right);
void aEnvSetup2Impl(uint16_t initial_vol_left, uint16_t initial_vol_right);
-void aEnvMixerImpl(uint16_t in_addr, uint16_t n_samples, bool swap_reverb,
- bool neg_left, bool neg_right,
- uint16_t dry_left_addr, uint16_t dry_right_addr,
- uint16_t wet_left_addr, uint16_t wet_right_addr);
+void aEnvMixerImpl(
+ uint16_t in_addr, uint16_t n_samples, bool swap_reverb,
+ bool neg_left, bool neg_right,
+ uint16_t dry_left_addr, uint16_t dry_right_addr,
+ uint16_t wet_left_addr, uint16_t wet_right_addr);
void aS8DecImpl(uint8_t flags, ADPCM_STATE state);
void aAddMixerImpl(uint16_t in_addr, uint16_t out_addr, uint16_t count);
void aDuplicateImpl(uint16_t in_addr, uint16_t out_addr, uint16_t count);
diff --git a/src/decomp/pc/ultra_reimplementation.c b/src/decomp/pc/ultra_reimplementation.c
index 4957cce..e5d3363 100644
--- a/src/decomp/pc/ultra_reimplementation.c
+++ b/src/decomp/pc/ultra_reimplementation.c
@@ -11,14 +11,17 @@ extern OSMgrArgs piMgrArgs;
u64 osClockRate = 62500000;
-s32 osPiStartDma(UNUSED OSIoMesg *mb, UNUSED s32 priority, UNUSED s32 direction,
- uintptr_t devAddr, void *vAddr, size_t nbytes,
- UNUSED OSMesgQueue *mq) {
- memcpy(vAddr, (const void *) devAddr, nbytes);
+s32 osPiStartDma(
+ UNUSED OSIoMesg *mb, UNUSED s32 priority, UNUSED s32 direction,
+ uintptr_t devAddr, void *vAddr, size_t nbytes,
+ UNUSED OSMesgQueue *mq)
+{
+ memcpy(vAddr, (const void *)devAddr, nbytes);
return 0;
}
-void osCreateMesgQueue(OSMesgQueue *mq, OSMesg *msgBuf, s32 count) {
+void osCreateMesgQueue(OSMesgQueue *mq, OSMesg *msgBuf, s32 count)
+{
mq->validCount = 0;
mq->first = 0;
mq->msgCount = count;
@@ -26,191 +29,245 @@ void osCreateMesgQueue(OSMesgQueue *mq, OSMesg *msgBuf, s32 count) {
return;
}
-void osSetEventMesg(UNUSED OSEvent e, UNUSED OSMesgQueue *mq, UNUSED OSMesg msg) {
+void osSetEventMesg(UNUSED OSEvent e, UNUSED OSMesgQueue *mq, UNUSED OSMesg msg)
+{
}
-s32 osJamMesg(UNUSED OSMesgQueue *mq, UNUSED OSMesg msg, UNUSED s32 flag) {
+
+s32 osJamMesg(UNUSED OSMesgQueue *mq, UNUSED OSMesg msg, UNUSED s32 flag)
+{
return 0;
}
-s32 osSendMesg(UNUSED OSMesgQueue *mq, UNUSED OSMesg msg, UNUSED s32 flag) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
+
+s32 osSendMesg(UNUSED OSMesgQueue *mq, UNUSED OSMesg msg, UNUSED s32 flag)
+{
+ #if defined(VERSION_EU) || defined(VERSION_SH)
s32 index;
- if (mq->validCount >= mq->msgCount) {
+ if (mq->validCount >= mq->msgCount)
+ {
return -1;
}
index = (mq->first + mq->validCount) % mq->msgCount;
mq->msg[index] = msg;
mq->validCount++;
-#endif
+ #endif
return 0;
}
-s32 osRecvMesg(UNUSED OSMesgQueue *mq, UNUSED OSMesg *msg, UNUSED s32 flag) {
-#if defined(VERSION_EU) || defined(VERSION_SH)
- if (mq->validCount == 0) {
+
+s32 osRecvMesg(UNUSED OSMesgQueue *mq, UNUSED OSMesg *msg, UNUSED s32 flag)
+{
+ #if defined(VERSION_EU) || defined(VERSION_SH)
+ if (mq->validCount == 0)
+ {
return -1;
}
- if (msg != NULL) {
+ if (msg != NULL)
+ {
*msg = *(mq->first + mq->msg);
}
mq->first = (mq->first + 1) % mq->msgCount;
mq->validCount--;
-#endif
+ #endif
return 0;
}
-uintptr_t osVirtualToPhysical(void *addr) {
- return (uintptr_t) addr;
+uintptr_t osVirtualToPhysical(void *addr)
+{
+ return (uintptr_t)addr;
}
-void osCreateViManager(UNUSED OSPri pri) {
-}
-void osViSetMode(UNUSED OSViMode *mode) {
-}
-void osViSetEvent(UNUSED OSMesgQueue *mq, UNUSED OSMesg msg, UNUSED u32 retraceCount) {
-}
-void osViBlack(UNUSED u8 active) {
-}
-void osViSetSpecialFeatures(UNUSED u32 func) {
-}
-void osViSwapBuffer(UNUSED void *vaddr) {
+void osCreateViManager(UNUSED OSPri pri)
+{
}
-OSTime osGetTime(void) {
+void osViSetMode(UNUSED OSViMode *mode)
+{
+}
+
+void osViSetEvent(UNUSED OSMesgQueue *mq, UNUSED OSMesg msg, UNUSED u32 retraceCount)
+{
+}
+
+void osViBlack(UNUSED u8 active)
+{
+}
+
+void osViSetSpecialFeatures(UNUSED u32 func)
+{
+}
+
+void osViSwapBuffer(UNUSED void *vaddr)
+{
+}
+
+OSTime osGetTime(void)
+{
return 0;
}
-void osWritebackDCacheAll(void) {
+void osWritebackDCacheAll(void)
+{
}
-void osWritebackDCache(UNUSED void *a, UNUSED size_t b) {
+void osWritebackDCache(UNUSED void *a, UNUSED size_t b)
+{
}
-void osInvalDCache(UNUSED void *a, UNUSED size_t b) {
+void osInvalDCache(UNUSED void *a, UNUSED size_t b)
+{
}
-u32 osGetCount(void) {
+u32 osGetCount(void)
+{
static u32 counter;
return counter++;
}
-s32 osAiSetFrequency(u32 freq) {
+s32 osAiSetFrequency(u32 freq)
+{
u32 a1;
s32 a2;
u32 D_8033491C;
-#ifdef VERSION_EU
+ #ifdef VERSION_EU
D_8033491C = 0x02E6025C;
-#else
+ #else
D_8033491C = 0x02E6D354;
-#endif
+ #endif
- a1 = D_8033491C / (float) freq + .5f;
+ a1 = D_8033491C / (float)freq + .5f;
- if (a1 < 0x84) {
+ if (a1 < 0x84)
+ {
return -1;
}
- a2 = (a1 / 66) & 0xff;
- if (a2 > 16) {
+ a2 = a1 / 66 & 0xff;
+ if (a2 > 16)
+ {
a2 = 16;
}
- return D_8033491C / (s32) a1;
+ return D_8033491C / (s32)a1;
}
-s32 osEepromProbe(UNUSED OSMesgQueue *mq) {
+s32 osEepromProbe(UNUSED OSMesgQueue *mq)
+{
return 1;
}
-s32 osEepromLongRead(UNUSED OSMesgQueue *mq, u8 address, u8 *buffer, int nbytes) {
+s32 osEepromLongRead(UNUSED OSMesgQueue *mq, u8 address, u8 *buffer, int nbytes)
+{
u8 content[512];
s32 ret = -1;
-#ifdef TARGET_WEB
+ #ifdef TARGET_WEB
if (EM_ASM_INT({
var s = localStorage.sm64_save_file;
- if (s && s.length === 684) {
+ if (s && s.length == = 684) {
try {
var binary = atob(s);
- if (binary.length === 512) {
+ if (binary.length == = 512) {
for (var i = 0; i < 512; i++) {
- HEAPU8[$0 + i] = binary.charCodeAt(i);
- }
+ HEAPU8[$0 + i] = binary.charCodeAt(i);
+
+
+ }
return 1;
- }
- } catch (e) {
- }
- }
+
+
+ }
+ } catch (e) {
+ }
+ }
return 0;
- }, content)) {
+
+
+ }, content))
+ {
memcpy(buffer, content + address * 8, nbytes);
ret = 0;
}
-#else
+ #else
FILE *fp = fopen("sm64_save_file.bin", "rb");
- if (fp == NULL) {
+ if (fp == NULL)
+ {
return -1;
}
- if (fread(content, 1, 512, fp) == 512) {
+ if (fread(content, 1, 512, fp) == 512)
+ {
memcpy(buffer, content + address * 8, nbytes);
ret = 0;
}
fclose(fp);
-#endif
+ #endif
return ret;
}
-s32 osEepromLongWrite(UNUSED OSMesgQueue *mq, u8 address, u8 *buffer, int nbytes) {
+s32 osEepromLongWrite(UNUSED OSMesgQueue *mq, u8 address, u8 *buffer, int nbytes)
+{
u8 content[512] = {0};
- if (address != 0 || nbytes != 512) {
+ if (address != 0 || nbytes != 512)
+ {
osEepromLongRead(mq, 0, content, 512);
}
memcpy(content + address * 8, buffer, nbytes);
-#ifdef TARGET_WEB
+ #ifdef TARGET_WEB
EM_ASM({
var str = "";
for (var i = 0; i < 512; i++) {
- str += String.fromCharCode(HEAPU8[$0 + i]);
- }
- localStorage.sm64_save_file = btoa(str);
- }, content);
+ str += String.fromCharCode(HEAPU8[$0 + i]);
+
+
+ }
+ localStorage.sm64_save_file = btoa(str);
+
+
+ }, content);
s32 ret = 0;
-#else
- FILE* fp = fopen("sm64_save_file.bin", "wb");
- if (fp == NULL) {
+ #else
+ FILE *fp = fopen("sm64_save_file.bin", "wb");
+ if (fp == NULL)
+ {
return -1;
}
s32 ret = fwrite(content, 1, 512, fp) == 512 ? 0 : -1;
fclose(fp);
-#endif
+ #endif
return ret;
}
s32 gNumVblanks;
-s32 osMotorInit(UNUSED OSMesgQueue *mq, UNUSED void *pfs, UNUSED int channel) {
+s32 osMotorInit(UNUSED OSMesgQueue *mq, UNUSED void *pfs, UNUSED int channel)
+{
return 0;
}
-s32 osMotorStart(UNUSED void *pfs) {
+s32 osMotorStart(UNUSED void *pfs)
+{
return 0;
}
-s32 osMotorStop(UNUSED void *pfs) {
+s32 osMotorStop(UNUSED void *pfs)
+{
return 0;
}
-OSPiHandle *osCartRomInit(void) {
+OSPiHandle *osCartRomInit(void)
+{
static OSPiHandle handle;
return &handle;
}
-OSPiHandle *osDriveRomInit(void) {
+OSPiHandle *osDriveRomInit(void)
+{
static OSPiHandle handle;
return &handle;
}
-s32 osEPiStartDma(UNUSED OSPiHandle *pihandle, OSIoMesg *mb, UNUSED s32 direction) {
- memcpy(mb->dramAddr, (const void *) mb->devAddr, mb->size);
+s32 osEPiStartDma(UNUSED OSPiHandle *pihandle, OSIoMesg *mb, UNUSED s32 direction)
+{
+ memcpy(mb->dramAddr, (const void *)mb->devAddr, mb->size);
osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK);
}
diff --git a/src/decomp/shim.h b/src/decomp/shim.h
index 41ead3e..6fa33a8 100644
--- a/src/decomp/shim.h
+++ b/src/decomp/shim.h
@@ -37,30 +37,80 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
-static void enable_time_stop() {}
-static void disable_time_stop() {}
-static void *segmented_to_virtual(const void *addr) { return (void*)addr; }
-static void *virtual_to_segmented(u32 segment, const void *addr) { return (void*)addr; }
-static void func_80320A4C(u8 bankIndex, u8 arg1) {}
-static void raise_background_noise(s32 a) {}
-static void lower_background_noise(s32 a) {}
-static void set_camera_mode(struct Camera *c, s16 mode, s16 frames) {}
-static void print_text_fmt_int(s32 x, s32 y, const char *str, s32 n) {}
+static void enable_time_stop()
+{
+}
+
+static void disable_time_stop()
+{
+}
+
+static void *segmented_to_virtual(const void *addr) { return (void *)addr; }
+static void *virtual_to_segmented(u32 segment, const void *addr) { return (void *)addr; }
+
+static void func_80320A4C(u8 bankIndex, u8 arg1)
+{
+}
+
+static void raise_background_noise(s32 a)
+{
+}
+
+static void lower_background_noise(s32 a)
+{
+}
+
+static void set_camera_mode(struct Camera *c, s16 mode, s16 frames)
+{
+}
+
+static void print_text_fmt_int(s32 x, s32 y, const char *str, s32 n)
+{
+}
+
static s16 level_trigger_warp(struct MarioState *m, s32 warpOp) { return 0; }
//static void play_cap_music(u16 seqArgs) {}
//static void fadeout_cap_music(void) {}
//static void stop_cap_music(void) {}
-static void play_infinite_stairs_music(void) {}
+static void play_infinite_stairs_music(void)
+{
+}
+
static s32 save_file_get_total_star_count(s32 fileIndex, s32 minCourse, s32 maxCourse) { return 0; }
static u32 save_file_get_flags(void) { return 0; }
-static void save_file_set_flags(u32 flags) {}
-static void save_file_clear_flags(u32 flags) {}
-static void spawn_wind_particles(s16 pitch, s16 yaw) {}
-static void set_camera_shake_from_hit(s16 shake) {}
-static void load_level_init_text(u32 arg) {}
-static void spawn_default_star(f32 sp20, f32 sp24, f32 sp28) {}
-static void play_shell_music(void) {}
-static void stop_shell_music(void) {}
+
+static void save_file_set_flags(u32 flags)
+{
+}
+
+static void save_file_clear_flags(u32 flags)
+{
+}
+
+static void spawn_wind_particles(s16 pitch, s16 yaw)
+{
+}
+
+static void set_camera_shake_from_hit(s16 shake)
+{
+}
+
+static void load_level_init_text(u32 arg)
+{
+}
+
+static void spawn_default_star(f32 sp20, f32 sp24, f32 sp28)
+{
+}
+
+static void play_shell_music(void)
+{
+}
+
+static void stop_shell_music(void)
+{
+}
+
static u16 level_control_timer(s32 timerOp) { return 0; }
-#pragma GCC diagnostic pop
\ No newline at end of file
+#pragma GCC diagnostic pop
diff --git a/src/decomp/tools/convTypes.h b/src/decomp/tools/convTypes.h
index 63dc5c8..70b652d 100644
--- a/src/decomp/tools/convTypes.h
+++ b/src/decomp/tools/convTypes.h
@@ -24,74 +24,91 @@ struct CBook
short table[32]; // 8 * order * npredictors
};
-struct CSample{
+struct CSample
+{
unsigned int zero;
uintptr_t addr;
- struct CLoop* loop; // must not be null
- struct CBook* book; // must not be null
+ struct CLoop *loop; // must not be null
+ struct CBook *book; // must not be null
unsigned int sample_size;
};
-struct CSound{
- struct CSample* sample_addr;
+struct CSound
+{
+ struct CSample *sample_addr;
float tuning;
};
-struct delay_arg{
+struct delay_arg
+{
unsigned short delay;
unsigned short arg;
};
-struct CEnvelope{
+struct CEnvelope
+{
struct delay_arg delay_args[1]; // array of [(delay,arg)]
};
-struct CDrum{
+struct CDrum
+{
unsigned char release_rate;
unsigned char pan;
unsigned char loaded;
unsigned char pad;
struct CSound snd;
- struct CEnvelope* env_addr;
+ struct CEnvelope *env_addr;
};
-struct CInstrument{
+struct CInstrument
+{
unsigned char loaded;
unsigned char normal_range_lo;
unsigned char normal_range_hi;
unsigned char release_rate;
- struct CEnvelope* env_addr;
+ struct CEnvelope *env_addr;
struct CSound sound_lo;
struct CSound sound_med;
struct CSound sound_hi;
};
-struct TBL{
- unsigned char* data;
+struct TBL
+{
+ unsigned char *data;
};
-struct SEQ{
- unsigned char* data;
+struct SEQ
+{
+ unsigned char *data;
};
-struct CTL
+struct CTL
{
unsigned int numInstruments;
unsigned int numDrums;
unsigned int shared;
unsigned int iso_date;
- struct CDrum** drum_pointers;
- struct CInstrument* instrument_pointers[1];
+ struct CDrum **drum_pointers;
+ struct CInstrument *instrument_pointers[1];
};
-struct seqObject{
- uintptr_t offset __attribute__((aligned (8)));
- unsigned int len __attribute__((aligned (8)));
+struct seqObject
+{
+ uintptr_t offset __attribute__((aligned (8)
+
+ )
+ );
+
+ unsigned int len __attribute__((aligned (8)
+
+ )
+ );
};
-struct seqFile{
+struct seqFile
+{
unsigned short revision;
unsigned short seqCount;
- unsigned int pad;
+ unsigned int pad;
struct seqObject seqArray[1];
-} __attribute__((aligned (16)));
\ No newline at end of file
+} __attribute__((aligned(16)));
\ No newline at end of file
diff --git a/src/decomp/tools/convUtils.c b/src/decomp/tools/convUtils.c
index b8a0578..111f2c5 100644
--- a/src/decomp/tools/convUtils.c
+++ b/src/decomp/tools/convUtils.c
@@ -16,111 +16,135 @@
* https://github.com/n64decomp/sm64/blob/1372ae1bb7cbedc03df366393188f4f05dcfc422/tools/assemble_sound.py
* https://github.com/Retro64Mod/libsm64-retro64
*/
-
+
#define ALIGN16(val) (((val) + 0xF) & ~0xF)
-unsigned char* gCtlSeqs;
+unsigned char *gCtlSeqs;
-struct seqFile* parse_seqfile(unsigned char* seq){ /* Read SeqFile data */
+struct seqFile *parse_seqfile(unsigned char *seq)
+{ /* Read SeqFile data */
short revision = read_u16_be(seq);
short bankCount = read_u16_be(seq + 2);
- unsigned int size = sizeof(struct seqFile) + (bankCount-1) * sizeof(struct seqObject);
+ unsigned int size = sizeof(struct seqFile) + (bankCount - 1) * sizeof(struct seqObject);
- struct seqFile* seqFile = (struct seqFile*)calloc(size, 1);
+ struct seqFile *seqFile = calloc(size, 1);
seqFile->revision = revision;
seqFile->seqCount = bankCount;
- for (int i = 0; i < bankCount; i++){ // read bank offsets and sizes
+ for (int i = 0; i < bankCount; i++)
+ { // read bank offsets and sizes
seqFile->seqArray[i].offset = (uintptr_t)read_u32_be(seq + 4 + i * 8);
seqFile->seqArray[i].len = read_u32_be((seq + 4 + i * 8 + 4));
}
- if (revision == TYPE_CTL){
+ if (revision == TYPE_CTL)
+ {
// CTL file, contains instrument and drum data, this is really the only one that needs to be parsed, the rest only needs a header change
- gCtlSeqs = (unsigned char*)calloc(0x20B40, 1); // We only really need 0x20AD0 bytes but still
+ gCtlSeqs = (unsigned char *)calloc(0x20B40, 1); // We only really need 0x20AD0 bytes but still
uintptr_t pos = (uintptr_t)gCtlSeqs;
- for (int i = 0; i < bankCount; i++){
+ for (int i = 0; i < bankCount; i++)
+ {
uintptr_t start = pos;
- struct CTL* ptr = parse_ctl_data(seq+(seqFile->seqArray[i].offset), &pos);
+ struct CTL *ptr = parse_ctl_data(seq + seqFile->seqArray[i].offset, &pos);
seqFile->seqArray[i].offset = (uintptr_t)ptr;
seqFile->seqArray[i].len = (unsigned int)(pos - start);
}
- }else if (revision == TYPE_TBL){
+ }
+ else if (revision == TYPE_TBL)
+ {
// TBL file, contains raw audio data
- for (int i = 0; i < bankCount; i++){
- seqFile->seqArray[i].offset = (uintptr_t)(seq+(seqFile->seqArray[i].offset));
+ for (int i = 0; i < bankCount; i++)
+ {
+ seqFile->seqArray[i].offset = (uintptr_t)(seq + seqFile->seqArray[i].offset);
}
- }else if (revision == TYPE_SEQ){
+ }
+ else if (revision == TYPE_SEQ)
+ {
// SEQ file, contains music files (*.m64)
- for (int i = 0; i < bankCount; i++){
- seqFile->seqArray[i].offset = (uintptr_t)(seq+(seqFile->seqArray[i].offset));
+ for (int i = 0; i < bankCount; i++)
+ {
+ seqFile->seqArray[i].offset = (uintptr_t)(seq + seqFile->seqArray[i].offset);
}
}
return seqFile;
}
-void ctl_free(){
+void ctl_free()
+{
free(gCtlSeqs);
}
-void snd_ptrs_to_offsets(struct CSound* snd, uintptr_t ctlData){
- struct CSample* smp = snd->sample_addr;
- if((uintptr_t)(smp->loop) > ctlData)
- smp->loop = (struct CLoop*)((uintptr_t)(smp->loop) - ctlData);
- if((uintptr_t)(smp->book) > ctlData)
- smp->book = (struct CBook*)((uintptr_t)(smp->book) - ctlData);
- snd->sample_addr = (struct CSample*)((uintptr_t)(snd->sample_addr) - ctlData);
+void snd_ptrs_to_offsets(struct CSound *snd, uintptr_t ctlData)
+{
+ struct CSample *smp = snd->sample_addr;
+ if ((uintptr_t)smp->loop > ctlData)
+ smp->loop = (struct CLoop *)((uintptr_t)smp->loop - ctlData);
+ if ((uintptr_t)smp->book > ctlData)
+ smp->book = (struct CBook *)((uintptr_t)smp->book - ctlData);
+ snd->sample_addr = (struct CSample *)((uintptr_t)snd->sample_addr - ctlData);
}
-void ptrs_to_offsets(struct seqFile* ctl){
- if (ctl->revision != TYPE_CTL){
+void ptrs_to_offsets(struct seqFile *ctl)
+{
+ if (ctl->revision != TYPE_CTL)
+ {
return;
}
- for (int i = 0; i < ctl->seqCount; i++){
- struct CTL* ptr = (struct CTL*)ctl->seqArray[i].offset;
+ for (int i = 0; i < ctl->seqCount; i++)
+ {
+ struct CTL *ptr = (struct CTL *)ctl->seqArray[i].offset;
uintptr_t ctlData = (uintptr_t)ptr + 0x10;
// find all samples in the CTL file
- for (int j = 0; j < ptr->numInstruments; j++){
- struct CInstrument* inst = ptr->instrument_pointers[j];
- if (inst==0x0)
+ for (int j = 0; j < ptr->numInstruments; j++)
+ {
+ struct CInstrument *inst = ptr->instrument_pointers[j];
+ if (inst == 0x0)
continue; // null instrument.
- inst->env_addr = (struct CEnvelope*)((uintptr_t)inst->env_addr - ctlData);
- if (inst->sound_hi.sample_addr!=0x0){
- snd_ptrs_to_offsets(&(inst->sound_hi), ctlData);
+ inst->env_addr = (struct CEnvelope *)((uintptr_t)inst->env_addr - ctlData);
+ if (inst->sound_hi.sample_addr != 0x0)
+ {
+ snd_ptrs_to_offsets(&inst->sound_hi, ctlData);
}
- if (inst->sound_med.sample_addr!=0x0){
- snd_ptrs_to_offsets(&(inst->sound_med), ctlData);
+ if (inst->sound_med.sample_addr != 0x0)
+ {
+ snd_ptrs_to_offsets(&inst->sound_med, ctlData);
}
- if (inst->sound_lo.sample_addr!=0x0){
- snd_ptrs_to_offsets(&(inst->sound_lo), ctlData);
+ if (inst->sound_lo.sample_addr != 0x0)
+ {
+ snd_ptrs_to_offsets(&inst->sound_lo, ctlData);
}
- ptr->instrument_pointers[j] = (struct CInstrument*)((uintptr_t)(inst) - ctlData);
+ ptr->instrument_pointers[j] = (struct CInstrument *)((uintptr_t)inst - ctlData);
}
- if(ptr->numDrums != 0){
- for (int j = 0; j < ptr->numDrums; j++){
- struct CDrum* drum = ptr->drum_pointers[j];
- if (drum==0x0)
+ if (ptr->numDrums != 0)
+ {
+ for (int j = 0; j < ptr->numDrums; j++)
+ {
+ struct CDrum *drum = ptr->drum_pointers[j];
+ if (drum == 0x0)
continue; // null drum.
- drum->env_addr = (struct CEnvelope*)((uintptr_t)drum->env_addr - ctlData);
- if (drum->snd.sample_addr!=0x0){
- snd_ptrs_to_offsets(&(drum->snd), ctlData);
+ drum->env_addr = (struct CEnvelope *)((uintptr_t)drum->env_addr - ctlData);
+ if (drum->snd.sample_addr != 0x0)
+ {
+ snd_ptrs_to_offsets(&drum->snd, ctlData);
}
- ptr->drum_pointers[j] = (struct CDrum*)((uintptr_t)(drum) - ctlData);
+ ptr->drum_pointers[j] = (struct CDrum *)((uintptr_t)drum - ctlData);
}
- ptr->drum_pointers = (struct CDrum**)((uintptr_t)(ptr->drum_pointers) - ctlData);
+ ptr->drum_pointers = (struct CDrum **)((uintptr_t)ptr->drum_pointers - ctlData);
}
}
}
-struct CLoop* parse_loop(unsigned char* loop, uintptr_t* pos){
+struct CLoop *parse_loop(unsigned char *loop, uintptr_t *pos)
+{
uint32_t count = read_u32_be(loop + 8); // variable is signed, but the data is being read as unsigned.
unsigned int size = sizeof(struct CLoop) - 4;
- if(count != 0){
+ if (count != 0)
+ {
size = sizeof(struct CLoop) - 4 + sizeof(short) * 16;
}
- struct CLoop* loop_ptr = (struct CLoop*)(*pos);
+ struct CLoop *loop_ptr = (struct CLoop *)*pos;
*pos += size;
*pos = ALIGN16(*pos);
@@ -129,128 +153,148 @@ struct CLoop* parse_loop(unsigned char* loop, uintptr_t* pos){
loop_ptr->count = count;
loop_ptr->pad = read_u32_be(loop + 12);
- if (loop_ptr->count!=0){
- for (int i = 0;i<16;i++){
- loop_ptr->state[i]=read_u16_be(loop + 16 + i*2);
+ if (loop_ptr->count != 0)
+ {
+ for (int i = 0; i < 16; i++)
+ {
+ loop_ptr->state[i] = read_u16_be(loop + 16 + i * 2);
}
}
return loop_ptr;
}
-struct CBook* parse_book(unsigned char* book, uintptr_t* pos){
- struct CBook* book_ptr = (struct CBook*)(*pos);
+struct CBook *parse_book(unsigned char *book, uintptr_t *pos)
+{
+ struct CBook *book_ptr = (struct CBook *)*pos;
*pos += sizeof(struct CBook);
*pos = ALIGN16(*pos);
book_ptr->order = read_u32_be(book);
book_ptr->npredictors = read_u32_be(book + 4); // both are signed
- unsigned char* table_data = book+8;
- for (int i = 0; i < 8 * book_ptr->order * book_ptr->npredictors; i ++){
+ unsigned char *table_data = book + 8;
+ for (int i = 0; i < 8 * book_ptr->order * book_ptr->npredictors; i++)
+ {
book_ptr->table[i] = read_u16_be(table_data + i * 2);
}
return book_ptr;
}
-struct CSample* parse_sample(unsigned char* sample,unsigned char* ctl, uintptr_t* pos){
- struct CSample* samp = (struct CSample*)(*pos);
+struct CSample *parse_sample(unsigned char *sample, unsigned char *ctl, uintptr_t *pos)
+{
+ struct CSample *samp = (struct CSample *)*pos;
*pos += sizeof(struct CSample);
*pos = ALIGN16(*pos);
- samp->zero=read_u32_be(sample);
- samp->addr=read_u32_be(sample+4);
- samp->loop=(struct CLoop*)read_u32_be(sample+8);// loop address
- samp->book=(struct CBook*)read_u32_be(sample+12);// book address
- samp->sample_size=read_u32_be(sample+16);
+ samp->zero = read_u32_be(sample);
+ samp->addr = read_u32_be(sample + 4);
+ samp->loop = (struct CLoop *)read_u32_be(sample + 8); // loop address
+ samp->book = (struct CBook *)read_u32_be(sample + 12); // book address
+ samp->sample_size = read_u32_be(sample + 16);
- samp->book=parse_book(ctl+((uintptr_t)samp->book), pos);
- samp->loop=parse_loop(ctl+((uintptr_t)samp->loop), pos);
+ samp->book = parse_book(ctl + (uintptr_t)samp->book, pos);
+ samp->loop = parse_loop(ctl + (uintptr_t)samp->loop, pos);
return samp;
}
-struct CSound* parse_sound(unsigned char* sound,unsigned char* ctl, uintptr_t* pos, uintptr_t sndPos, struct SampleList* samples){
- struct CSound* snd = (struct CSound*)(sndPos);
- snd->sample_addr=(struct CSample*)read_u32_be(sound);
- snd->tuning = (float)read_f32_be(sound+4);
+struct CSound *parse_sound(unsigned char *sound, unsigned char *ctl, uintptr_t *pos, uintptr_t sndPos, struct SampleList *samples)
+{
+ struct CSound *snd = (struct CSound *)sndPos;
+ snd->sample_addr = (struct CSample *)read_u32_be(sound);
+ snd->tuning = read_f32_be(sound + 4);
// if sample_addr is 0 then the sound is null
- if (snd->sample_addr!=0){
+ if (snd->sample_addr != 0)
+ {
int smpIndex = -1;
- for(int i = 0; i < samples->count; i++){
- if(samples->orig_addrs[i] == (uintptr_t)(snd->sample_addr)){
+ for (int i = 0; i < samples->count; i++)
+ {
+ if (samples->orig_addrs[i] == (uintptr_t)snd->sample_addr)
+ {
smpIndex = i;
break;
}
}
- if(smpIndex < 0){
- samples->orig_addrs[samples->count] = (uintptr_t)(snd->sample_addr);
- snd->sample_addr = parse_sample(ctl+((uintptr_t)snd->sample_addr),ctl, pos);
+ if (smpIndex < 0)
+ {
+ samples->orig_addrs[samples->count] = (uintptr_t)snd->sample_addr;
+ snd->sample_addr = parse_sample(ctl + (uintptr_t)snd->sample_addr, ctl, pos);
samples->addrs[samples->count] = snd->sample_addr;
samples->count++;
- } else {
+ }
+ else
+ {
snd->sample_addr = samples->addrs[smpIndex];
}
}
return snd;
}
-struct CDrum* parse_drum(unsigned char* drum,unsigned char* ctl, uintptr_t* pos, struct SampleList* samples){ /* Read Drum data */
- struct CDrum* drumData = malloc(sizeof(struct CDrum));
+struct CDrum *parse_drum(unsigned char *drum, unsigned char *ctl, uintptr_t *pos, struct SampleList *samples)
+{ /* Read Drum data */
+ struct CDrum *drumData = malloc(sizeof(struct CDrum));
drumData->release_rate = drum[0];
drumData->pan = drum[1];
drumData->loaded = drum[2];
drumData->pad = drum[3];
- drumData->snd=*parse_sound(drum+4,ctl, pos, (uintptr_t)&drumData->snd, samples);
- drumData->env_addr=(struct CEnvelope*)read_u32_be(drum+12);
+ drumData->snd = *parse_sound(drum + 4, ctl, pos, (uintptr_t) & drumData->snd, samples);
+ drumData->env_addr = (struct CEnvelope *)read_u32_be(drum + 12);
return drumData;
}
-struct CEnvelope* parse_envelope(unsigned char* env, uintptr_t* pos, int* size){
+struct CEnvelope *parse_envelope(unsigned char *env, uintptr_t *pos, int *size)
+{
int count = 0;
- while(1){
+ while (1)
+ {
unsigned short delay = read_u16_le(env + count * 4);
unsigned short arg = read_u16_le(env + count * 4 + 2);
- unsigned short delayC = (-delay);
+ unsigned short delayC = -delay;
count++;
if ((1 <= delayC && delayC <= 3) || delay == 0)
break;
}
- *size = sizeof(struct CEnvelope) + sizeof(struct delay_arg) * (count-1);
- struct CEnvelope* envData = malloc(*size);
- for (int i = 0; i < count; i++){
+ *size = sizeof(struct CEnvelope) + sizeof(struct delay_arg) * (count - 1);
+ struct CEnvelope *envData = malloc(*size);
+ for (int i = 0; i < count; i++)
+ {
envData->delay_args[i].delay = read_u16_le(env + i * 4);
envData->delay_args[i].arg = read_u16_le(env + i * 4 + 2);
}
return envData;
}
-struct CInstrument* parse_instrument(unsigned char* instrument,unsigned char* ctl, uintptr_t* pos, struct SampleList* samples){
- struct CInstrument* inst = malloc(sizeof(struct CInstrument));
+struct CInstrument *parse_instrument(unsigned char *instrument, unsigned char *ctl, uintptr_t *pos, struct SampleList *samples)
+{
+ struct CInstrument *inst = malloc(sizeof(struct CInstrument));
inst->loaded = instrument[0];
inst->normal_range_lo = instrument[1];
inst->normal_range_hi = instrument[2];
inst->release_rate = instrument[3];
- inst->env_addr=(struct CEnvelope*)read_u32_be(instrument+4);
- inst->sound_lo=*parse_sound(instrument+8,ctl, pos, (uintptr_t)&(inst->sound_lo), samples);
- inst->sound_med=*parse_sound(instrument+16,ctl, pos, (uintptr_t)&(inst->sound_med), samples);
- inst->sound_hi=*parse_sound(instrument+24,ctl, pos, (uintptr_t)&(inst->sound_hi), samples);
+ inst->env_addr = (struct CEnvelope *)read_u32_be(instrument + 4);
+ inst->sound_lo = *parse_sound(instrument + 8, ctl, pos, (uintptr_t) & inst->sound_lo, samples);
+ inst->sound_med = *parse_sound(instrument + 16, ctl, pos, (uintptr_t) & inst->sound_med, samples);
+ inst->sound_hi = *parse_sound(instrument + 24, ctl, pos, (uintptr_t) & inst->sound_hi, samples);
return inst;
}
-struct TBL* parse_tbl_data(unsigned char* tbl){
- struct TBL* tblData = malloc(sizeof(struct TBL));
+struct TBL *parse_tbl_data(unsigned char *tbl)
+{
+ struct TBL *tblData = malloc(sizeof(struct TBL));
tblData->data = tbl;
return tblData;
}
- struct SEQ* parse_seq_data(unsigned char* seq){
- struct SEQ* seqData = malloc(sizeof(struct SEQ));
+struct SEQ *parse_seq_data(unsigned char *seq)
+{
+ struct SEQ *seqData = malloc(sizeof(struct SEQ));
seqData->data = seq;
return seqData;
}
-struct CTL* parse_ctl_data(unsigned char* ctlData, uintptr_t* pos){
- int instruments=read_u32_be(ctlData);
- unsigned int size = sizeof(struct CTL) + sizeof(struct CInstrument*) * (instruments-1);
- struct CTL* ctl = (struct CTL*)(*pos);
+struct CTL *parse_ctl_data(unsigned char *ctlData, uintptr_t *pos)
+{
+ int instruments = read_u32_be(ctlData);
+ unsigned int size = sizeof(struct CTL) + sizeof(struct CInstrument *) * (instruments - 1);
+ struct CTL *ctl = (struct CTL *)*pos;
*pos += size;
*pos = ALIGN16(*pos);
#pragma region Parse CTL header
@@ -264,27 +308,32 @@ struct CTL* parse_ctl_data(unsigned char* ctlData, uintptr_t* pos){
int envCount = 0;
samples.count = 0;
// header parsed, now read data
- if(ctl->numDrums != 0) {
- ctl->drum_pointers= (struct CDrum**)(*pos);
- size = sizeof(struct CDrum*) * ctl->numDrums;
+ if (ctl->numDrums != 0)
+ {
+ ctl->drum_pointers = (struct CDrum **)*pos;
+ size = sizeof(struct CDrum *) * ctl->numDrums;
*pos += size;
*pos = ALIGN16(*pos);
int drumTablePtr = read_u32_be(ctlData + 16);
- for (int i = 0; i < ctl->numDrums; i++){
- uint32_t data = read_u32_be(ctlData + drumTablePtr+16 + i * 4);
-
- struct CDrum* d = parse_drum(ctlData+data+16,ctlData+16, pos, &samples);
+ for (int i = 0; i < ctl->numDrums; i++)
+ {
+ uint32_t data = read_u32_be(ctlData + drumTablePtr + 16 + i * 4);
+
+ struct CDrum *d = parse_drum(ctlData + data + 16, ctlData + 16, pos, &samples);
bool used = 0;
- for(int j = 0; j < envCount; j++){
- if(envData[j].orig == (uintptr_t)d->env_addr){
+ for (int j = 0; j < envCount; j++)
+ {
+ if (envData[j].orig == (uintptr_t)d->env_addr)
+ {
used = 1;
break;
}
}
- if(used == 0){
+ if (used == 0)
+ {
int size = 0;
- unsigned char* addr = ctlData+((uintptr_t)d->env_addr)+16;
- envData[envCount].orig = (uintptr_t)(d->env_addr);
+ unsigned char *addr = ctlData + (uintptr_t)d->env_addr + 16;
+ envData[envCount].orig = (uintptr_t)d->env_addr;
envData[envCount].addr = parse_envelope(addr, pos, &size);
envData[envCount].size = size;
envCount++;
@@ -292,27 +341,33 @@ struct CTL* parse_ctl_data(unsigned char* ctlData, uintptr_t* pos){
ctl->drum_pointers[i] = d;
}
*pos = ALIGN16(*pos);
- } else {
- ctl->drum_pointers= NULL;
+ }
+ else
+ {
+ ctl->drum_pointers = NULL;
}
// parse instrument data
int instTablePtr = 4;
- for (int i = 0; i < ctl->numInstruments; i++){
+ for (int i = 0; i < ctl->numInstruments; i++)
+ {
uint32_t data = read_u32_be(ctlData + 16 + instTablePtr + i * 4);
if (data == 0)
continue;
- struct CInstrument* inst = parse_instrument(ctlData+16+data,ctlData+16, pos, &samples);
+ struct CInstrument *inst = parse_instrument(ctlData + 16 + data, ctlData + 16, pos, &samples);
bool used = 0;
- for(int j = 0; j < envCount; j++){
- if(envData[j].orig == (uintptr_t)inst->env_addr){
+ for (int j = 0; j < envCount; j++)
+ {
+ if (envData[j].orig == (uintptr_t)inst->env_addr)
+ {
used = 1;
break;
}
}
- if(used == 0){
+ if (used == 0)
+ {
int size = 0;
- unsigned char* addr = ctlData+((uintptr_t)inst->env_addr)+16;
- envData[envCount].orig = (uintptr_t)(inst->env_addr);
+ unsigned char *addr = ctlData + (uintptr_t)inst->env_addr + 16;
+ envData[envCount].orig = (uintptr_t)inst->env_addr;
envData[envCount].addr = parse_envelope(addr, pos, &size);
envData[envCount].size = size;
envCount++;
@@ -322,23 +377,28 @@ struct CTL* parse_ctl_data(unsigned char* ctlData, uintptr_t* pos){
*pos = ALIGN16(*pos);
// Copy envelopes to ctl
- for (int i = 0; i < envCount; i++){
- struct CEnvelope* env = envData[i].addr;
- memcpy((uint8_t*)(*pos), env, envData[i].size);
- for (int j = 0; j < ctl->numInstruments; j++){
- struct CInstrument* inst = ctl->instrument_pointers[j];
+ for (int i = 0; i < envCount; i++)
+ {
+ struct CEnvelope *env = envData[i].addr;
+ memcpy((uint8_t *)*pos, env, envData[i].size);
+ for (int j = 0; j < ctl->numInstruments; j++)
+ {
+ struct CInstrument *inst = ctl->instrument_pointers[j];
if (inst == 0x0)
continue;
- if((uintptr_t)(inst->env_addr) == envData[i].orig){
- inst->env_addr = (struct CEnvelope*)(*pos);
+ if ((uintptr_t)inst->env_addr == envData[i].orig)
+ {
+ inst->env_addr = (struct CEnvelope *)*pos;
}
}
- for (int j = 0; j < ctl->numDrums; j++){
- struct CDrum* drum = ctl->drum_pointers[j];
+ for (int j = 0; j < ctl->numDrums; j++)
+ {
+ struct CDrum *drum = ctl->drum_pointers[j];
if (drum == 0x0)
continue;
- if((uintptr_t)(drum->env_addr) == envData[i].orig){
- drum->env_addr = (struct CEnvelope*)(*pos);
+ if ((uintptr_t)drum->env_addr == envData[i].orig)
+ {
+ drum->env_addr = (struct CEnvelope *)*pos;
}
}
free(env);
@@ -347,25 +407,27 @@ struct CTL* parse_ctl_data(unsigned char* ctlData, uintptr_t* pos){
*pos = ALIGN16(*pos);
// Copy instruments to ctl
- for (int i = 0; i < ctl->numInstruments; i++){
- struct CInstrument* inst = ctl->instrument_pointers[i];
+ for (int i = 0; i < ctl->numInstruments; i++)
+ {
+ struct CInstrument *inst = ctl->instrument_pointers[i];
if (inst == 0x0)
continue;
- memcpy((uint8_t*)(*pos), inst, sizeof(struct CInstrument));
+ memcpy((uint8_t *)*pos, inst, sizeof(struct CInstrument));
free(inst);
- ctl->instrument_pointers[i] = (struct CInstrument*)(*pos);
+ ctl->instrument_pointers[i] = (struct CInstrument *)*pos;
*pos += sizeof(struct CInstrument);
}
*pos = ALIGN16(*pos);
// Copy drums to ctl
- for (int i = 0; i < ctl->numDrums; i++){
- struct CDrum* drum = ctl->drum_pointers[i];
+ for (int i = 0; i < ctl->numDrums; i++)
+ {
+ struct CDrum *drum = ctl->drum_pointers[i];
if (drum == 0x0)
continue;
- memcpy((uint8_t*)(*pos), drum, sizeof(struct CDrum));
+ memcpy((uint8_t *)*pos, drum, sizeof(struct CDrum));
free(drum);
- ctl->drum_pointers[i] = (struct CDrum*)(*pos);
+ ctl->drum_pointers[i] = (struct CDrum *)*pos;
*pos += sizeof(struct CDrum);
}
*pos = ALIGN16(*pos);
diff --git a/src/decomp/tools/convUtils.h b/src/decomp/tools/convUtils.h
index 5f5b30f..2636320 100644
--- a/src/decomp/tools/convUtils.h
+++ b/src/decomp/tools/convUtils.h
@@ -6,23 +6,31 @@
#define read_u16_le(p) ((uint8_t*)p)[1] * 0x100u + ((uint8_t*)p)[0]
-struct EnvelopeMeta {
- uintptr_t orig;
- struct CEnvelope* addr;
- int size;
+struct EnvelopeMeta
+{
+ uintptr_t orig;
+ struct CEnvelope *addr;
+ int size;
};
-struct SampleList {
- int count;
- uintptr_t orig_addrs[256];
- struct CSample* addrs[256];
+struct SampleList
+{
+ int count;
+ uintptr_t orig_addrs[256];
+ struct CSample *addrs[256];
};
-struct seqFile* parse_seqfile(unsigned char* seq);
-struct CTL* parse_ctl_data(unsigned char* ctlData, uintptr_t* pos);
-struct TBL* parse_tbl_data(unsigned char* tbl);
-struct SEQ* parse_seq_data(unsigned char* seq);
-void ptrs_to_offsets(struct seqFile* ctl);
+struct seqFile *parse_seqfile(unsigned char *seq);
+
+struct CTL *parse_ctl_data(unsigned char *ctlData, uintptr_t *pos);
+
+struct TBL *parse_tbl_data(unsigned char *tbl);
+
+struct SEQ *parse_seq_data(unsigned char *seq);
+
+void ptrs_to_offsets(struct seqFile *ctl);
+
void ctl_free();
+
#define INITIAL_GFX_ALLOC 10
#define INITIAL_GEO_ALLOC 10
\ No newline at end of file
diff --git a/src/decomp/tools/libmio0.c b/src/decomp/tools/libmio0.c
index 2c7a493..f46913e 100644
--- a/src/decomp/tools/libmio0.c
+++ b/src/decomp/tools/libmio0.c
@@ -18,50 +18,54 @@
// types
typedef struct
{
- int *indexes;
- int allocated;
- int count;
- int start;
+ int *indexes;
+ int allocated;
+ int count;
+ int start;
} lookback;
// functions
#define LOOKBACK_COUNT 256
#define LOOKBACK_INIT_SIZE 128
+
static lookback *lookback_init(void)
{
- lookback *lb = malloc(LOOKBACK_COUNT * sizeof(*lb));
- for (int i = 0; i < LOOKBACK_COUNT; i++) {
- lb[i].allocated = LOOKBACK_INIT_SIZE;
- lb[i].indexes = malloc(lb[i].allocated * sizeof(*lb[i].indexes));
- lb[i].count = 0;
- lb[i].start = 0;
- }
- return lb;
+ lookback *lb = malloc(LOOKBACK_COUNT * sizeof(*lb));
+ for (int i = 0; i < LOOKBACK_COUNT; i++)
+ {
+ lb[i].allocated = LOOKBACK_INIT_SIZE;
+ lb[i].indexes = malloc(lb[i].allocated * sizeof(*lb[i].indexes));
+ lb[i].count = 0;
+ lb[i].start = 0;
+ }
+ return lb;
}
static void lookback_free(lookback *lb)
{
- for (int i = 0; i < LOOKBACK_COUNT; i++) {
- free(lb[i].indexes);
- }
- free(lb);
+ for (int i = 0; i < LOOKBACK_COUNT; i++)
+ {
+ free(lb[i].indexes);
+ }
+ free(lb);
}
static inline void lookback_push(lookback *lkbk, unsigned char val, int index)
{
- lookback *lb = &lkbk[val];
- if (lb->count == lb->allocated) {
- lb->allocated *= 4;
- lb->indexes = realloc(lb->indexes, lb->allocated * sizeof(*lb->indexes));
- }
- lb->indexes[lb->count++] = index;
+ lookback *lb = &lkbk[val];
+ if (lb->count == lb->allocated)
+ {
+ lb->allocated *= 4;
+ lb->indexes = realloc(lb->indexes, lb->allocated * sizeof(*lb->indexes));
+ }
+ lb->indexes[lb->count++] = index;
}
static void PUT_BIT(unsigned char *buf, int bit, int val)
{
- unsigned char mask = 1 << (7 - (bit % 8));
- unsigned int offset = bit / 8;
- buf[offset] = (buf[offset] & ~(mask)) | (val ? mask : 0);
+ unsigned char mask = 1 << (7 - bit % 8);
+ unsigned int offset = bit / 8;
+ buf[offset] = buf[offset] & ~mask | (val ? mask : 0);
}
// used to find longest matching stream in buffer
@@ -72,504 +76,559 @@ static void PUT_BIT(unsigned char *buf, int bit, int val)
// returns max length of matching stream (0 if none found)
static int find_longest(const unsigned char *buf, int start_offset, int max_search, int *found_offset, lookback *lkbk)
{
- int best_length = 0;
- int best_offset = 0;
- int cur_length;
- int search_len;
- int farthest, off, i;
- int lb_idx;
- const unsigned char first = buf[start_offset];
- lookback *lb = &lkbk[first];
+ int best_length = 0;
+ int best_offset = 0;
+ int cur_length;
+ int search_len;
+ int farthest, off, i;
+ int lb_idx;
+ const unsigned char first = buf[start_offset];
+ lookback *lb = &lkbk[first];
- // buf
- // | off start max
- // V |+i-> |+i-> |
- // |--------------raw-data-----------------|
- // |+i-> | |+i->
- // +cur_length
+ // buf
+ // | off start max
+ // V |+i-> |+i-> |
+ // |--------------raw-data-----------------|
+ // |+i-> | |+i->
+ // +cur_length
- // check at most the past 4096 values
- farthest = MAX(start_offset - 4096, 0);
- // find starting index
- for (lb_idx = lb->start; lb_idx < lb->count && lb->indexes[lb_idx] < farthest; lb_idx++) {}
- lb->start = lb_idx;
- for ( ; lb_idx < lb->count && lb->indexes[lb_idx] < start_offset; lb_idx++) {
- off = lb->indexes[lb_idx];
- // check at most requested max or up until start
- search_len = MIN(max_search, start_offset - off);
- for (i = 0; i < search_len; i++) {
- if (buf[start_offset + i] != buf[off + i]) {
- break;
- }
- }
- cur_length = i;
- // if matched up until start, continue matching in already matched parts
- if (cur_length == search_len) {
- // check at most requested max less current length
- search_len = max_search - cur_length;
- for (i = 0; i < search_len; i++) {
- if (buf[start_offset + cur_length + i] != buf[off + i]) {
- break;
+ // check at most the past 4096 values
+ farthest = MAX(start_offset - 4096, 0);
+ // find starting index
+ for (lb_idx = lb->start; lb_idx < lb->count && lb->indexes[lb_idx] < farthest; lb_idx++)
+ {
+ }
+ lb->start = lb_idx;
+ for (; lb_idx < lb->count && lb->indexes[lb_idx] < start_offset; lb_idx++)
+ {
+ off = lb->indexes[lb_idx];
+ // check at most requested max or up until start
+ search_len = MIN(max_search, start_offset - off);
+ for (i = 0; i < search_len; i++)
+ {
+ if (buf[start_offset + i] != buf[off + i])
+ {
+ break;
}
- }
- cur_length += i;
- }
- if (cur_length > best_length) {
- best_offset = start_offset - off;
- best_length = cur_length;
- }
- }
+ }
+ cur_length = i;
+ // if matched up until start, continue matching in already matched parts
+ if (cur_length == search_len)
+ {
+ // check at most requested max less current length
+ search_len = max_search - cur_length;
+ for (i = 0; i < search_len; i++)
+ {
+ if (buf[start_offset + cur_length + i] != buf[off + i])
+ {
+ break;
+ }
+ }
+ cur_length += i;
+ }
+ if (cur_length > best_length)
+ {
+ best_offset = start_offset - off;
+ best_length = cur_length;
+ }
+ }
- // return best reverse offset and length (may be 0)
- *found_offset = best_offset;
- return best_length;
+ // return best reverse offset and length (may be 0)
+ *found_offset = best_offset;
+ return best_length;
}
// decode MIO0 header
// returns 1 if valid header, 0 otherwise
int mio0_decode_header(const unsigned char *buf, mio0_header_t *head)
{
- if (!memcmp(buf, "MIO0", 4)) {
- head->dest_size = read_u32_be(&buf[4]);
- head->comp_offset = read_u32_be(&buf[8]);
- head->uncomp_offset = read_u32_be(&buf[12]);
- return 1;
- }
- return 0;
+ if (!memcmp(buf, "MIO0", 4))
+ {
+ head->dest_size = read_u32_be(&buf[4]);
+ head->comp_offset = read_u32_be(&buf[8]);
+ head->uncomp_offset = read_u32_be(&buf[12]);
+ return 1;
+ }
+ return 0;
}
void mio0_encode_header(unsigned char *buf, const mio0_header_t *head)
{
- memcpy(buf, "MIO0", 4);
- write_u32_be(&buf[4], head->dest_size);
- write_u32_be(&buf[8], head->comp_offset);
- write_u32_be(&buf[12], head->uncomp_offset);
+ memcpy(buf, "MIO0", 4);
+ write_u32_be(&buf[4], head->dest_size);
+ write_u32_be(&buf[8], head->comp_offset);
+ write_u32_be(&buf[12], head->uncomp_offset);
}
int mio0_decode(const unsigned char *in, unsigned char *out, unsigned int *end)
{
- mio0_header_t head;
- unsigned int bytes_written = 0;
- int bit_idx = 0;
- int comp_idx = 0;
- int uncomp_idx = 0;
- int valid;
+ mio0_header_t head;
+ unsigned int bytes_written = 0;
+ int bit_idx = 0;
+ int comp_idx = 0;
+ int uncomp_idx = 0;
+ int valid;
- // extract header
- valid = mio0_decode_header(in, &head);
- // verify MIO0 header
- if (!valid) {
- return -2;
- }
+ // extract header
+ valid = mio0_decode_header(in, &head);
+ // verify MIO0 header
+ if (!valid)
+ {
+ return -2;
+ }
- // decode data
- while (bytes_written < head.dest_size) {
- if (GET_BIT(&in[MIO0_HEADER_LENGTH], bit_idx)) {
- // 1 - pull uncompressed data
- out[bytes_written] = in[head.uncomp_offset + uncomp_idx];
- bytes_written++;
- uncomp_idx++;
- } else {
- // 0 - read compressed data
- int idx;
- int length;
- int i;
- const unsigned char *vals = &in[head.comp_offset + comp_idx];
- comp_idx += 2;
- length = ((vals[0] & 0xF0) >> 4) + 3;
- idx = ((vals[0] & 0x0F) << 8) + vals[1] + 1;
- for (i = 0; i < length; i++) {
- out[bytes_written] = out[bytes_written - idx];
+ // decode data
+ while (bytes_written < head.dest_size)
+ {
+ if (GET_BIT(&in[MIO0_HEADER_LENGTH], bit_idx))
+ {
+ // 1 - pull uncompressed data
+ out[bytes_written] = in[head.uncomp_offset + uncomp_idx];
bytes_written++;
- }
- }
- bit_idx++;
- }
+ uncomp_idx++;
+ }
+ else
+ {
+ // 0 - read compressed data
+ int idx;
+ int length;
+ int i;
+ const unsigned char *vals = &in[head.comp_offset + comp_idx];
+ comp_idx += 2;
+ length = ((vals[0] & 0xF0) >> 4) + 3;
+ idx = ((vals[0] & 0x0F) << 8) + vals[1] + 1;
+ for (i = 0; i < length; i++)
+ {
+ out[bytes_written] = out[bytes_written - idx];
+ bytes_written++;
+ }
+ }
+ bit_idx++;
+ }
- if (end) {
- *end = head.uncomp_offset + uncomp_idx;
- }
+ if (end)
+ {
+ *end = head.uncomp_offset + uncomp_idx;
+ }
- return bytes_written;
+ return bytes_written;
}
int mio0_encode(const unsigned char *in, unsigned int length, unsigned char *out)
{
- unsigned char *bit_buf;
- unsigned char *comp_buf;
- unsigned char *uncomp_buf;
- unsigned int bit_length;
- unsigned int comp_offset;
- unsigned int uncomp_offset;
- unsigned int bytes_proc = 0;
- int bytes_written;
- int bit_idx = 0;
- int comp_idx = 0;
- int uncomp_idx = 0;
- lookback *lookbacks;
+ unsigned char *bit_buf;
+ unsigned char *comp_buf;
+ unsigned char *uncomp_buf;
+ unsigned int bit_length;
+ unsigned int comp_offset;
+ unsigned int uncomp_offset;
+ unsigned int bytes_proc = 0;
+ int bytes_written;
+ int bit_idx = 0;
+ int comp_idx = 0;
+ int uncomp_idx = 0;
+ lookback *lookbacks;
- // initialize lookback buffer
- lookbacks = lookback_init();
+ // initialize lookback buffer
+ lookbacks = lookback_init();
- // allocate some temporary buffers worst case size
- bit_buf = malloc((length + 7) / 8); // 1-bit/byte
- comp_buf = malloc(length); // 16-bits/2bytes
- uncomp_buf = malloc(length); // all uncompressed
- memset(bit_buf, 0, (length + 7) / 8);
+ // allocate some temporary buffers worst case size
+ bit_buf = malloc((length + 7) / 8); // 1-bit/byte
+ comp_buf = malloc(length); // 16-bits/2bytes
+ uncomp_buf = malloc(length); // all uncompressed
+ memset(bit_buf, 0, (length + 7) / 8);
- // encode data
- // special case for first byte
- lookback_push(lookbacks, in[0], 0);
- uncomp_buf[uncomp_idx] = in[0];
- uncomp_idx += 1;
- bytes_proc += 1;
- PUT_BIT(bit_buf, bit_idx++, 1);
- while (bytes_proc < length) {
- int offset;
- int max_length = MIN(length - bytes_proc, 18);
- int longest_match = find_longest(in, bytes_proc, max_length, &offset, lookbacks);
- // push current byte before checking next longer match
- lookback_push(lookbacks, in[bytes_proc], bytes_proc);
- if (longest_match > 2) {
- int lookahead_offset;
- // lookahead to next byte to see if longer match
- int lookahead_length = MIN(length - bytes_proc - 1, 18);
- int lookahead_match = find_longest(in, bytes_proc + 1, lookahead_length, &lookahead_offset, lookbacks);
- // better match found, use uncompressed + lookahead compressed
- if ((longest_match + 1) < lookahead_match) {
+ // encode data
+ // special case for first byte
+ lookback_push(lookbacks, in[0], 0);
+ uncomp_buf[uncomp_idx] = in[0];
+ uncomp_idx += 1;
+ bytes_proc += 1;
+ PUT_BIT(bit_buf, bit_idx++, 1);
+ while (bytes_proc < length)
+ {
+ int offset;
+ int max_length = MIN(length - bytes_proc, 18);
+ int longest_match = find_longest(in, bytes_proc, max_length, &offset, lookbacks);
+ // push current byte before checking next longer match
+ lookback_push(lookbacks, in[bytes_proc], bytes_proc);
+ if (longest_match > 2)
+ {
+ int lookahead_offset;
+ // lookahead to next byte to see if longer match
+ int lookahead_length = MIN(length - bytes_proc - 1, 18);
+ int lookahead_match = find_longest(in, bytes_proc + 1, lookahead_length, &lookahead_offset, lookbacks);
+ // better match found, use uncompressed + lookahead compressed
+ if (longest_match + 1 < lookahead_match)
+ {
+ // uncompressed byte
+ uncomp_buf[uncomp_idx] = in[bytes_proc];
+ uncomp_idx++;
+ PUT_BIT(bit_buf, bit_idx, 1);
+ bytes_proc++;
+ longest_match = lookahead_match;
+ offset = lookahead_offset;
+ bit_idx++;
+ lookback_push(lookbacks, in[bytes_proc], bytes_proc);
+ }
+ // first byte already pushed above
+ for (int i = 1; i < longest_match; i++)
+ {
+ lookback_push(lookbacks, in[bytes_proc + i], bytes_proc + i);
+ }
+ // compressed block
+ comp_buf[comp_idx] = (longest_match - 3 & 0x0F) << 4 |
+ (offset - 1) >> 8 & 0x0F;
+ comp_buf[comp_idx + 1] = offset - 1 & 0xFF;
+ comp_idx += 2;
+ PUT_BIT(bit_buf, bit_idx, 0);
+ bytes_proc += longest_match;
+ }
+ else
+ {
// uncompressed byte
uncomp_buf[uncomp_idx] = in[bytes_proc];
uncomp_idx++;
PUT_BIT(bit_buf, bit_idx, 1);
bytes_proc++;
- longest_match = lookahead_match;
- offset = lookahead_offset;
- bit_idx++;
- lookback_push(lookbacks, in[bytes_proc], bytes_proc);
- }
- // first byte already pushed above
- for (int i = 1; i < longest_match; i++) {
- lookback_push(lookbacks, in[bytes_proc + i], bytes_proc + i);
- }
- // compressed block
- comp_buf[comp_idx] = (((longest_match - 3) & 0x0F) << 4) |
- (((offset - 1) >> 8) & 0x0F);
- comp_buf[comp_idx + 1] = (offset - 1) & 0xFF;
- comp_idx += 2;
- PUT_BIT(bit_buf, bit_idx, 0);
- bytes_proc += longest_match;
- } else {
- // uncompressed byte
- uncomp_buf[uncomp_idx] = in[bytes_proc];
- uncomp_idx++;
- PUT_BIT(bit_buf, bit_idx, 1);
- bytes_proc++;
- }
- bit_idx++;
- }
+ }
+ bit_idx++;
+ }
- // compute final sizes and offsets
- // +7 so int division accounts for all bits
- bit_length = ((bit_idx + 7) / 8);
- // compressed data after control bits and aligned to 4-byte boundary
- comp_offset = ALIGN(MIO0_HEADER_LENGTH + bit_length, 4);
- uncomp_offset = comp_offset + comp_idx;
- bytes_written = uncomp_offset + uncomp_idx;
+ // compute final sizes and offsets
+ // +7 so int division accounts for all bits
+ bit_length = (bit_idx + 7) / 8;
+ // compressed data after control bits and aligned to 4-byte boundary
+ comp_offset = ALIGN(MIO0_HEADER_LENGTH + bit_length, 4);
+ uncomp_offset = comp_offset + comp_idx;
+ bytes_written = uncomp_offset + uncomp_idx;
- // output header
- memcpy(out, "MIO0", 4);
- write_u32_be(&out[4], length);
- write_u32_be(&out[8], comp_offset);
- write_u32_be(&out[12], uncomp_offset);
- // output data
- memcpy(&out[MIO0_HEADER_LENGTH], bit_buf, bit_length);
- memcpy(&out[comp_offset], comp_buf, comp_idx);
- memcpy(&out[uncomp_offset], uncomp_buf, uncomp_idx);
+ // output header
+ memcpy(out, "MIO0", 4);
+ write_u32_be(&out[4], length);
+ write_u32_be(&out[8], comp_offset);
+ write_u32_be(&out[12], uncomp_offset);
+ // output data
+ memcpy(&out[MIO0_HEADER_LENGTH], bit_buf, bit_length);
+ memcpy(&out[comp_offset], comp_buf, comp_idx);
+ memcpy(&out[uncomp_offset], uncomp_buf, uncomp_idx);
- // free allocated buffers
- free(bit_buf);
- free(comp_buf);
- free(uncomp_buf);
- lookback_free(lookbacks);
+ // free allocated buffers
+ free(bit_buf);
+ free(comp_buf);
+ free(uncomp_buf);
+ lookback_free(lookbacks);
- return bytes_written;
+ return bytes_written;
}
-static FILE *mio0_open_out_file(const char *out_file) {
- if (strcmp(out_file, "-") == 0) {
-#if defined(_WIN32) || defined(_WIN64)
- _setmode(_fileno(stdout), _O_BINARY);
-#endif
- return stdout;
- } else {
- return fopen(out_file, "wb");
- }
+static FILE *mio0_open_out_file(const char *out_file)
+{
+ if (strcmp(out_file, "-") == 0)
+ {
+ #if defined(_WIN32) || defined(_WIN64)
+ _setmode(_fileno(stdout), _O_BINARY);
+ #endif
+ return stdout;
+ }
+ else
+ {
+ return fopen(out_file, "wb");
+ }
}
int mio0_decode_file(const char *in_file, unsigned long offset, const char *out_file)
{
- mio0_header_t head;
- FILE *in;
- FILE *out;
- unsigned char *in_buf = NULL;
- unsigned char *out_buf = NULL;
- long file_size;
- int ret_val = 0;
- size_t bytes_read;
- int bytes_decoded;
- int bytes_written;
- int valid;
+ mio0_header_t head;
+ FILE *in;
+ FILE *out;
+ unsigned char *in_buf = NULL;
+ unsigned char *out_buf = NULL;
+ long file_size;
+ int ret_val = 0;
+ size_t bytes_read;
+ int bytes_decoded;
+ int bytes_written;
+ int valid;
- in = fopen(in_file, "rb");
- if (in == NULL) {
- return 1;
- }
+ in = fopen(in_file, "rb");
+ if (in == NULL)
+ {
+ return 1;
+ }
- // allocate buffer to read from offset to end of file
- fseek(in, 0, SEEK_END);
- file_size = ftell(in);
- in_buf = malloc(file_size - offset);
- fseek(in, offset, SEEK_SET);
+ // allocate buffer to read from offset to end of file
+ fseek(in, 0, SEEK_END);
+ file_size = ftell(in);
+ in_buf = malloc(file_size - offset);
+ fseek(in, offset, SEEK_SET);
- // read bytes
- bytes_read = fread(in_buf, 1, file_size - offset, in);
- if (bytes_read != file_size - offset) {
- ret_val = 2;
- goto free_all;
- }
+ // read bytes
+ bytes_read = fread(in_buf, 1, file_size - offset, in);
+ if (bytes_read != file_size - offset)
+ {
+ ret_val = 2;
+ goto free_all;
+ }
- // verify header
- valid = mio0_decode_header(in_buf, &head);
- if (!valid) {
- ret_val = 3;
- goto free_all;
- }
- out_buf = malloc(head.dest_size);
+ // verify header
+ valid = mio0_decode_header(in_buf, &head);
+ if (!valid)
+ {
+ ret_val = 3;
+ goto free_all;
+ }
+ out_buf = malloc(head.dest_size);
- // decompress MIO0 encoded data
- bytes_decoded = mio0_decode(in_buf, out_buf, NULL);
- if (bytes_decoded < 0) {
- ret_val = 3;
- goto free_all;
- }
+ // decompress MIO0 encoded data
+ bytes_decoded = mio0_decode(in_buf, out_buf, NULL);
+ if (bytes_decoded < 0)
+ {
+ ret_val = 3;
+ goto free_all;
+ }
- // open output file
- out = mio0_open_out_file(out_file);
- if (out == NULL) {
- ret_val = 4;
- goto free_all;
- }
+ // open output file
+ out = mio0_open_out_file(out_file);
+ if (out == NULL)
+ {
+ ret_val = 4;
+ goto free_all;
+ }
- // write data to file
- bytes_written = fwrite(out_buf, 1, bytes_decoded, out);
- if (bytes_written != bytes_decoded) {
- ret_val = 5;
- }
+ // write data to file
+ bytes_written = fwrite(out_buf, 1, bytes_decoded, out);
+ if (bytes_written != bytes_decoded)
+ {
+ ret_val = 5;
+ }
- // clean up
- if (out != stdout) {
- fclose(out);
- }
-free_all:
- if (out_buf) {
- free(out_buf);
- }
- if (in_buf) {
- free(in_buf);
- }
- fclose(in);
+ // clean up
+ if (out != stdout)
+ {
+ fclose(out);
+ }
+free_all: if (out_buf)
+ {
+ free(out_buf);
+ }
+ if (in_buf)
+ {
+ free(in_buf);
+ }
+ fclose(in);
- return ret_val;
+ return ret_val;
}
int mio0_encode_file(const char *in_file, const char *out_file)
{
- FILE *in;
- FILE *out;
- unsigned char *in_buf = NULL;
- unsigned char *out_buf = NULL;
- size_t file_size;
- size_t bytes_read;
- int bytes_encoded;
- int bytes_written;
- int ret_val = 0;
+ FILE *in;
+ FILE *out;
+ unsigned char *in_buf = NULL;
+ unsigned char *out_buf = NULL;
+ size_t file_size;
+ size_t bytes_read;
+ int bytes_encoded;
+ int bytes_written;
+ int ret_val = 0;
- in = fopen(in_file, "rb");
- if (in == NULL) {
- return 1;
- }
+ in = fopen(in_file, "rb");
+ if (in == NULL)
+ {
+ return 1;
+ }
- // allocate buffer to read entire contents of files
- fseek(in, 0, SEEK_END);
- file_size = ftell(in);
- fseek(in, 0, SEEK_SET);
- in_buf = malloc(file_size);
+ // allocate buffer to read entire contents of files
+ fseek(in, 0, SEEK_END);
+ file_size = ftell(in);
+ fseek(in, 0, SEEK_SET);
+ in_buf = malloc(file_size);
- // read bytes
- bytes_read = fread(in_buf, 1, file_size, in);
- if (bytes_read != file_size) {
- ret_val = 2;
- goto free_all;
- }
+ // read bytes
+ bytes_read = fread(in_buf, 1, file_size, in);
+ if (bytes_read != file_size)
+ {
+ ret_val = 2;
+ goto free_all;
+ }
- // allocate worst case length
- out_buf = malloc(MIO0_HEADER_LENGTH + ((file_size+7)/8) + file_size);
+ // allocate worst case length
+ out_buf = malloc(MIO0_HEADER_LENGTH + (file_size + 7) / 8 + file_size);
- // compress data in MIO0 format
- bytes_encoded = mio0_encode(in_buf, file_size, out_buf);
+ // compress data in MIO0 format
+ bytes_encoded = mio0_encode(in_buf, file_size, out_buf);
- // open output file
- out = mio0_open_out_file(out_file);
- if (out == NULL) {
- ret_val = 4;
- goto free_all;
- }
+ // open output file
+ out = mio0_open_out_file(out_file);
+ if (out == NULL)
+ {
+ ret_val = 4;
+ goto free_all;
+ }
- // write data to file
- bytes_written = fwrite(out_buf, 1, bytes_encoded, out);
- if (bytes_written != bytes_encoded) {
- ret_val = 5;
- }
+ // write data to file
+ bytes_written = fwrite(out_buf, 1, bytes_encoded, out);
+ if (bytes_written != bytes_encoded)
+ {
+ ret_val = 5;
+ }
- // clean up
- if (out != stdout) {
- fclose(out);
- }
-free_all:
- if (out_buf) {
- free(out_buf);
- }
- if (in_buf) {
- free(in_buf);
- }
- fclose(in);
+ // clean up
+ if (out != stdout)
+ {
+ fclose(out);
+ }
+free_all: if (out_buf)
+ {
+ free(out_buf);
+ }
+ if (in_buf)
+ {
+ free(in_buf);
+ }
+ fclose(in);
- return ret_val;
+ return ret_val;
}
// mio0 standalone executable
#ifdef MIO0_STANDALONE
typedef struct
{
- char *in_filename;
- char *out_filename;
- unsigned int offset;
- int compress;
+ char *in_filename;
+ char *out_filename;
+ unsigned int offset;
+ int compress;
} arg_config;
static arg_config default_config =
{
- NULL,
- NULL,
- 0,
- 1
+ NULL,
+ NULL,
+ 0,
+ 1
};
static void print_usage(void)
{
- ERROR("Usage: mio0 [-c / -d] [-o OFFSET] FILE [OUTPUT]\n"
- "\n"
- "mio0 v" MIO0_VERSION ": MIO0 compression and decompression tool\n"
- "\n"
- "Optional arguments:\n"
- " -c compress raw data into MIO0 (default: compress)\n"
- " -d decompress MIO0 into raw data\n"
- " -o OFFSET starting offset in FILE (default: 0)\n"
- "\n"
- "File arguments:\n"
- " FILE input file\n"
- " [OUTPUT] output file (default: FILE.out), \"-\" for stdout\n");
- exit(1);
+ ERROR("Usage: mio0 [-c / -d] [-o OFFSET] FILE [OUTPUT]\n"
+ "\n"
+ "mio0 v" MIO0_VERSION ": MIO0 compression and decompression tool\n"
+ "\n"
+ "Optional arguments:\n"
+ " -c compress raw data into MIO0 (default: compress)\n"
+ " -d decompress MIO0 into raw data\n"
+ " -o OFFSET starting offset in FILE (default: 0)\n"
+ "\n"
+ "File arguments:\n"
+ " FILE input file\n"
+ " [OUTPUT] output file (default: FILE.out), \"-\" for stdout\n");
+ exit(1);
}
// parse command line arguments
static void parse_arguments(int argc, char *argv[], arg_config *config)
{
- int i;
- int file_count = 0;
- if (argc < 2) {
- print_usage();
- exit(1);
- }
- for (i = 1; i < argc; i++) {
- if (argv[i][0] == '-' && argv[i][1] != '\0') {
- switch (argv[i][1]) {
- case 'c':
- config->compress = 1;
- break;
- case 'd':
- config->compress = 0;
- break;
- case 'o':
- if (++i >= argc) {
- print_usage();
- }
- config->offset = strtoul(argv[i], NULL, 0);
- break;
- default:
- print_usage();
- break;
- }
- } else {
- switch (file_count) {
- case 0:
- config->in_filename = argv[i];
- break;
- case 1:
- config->out_filename = argv[i];
- break;
- default: // too many
- print_usage();
- break;
- }
- file_count++;
- }
- }
- if (file_count < 1) {
- print_usage();
- }
+ int i;
+ int file_count = 0;
+ if (argc < 2)
+ {
+ print_usage();
+ exit(1);
+ }
+ for (i = 1; i < argc; i++)
+ {
+ if (argv[i][0] == '-' && argv[i][1] != '\0')
+ {
+ switch (argv[i][1])
+ {
+ case 'c':
+ config->compress = 1;
+ break;
+ case 'd':
+ config->compress = 0;
+ break;
+ case 'o':
+ if (++i >= argc)
+ {
+ print_usage();
+ }
+ config->offset = strtoul(argv[i], NULL, 0);
+ break;
+ default:
+ print_usage();
+ break;
+ }
+ }
+ else
+ {
+ switch (file_count)
+ {
+ case 0:
+ config->in_filename = argv[i];
+ break;
+ case 1:
+ config->out_filename = argv[i];
+ break;
+ default: // too many
+ print_usage();
+ break;
+ }
+ file_count++;
+ }
+ }
+ if (file_count < 1)
+ {
+ print_usage();
+ }
}
int main(int argc, char *argv[])
{
- char out_filename[FILENAME_MAX];
- arg_config config;
- int ret_val;
+ char out_filename[FILENAME_MAX];
+ arg_config config;
+ int ret_val;
- // get configuration from arguments
- config = default_config;
- parse_arguments(argc, argv, &config);
- if (config.out_filename == NULL) {
- config.out_filename = out_filename;
- sprintf(config.out_filename, "%s.out", config.in_filename);
- }
+ // get configuration from arguments
+ config = default_config;
+ parse_arguments(argc, argv, &config);
+ if (config.out_filename == NULL)
+ {
+ config.out_filename = out_filename;
+ sprintf(config.out_filename, "%s.out", config.in_filename);
+ }
- // operation
- if (config.compress) {
- ret_val = mio0_encode_file(config.in_filename, config.out_filename);
- } else {
- ret_val = mio0_decode_file(config.in_filename, config.offset, config.out_filename);
- }
+ // operation
+ if (config.compress)
+ {
+ ret_val = mio0_encode_file(config.in_filename, config.out_filename);
+ }
+ else
+ {
+ ret_val = mio0_decode_file(config.in_filename, config.offset, config.out_filename);
+ }
- switch (ret_val) {
- case 1:
- ERROR("Error opening input file \"%s\"\n", config.in_filename);
- break;
- case 2:
- ERROR("Error reading from input file \"%s\"\n", config.in_filename);
- break;
- case 3:
- ERROR("Error decoding MIO0 data. Wrong offset (0x%X)?\n", config.offset);
- break;
- case 4:
- ERROR("Error opening output file \"%s\"\n", config.out_filename);
- break;
- case 5:
- ERROR("Error writing bytes to output file \"%s\"\n", config.out_filename);
- break;
- }
+ switch (ret_val)
+ {
+ case 1:
+ ERROR("Error opening input file \"%s\"\n", config.in_filename);
+ break;
+ case 2:
+ ERROR("Error reading from input file \"%s\"\n", config.in_filename);
+ break;
+ case 3:
+ ERROR("Error decoding MIO0 data. Wrong offset (0x%X)?\n", config.offset);
+ break;
+ case 4:
+ ERROR("Error opening output file \"%s\"\n", config.out_filename);
+ break;
+ case 5:
+ ERROR("Error writing bytes to output file \"%s\"\n", config.out_filename);
+ break;
+ }
- return ret_val;
+ return ret_val;
}
#endif // MIO0_STANDALONE
diff --git a/src/decomp/tools/libmio0.h b/src/decomp/tools/libmio0.h
index 5b38ac7..1f47ad8 100644
--- a/src/decomp/tools/libmio0.h
+++ b/src/decomp/tools/libmio0.h
@@ -9,9 +9,9 @@
typedef struct
{
- unsigned int dest_size;
- unsigned int comp_offset;
- unsigned int uncomp_offset;
+ unsigned int dest_size;
+ unsigned int comp_offset;
+ unsigned int uncomp_offset;
} mio0_header_t;
// function prototypes
diff --git a/src/decomp/tools/n64graphics.c b/src/decomp/tools/n64graphics.c
index 2f28587..6ba36d1 100644
--- a/src/decomp/tools/n64graphics.c
+++ b/src/decomp/tools/n64graphics.c
@@ -26,11 +26,12 @@ typedef struct
{
enum
{
- IMG_FORMAT_RGBA,
- IMG_FORMAT_IA,
- IMG_FORMAT_I,
- IMG_FORMAT_CI,
+ IMG_FORMAT_RGBA,
+ IMG_FORMAT_IA,
+ IMG_FORMAT_I,
+ IMG_FORMAT_CI,
} format;
+
int depth;
} img_format;
@@ -40,162 +41,187 @@ typedef struct
rgba *raw2rgba(const uint8_t *raw, int width, int height, int depth)
{
- rgba *img;
- int img_size;
+ rgba *img;
+ int img_size;
- img_size = width * height * sizeof(*img);
- img = malloc(img_size);
- if (!img) {
- ERROR("Error allocating %d bytes\n", img_size);
- return NULL;
- }
+ img_size = width * height * sizeof(*img);
+ img = malloc(img_size);
+ if (!img)
+ {
+ ERROR("Error allocating %d bytes\n", img_size);
+ return NULL;
+ }
- if (depth == 16) {
- for (int i = 0; i < width * height; i++) {
- img[i].red = SCALE_5_8((raw[i*2] & 0xF8) >> 3);
- img[i].green = SCALE_5_8(((raw[i*2] & 0x07) << 2) | ((raw[i*2+1] & 0xC0) >> 6));
- img[i].blue = SCALE_5_8((raw[i*2+1] & 0x3E) >> 1);
- img[i].alpha = (raw[i*2+1] & 0x01) ? 0xFF : 0x00;
- }
- } else if (depth == 32) {
- for (int i = 0; i < width * height; i++) {
- img[i].red = raw[i*4];
- img[i].green = raw[i*4+1];
- img[i].blue = raw[i*4+2];
- img[i].alpha = raw[i*4+3];
- }
- }
+ if (depth == 16)
+ {
+ for (int i = 0; i < width * height; i++)
+ {
+ img[i].red = SCALE_5_8((raw[i*2] & 0xF8) >> 3);
+ img[i].green = SCALE_5_8((raw[i*2] & 0x07) << 2 | ((raw[i*2+1] & 0xC0) >> 6));
+ img[i].blue = SCALE_5_8((raw[i*2+1] & 0x3E) >> 1);
+ img[i].alpha = raw[i * 2 + 1] & 0x01 ? 0xFF : 0x00;
+ }
+ }
+ else if (depth == 32)
+ {
+ for (int i = 0; i < width * height; i++)
+ {
+ img[i].red = raw[i * 4];
+ img[i].green = raw[i * 4 + 1];
+ img[i].blue = raw[i * 4 + 2];
+ img[i].alpha = raw[i * 4 + 3];
+ }
+ }
- return img;
+ return img;
}
ia *raw2ia(const uint8_t *raw, int width, int height, int depth)
{
- ia *img;
- int img_size;
+ ia *img;
+ int img_size;
- img_size = width * height * sizeof(*img);
- img = malloc(img_size);
- if (!img) {
- ERROR("Error allocating %u bytes\n", img_size);
- return NULL;
- }
+ img_size = width * height * sizeof(*img);
+ img = malloc(img_size);
+ if (!img)
+ {
+ ERROR("Error allocating %u bytes\n", img_size);
+ return NULL;
+ }
- switch (depth) {
- case 16:
- for (int i = 0; i < width * height; i++) {
- img[i].intensity = raw[i*2];
- img[i].alpha = raw[i*2+1];
- }
- break;
- case 8:
- for (int i = 0; i < width * height; i++) {
- img[i].intensity = SCALE_4_8((raw[i] & 0xF0) >> 4);
- img[i].alpha = SCALE_4_8(raw[i] & 0x0F);
- }
- break;
- case 4:
- for (int i = 0; i < width * height; i++) {
- uint8_t bits;
- bits = raw[i/2];
- if (i % 2) {
- bits &= 0xF;
- } else {
- bits >>= 4;
+ switch (depth)
+ {
+ case 16:
+ for (int i = 0; i < width * height; i++)
+ {
+ img[i].intensity = raw[i * 2];
+ img[i].alpha = raw[i * 2 + 1];
}
- img[i].intensity = SCALE_3_8((bits >> 1) & 0x07);
- img[i].alpha = (bits & 0x01) ? 0xFF : 0x00;
- }
- break;
- case 1:
- for (int i = 0; i < width * height; i++) {
- uint8_t bits;
- uint8_t mask;
- bits = raw[i/8];
- mask = 1 << (7 - (i % 8)); // MSb->LSb
- bits = (bits & mask) ? 0xFF : 0x00;
- img[i].intensity = bits;
- img[i].alpha = bits;
- }
- break;
- default:
- ERROR("Error invalid depth %d\n", depth);
- break;
- }
+ break;
+ case 8:
+ for (int i = 0; i < width * height; i++)
+ {
+ img[i].intensity = SCALE_4_8((raw[i] & 0xF0) >> 4);
+ img[i].alpha = SCALE_4_8(raw[i] & 0x0F);
+ }
+ break;
+ case 4:
+ for (int i = 0; i < width * height; i++)
+ {
+ uint8_t bits;
+ bits = raw[i / 2];
+ if (i % 2)
+ {
+ bits &= 0xF;
+ }
+ else
+ {
+ bits >>= 4;
+ }
+ img[i].intensity = SCALE_3_8((bits >> 1) & 0x07);
+ img[i].alpha = bits & 0x01 ? 0xFF : 0x00;
+ }
+ break;
+ case 1:
+ for (int i = 0; i < width * height; i++)
+ {
+ uint8_t bits;
+ uint8_t mask;
+ bits = raw[i / 8];
+ mask = 1 << (7 - i % 8); // MSb->LSb
+ bits = bits & mask ? 0xFF : 0x00;
+ img[i].intensity = bits;
+ img[i].alpha = bits;
+ }
+ break;
+ default:
+ ERROR("Error invalid depth %d\n", depth);
+ break;
+ }
- return img;
+ return img;
}
ia *raw2i(const uint8_t *raw, int width, int height, int depth)
{
- ia *img = NULL;
- int img_size;
+ ia *img = NULL;
+ int img_size;
- img_size = width * height * sizeof(*img);
- img = malloc(img_size);
- if (!img) {
- ERROR("Error allocating %u bytes\n", img_size);
- return NULL;
- }
+ img_size = width * height * sizeof(*img);
+ img = malloc(img_size);
+ if (!img)
+ {
+ ERROR("Error allocating %u bytes\n", img_size);
+ return NULL;
+ }
- switch (depth) {
- case 8:
- for (int i = 0; i < width * height; i++) {
- img[i].intensity = raw[i];
- img[i].alpha = 0xFF;
- }
- break;
- case 4:
- for (int i = 0; i < width * height; i++) {
- uint8_t bits;
- bits = raw[i/2];
- if (i % 2) {
- bits &= 0xF;
- } else {
- bits >>= 4;
+ switch (depth)
+ {
+ case 8:
+ for (int i = 0; i < width * height; i++)
+ {
+ img[i].intensity = raw[i];
+ img[i].alpha = 0xFF;
}
- img[i].intensity = SCALE_4_8(bits);
- img[i].alpha = img[i].intensity; // alpha copy intensity
- // TODO: modes
- // img[i].alpha = 0xFF; // alpha = 1
- // img[i].alpha = img[i].intensity ? 0xFF : 0x00; // binary
- }
- break;
- default:
- ERROR("Error invalid depth %d\n", depth);
- break;
- }
+ break;
+ case 4:
+ for (int i = 0; i < width * height; i++)
+ {
+ uint8_t bits;
+ bits = raw[i / 2];
+ if (i % 2)
+ {
+ bits &= 0xF;
+ }
+ else
+ {
+ bits >>= 4;
+ }
+ img[i].intensity = SCALE_4_8(bits);
+ img[i].alpha = img[i].intensity; // alpha copy intensity
+ // TODO: modes
+ // img[i].alpha = 0xFF; // alpha = 1
+ // img[i].alpha = img[i].intensity ? 0xFF : 0x00; // binary
+ }
+ break;
+ default:
+ ERROR("Error invalid depth %d\n", depth);
+ break;
+ }
- return img;
+ return img;
}
// convert CI raw data and palette to raw data (either RGBA16 or IA16)
uint8_t *ci2raw(const uint8_t *rawci, const uint8_t *palette, int width, int height, int ci_depth)
{
- uint8_t *raw;
- int raw_size;
+ uint8_t *raw;
+ int raw_size;
- // first convert to raw RGBA
- raw_size = sizeof(uint16_t) * width * height;
- raw = malloc(raw_size);
- if (!raw) {
- ERROR("Error allocating %u bytes\n", raw_size);
- return NULL;
- }
+ // first convert to raw RGBA
+ raw_size = sizeof(uint16_t) * width * height;
+ raw = malloc(raw_size);
+ if (!raw)
+ {
+ ERROR("Error allocating %u bytes\n", raw_size);
+ return NULL;
+ }
- for (int i = 0; i < width * height; i++) {
- int pal_idx = rawci[i];
- if (ci_depth == 4) {
- int byte_idx = i / 2;
- int nibble = 1 - (i % 2);
- int shift = 4 * nibble;
- pal_idx = (rawci[byte_idx] >> shift) & 0xF;
- }
- raw[2*i] = palette[2*pal_idx];
- raw[2*i+1] = palette[2*pal_idx+1];
- }
+ for (int i = 0; i < width * height; i++)
+ {
+ int pal_idx = rawci[i];
+ if (ci_depth == 4)
+ {
+ int byte_idx = i / 2;
+ int nibble = 1 - i % 2;
+ int shift = 4 * nibble;
+ pal_idx = rawci[byte_idx] >> shift & 0xF;
+ }
+ raw[2 * i] = palette[2 * pal_idx];
+ raw[2 * i + 1] = palette[2 * pal_idx + 1];
+ }
- return raw;
+ return raw;
}
@@ -206,115 +232,139 @@ uint8_t *ci2raw(const uint8_t *rawci, const uint8_t *palette, int width, int hei
int rgba2raw(uint8_t *raw, const rgba *img, int width, int height, int depth)
{
- int size = (width * height * depth + 7) / 8;
- INFO("Converting RGBA%d %dx%d to raw\n", depth, width, height);
+ int size = (width * height * depth + 7) / 8;
+ INFO("Converting RGBA%d %dx%d to raw\n", depth, width, height);
- if (depth == 16) {
- for (int i = 0; i < width * height; i++) {
- uint8_t r, g, b, a;
- r = SCALE_8_5(img[i].red);
- g = SCALE_8_5(img[i].green);
- b = SCALE_8_5(img[i].blue);
- a = img[i].alpha ? 0x1 : 0x0;
- raw[i*2] = (r << 3) | (g >> 2);
- raw[i*2+1] = ((g & 0x3) << 6) | (b << 1) | a;
- }
- } else if (depth == 32) {
- for (int i = 0; i < width * height; i++) {
- raw[i*4] = img[i].red;
- raw[i*4+1] = img[i].green;
- raw[i*4+2] = img[i].blue;
- raw[i*4+3] = img[i].alpha;
- }
- } else {
- ERROR("Error invalid depth %d\n", depth);
- size = -1;
- }
+ if (depth == 16)
+ {
+ for (int i = 0; i < width * height; i++)
+ {
+ uint8_t r, g, b, a;
+ r = SCALE_8_5(img[i].red);
+ g = SCALE_8_5(img[i].green);
+ b = SCALE_8_5(img[i].blue);
+ a = img[i].alpha ? 0x1 : 0x0;
+ raw[i * 2] = r << 3 | g >> 2;
+ raw[i * 2 + 1] = (g & 0x3) << 6 | b << 1 | a;
+ }
+ }
+ else if (depth == 32)
+ {
+ for (int i = 0; i < width * height; i++)
+ {
+ raw[i * 4] = img[i].red;
+ raw[i * 4 + 1] = img[i].green;
+ raw[i * 4 + 2] = img[i].blue;
+ raw[i * 4 + 3] = img[i].alpha;
+ }
+ }
+ else
+ {
+ ERROR("Error invalid depth %d\n", depth);
+ size = -1;
+ }
- return size;
+ return size;
}
int ia2raw(uint8_t *raw, const ia *img, int width, int height, int depth)
{
- int size = (width * height * depth + 7) / 8;
- INFO("Converting IA%d %dx%d to raw\n", depth, width, height);
+ int size = (width * height * depth + 7) / 8;
+ INFO("Converting IA%d %dx%d to raw\n", depth, width, height);
- switch (depth) {
- case 16:
- for (int i = 0; i < width * height; i++) {
- raw[i*2] = img[i].intensity;
- raw[i*2+1] = img[i].alpha;
- }
- break;
- case 8:
- for (int i = 0; i < width * height; i++) {
- uint8_t val = SCALE_8_4(img[i].intensity);
- uint8_t alpha = SCALE_8_4(img[i].alpha);
- raw[i] = (val << 4) | alpha;
- }
- break;
- case 4:
- for (int i = 0; i < width * height; i++) {
- uint8_t val = SCALE_8_3(img[i].intensity);
- uint8_t alpha = img[i].alpha ? 0x01 : 0x00;
- uint8_t old = raw[i/2];
- if (i % 2) {
- raw[i/2] = (old & 0xF0) | (val << 1) | alpha;
- } else {
- raw[i/2] = (old & 0x0F) | (((val << 1) | alpha) << 4);
+ switch (depth)
+ {
+ case 16:
+ for (int i = 0; i < width * height; i++)
+ {
+ raw[i * 2] = img[i].intensity;
+ raw[i * 2 + 1] = img[i].alpha;
}
- }
- break;
- case 1:
- for (int i = 0; i < width * height; i++) {
- uint8_t val = img[i].intensity;
- uint8_t old = raw[i/8];
- uint8_t bit = 1 << (7 - (i % 8));
- if (val) {
- raw[i/8] = old | bit;
- } else {
- raw[i/8] = old & (~bit);
+ break;
+ case 8:
+ for (int i = 0; i < width * height; i++)
+ {
+ uint8_t val = SCALE_8_4(img[i].intensity);
+ uint8_t alpha = SCALE_8_4(img[i].alpha);
+ raw[i] = val << 4 | alpha;
}
- }
- break;
- default:
- ERROR("Error invalid depth %d\n", depth);
- size = -1;
- break;
- }
+ break;
+ case 4:
+ for (int i = 0; i < width * height; i++)
+ {
+ uint8_t val = SCALE_8_3(img[i].intensity);
+ uint8_t alpha = img[i].alpha ? 0x01 : 0x00;
+ uint8_t old = raw[i / 2];
+ if (i % 2)
+ {
+ raw[i / 2] = old & 0xF0 | val << 1 | alpha;
+ }
+ else
+ {
+ raw[i / 2] = old & 0x0F | (val << 1 | alpha) << 4;
+ }
+ }
+ break;
+ case 1:
+ for (int i = 0; i < width * height; i++)
+ {
+ uint8_t val = img[i].intensity;
+ uint8_t old = raw[i / 8];
+ uint8_t bit = 1 << (7 - i % 8);
+ if (val)
+ {
+ raw[i / 8] = old | bit;
+ }
+ else
+ {
+ raw[i / 8] = old & ~bit;
+ }
+ }
+ break;
+ default:
+ ERROR("Error invalid depth %d\n", depth);
+ size = -1;
+ break;
+ }
- return size;
+ return size;
}
int i2raw(uint8_t *raw, const ia *img, int width, int height, int depth)
{
- int size = (width * height * depth + 7) / 8;
- INFO("Converting I%d %dx%d to raw\n", depth, width, height);
+ int size = (width * height * depth + 7) / 8;
+ INFO("Converting I%d %dx%d to raw\n", depth, width, height);
- switch (depth) {
- case 8:
- for (int i = 0; i < width * height; i++) {
- raw[i] = img[i].intensity;
- }
- break;
- case 4:
- for (int i = 0; i < width * height; i++) {
- uint8_t val = SCALE_8_4(img[i].intensity);
- uint8_t old = raw[i/2];
- if (i % 2) {
- raw[i/2] = (old & 0xF0) | val;
- } else {
- raw[i/2] = (old & 0x0F) | (val << 4);
+ switch (depth)
+ {
+ case 8:
+ for (int i = 0; i < width * height; i++)
+ {
+ raw[i] = img[i].intensity;
}
- }
- break;
- default:
- ERROR("Error invalid depth %d\n", depth);
- size = -1;
- break;
- }
+ break;
+ case 4:
+ for (int i = 0; i < width * height; i++)
+ {
+ uint8_t val = SCALE_8_4(img[i].intensity);
+ uint8_t old = raw[i / 2];
+ if (i % 2)
+ {
+ raw[i / 2] = old & 0xF0 | val;
+ }
+ else
+ {
+ raw[i / 2] = old & 0x0F | val << 4;
+ }
+ }
+ break;
+ default:
+ ERROR("Error invalid depth %d\n", depth);
+ size = -1;
+ break;
+ }
- return size;
+ return size;
}
@@ -324,52 +374,58 @@ int i2raw(uint8_t *raw, const ia *img, int width, int height, int depth)
int rgba2png(const char *png_filename, const rgba *img, int width, int height)
{
- int ret = 0;
- INFO("Saving RGBA %dx%d to \"%s\"\n", width, height, png_filename);
+ int ret = 0;
+ INFO("Saving RGBA %dx%d to \"%s\"\n", width, height, png_filename);
- // convert to format stb_image_write expects
- uint8_t *data = malloc(4*width*height);
- if (data) {
- for (int j = 0; j < height; j++) {
- for (int i = 0; i < width; i++) {
- int idx = j*width + i;
- data[4*idx] = img[idx].red;
- data[4*idx + 1] = img[idx].green;
- data[4*idx + 2] = img[idx].blue;
- data[4*idx + 3] = img[idx].alpha;
- }
- }
+ // convert to format stb_image_write expects
+ uint8_t *data = malloc(4 * width * height);
+ if (data)
+ {
+ for (int j = 0; j < height; j++)
+ {
+ for (int i = 0; i < width; i++)
+ {
+ int idx = j * width + i;
+ data[4 * idx] = img[idx].red;
+ data[4 * idx + 1] = img[idx].green;
+ data[4 * idx + 2] = img[idx].blue;
+ data[4 * idx + 3] = img[idx].alpha;
+ }
+ }
- ret = stbi_write_png(png_filename, width, height, 4, data, 0);
+ ret = stbi_write_png(png_filename, width, height, 4, data, 0);
- free(data);
- }
+ free(data);
+ }
- return ret;
+ return ret;
}
int ia2png(const char *png_filename, const ia *img, int width, int height)
{
- int ret = 0;
- INFO("Saving IA %dx%d to \"%s\"\n", width, height, png_filename);
+ int ret = 0;
+ INFO("Saving IA %dx%d to \"%s\"\n", width, height, png_filename);
- // convert to format stb_image_write expects
- uint8_t *data = malloc(2*width*height);
- if (data) {
- for (int j = 0; j < height; j++) {
- for (int i = 0; i < width; i++) {
- int idx = j*width + i;
- data[2*idx] = img[idx].intensity;
- data[2*idx + 1] = img[idx].alpha;
- }
- }
+ // convert to format stb_image_write expects
+ uint8_t *data = malloc(2 * width * height);
+ if (data)
+ {
+ for (int j = 0; j < height; j++)
+ {
+ for (int i = 0; i < width; i++)
+ {
+ int idx = j * width + i;
+ data[2 * idx] = img[idx].intensity;
+ data[2 * idx + 1] = img[idx].alpha;
+ }
+ }
- ret = stbi_write_png(png_filename, width, height, 2, data, 0);
+ ret = stbi_write_png(png_filename, width, height, 2, data, 0);
- free(data);
- }
+ free(data);
+ }
- return ret;
+ return ret;
}
//---------------------------------------------------------
@@ -378,201 +434,232 @@ int ia2png(const char *png_filename, const ia *img, int width, int height)
rgba *png2rgba(const char *png_filename, int *width, int *height)
{
- rgba *img = NULL;
- int w = 0;
- int h = 0;
- int channels = 0;
- int img_size;
+ rgba *img = NULL;
+ int w = 0;
+ int h = 0;
+ int channels = 0;
+ int img_size;
- stbi_uc *data = stbi_load(png_filename, &w, &h, &channels, STBI_default);
- if (!data || w <= 0 || h <= 0) {
- ERROR("Error loading \"%s\"\n", png_filename);
- return NULL;
- }
- INFO("Read \"%s\" %dx%d channels: %d\n", png_filename, w, h, channels);
+ stbi_uc *data = stbi_load(png_filename, &w, &h, &channels, STBI_default);
+ if (!data || w <= 0 || h <= 0)
+ {
+ ERROR("Error loading \"%s\"\n", png_filename);
+ return NULL;
+ }
+ INFO("Read \"%s\" %dx%d channels: %d\n", png_filename, w, h, channels);
- img_size = w * h * sizeof(*img);
- img = malloc(img_size);
- if (!img) {
- ERROR("Error allocating %u bytes\n", img_size);
- return NULL;
- }
+ img_size = w * h * sizeof(*img);
+ img = malloc(img_size);
+ if (!img)
+ {
+ ERROR("Error allocating %u bytes\n", img_size);
+ return NULL;
+ }
- switch (channels) {
- case 3: // red, green, blue
- case 4: // red, green, blue, alpha
- for (int j = 0; j < h; j++) {
- for (int i = 0; i < w; i++) {
- int idx = j*w + i;
- img[idx].red = data[channels*idx];
- img[idx].green = data[channels*idx + 1];
- img[idx].blue = data[channels*idx + 2];
- if (channels == 4) {
- img[idx].alpha = data[channels*idx + 3];
- } else {
- img[idx].alpha = 0xFF;
- }
+ switch (channels)
+ {
+ case 3: // red, green, blue
+ case 4: // red, green, blue, alpha
+ for (int j = 0; j < h; j++)
+ {
+ for (int i = 0; i < w; i++)
+ {
+ int idx = j * w + i;
+ img[idx].red = data[channels * idx];
+ img[idx].green = data[channels * idx + 1];
+ img[idx].blue = data[channels * idx + 2];
+ if (channels == 4)
+ {
+ img[idx].alpha = data[channels * idx + 3];
+ }
+ else
+ {
+ img[idx].alpha = 0xFF;
+ }
+ }
}
- }
- break;
- case 2: // grey, alpha
- for (int j = 0; j < h; j++) {
- for (int i = 0; i < w; i++) {
- int idx = j*w + i;
- img[idx].red = data[2*idx];
- img[idx].green = data[2*idx];
- img[idx].blue = data[2*idx];
- img[idx].alpha = data[2*idx + 1];
+ break;
+ case 2: // grey, alpha
+ for (int j = 0; j < h; j++)
+ {
+ for (int i = 0; i < w; i++)
+ {
+ int idx = j * w + i;
+ img[idx].red = data[2 * idx];
+ img[idx].green = data[2 * idx];
+ img[idx].blue = data[2 * idx];
+ img[idx].alpha = data[2 * idx + 1];
+ }
}
- }
- break;
- default:
- ERROR("Don't know how to read channels: %d\n", channels);
- free(img);
- img = NULL;
- }
+ break;
+ default:
+ ERROR("Don't know how to read channels: %d\n", channels);
+ free(img);
+ img = NULL;
+ }
- // cleanup
- stbi_image_free(data);
+ // cleanup
+ stbi_image_free(data);
- *width = w;
- *height = h;
- return img;
+ *width = w;
+ *height = h;
+ return img;
}
ia *png2ia(const char *png_filename, int *width, int *height)
{
- ia *img = NULL;
- int w = 0, h = 0;
- int channels = 0;
- int img_size;
+ ia *img = NULL;
+ int w = 0, h = 0;
+ int channels = 0;
+ int img_size;
- stbi_uc *data = stbi_load(png_filename, &w, &h, &channels, STBI_default);
- if (!data || w <= 0 || h <= 0) {
- ERROR("Error loading \"%s\"\n", png_filename);
- return NULL;
- }
- INFO("Read \"%s\" %dx%d channels: %d\n", png_filename, w, h, channels);
+ stbi_uc *data = stbi_load(png_filename, &w, &h, &channels, STBI_default);
+ if (!data || w <= 0 || h <= 0)
+ {
+ ERROR("Error loading \"%s\"\n", png_filename);
+ return NULL;
+ }
+ INFO("Read \"%s\" %dx%d channels: %d\n", png_filename, w, h, channels);
- img_size = w * h * sizeof(*img);
- img = malloc(img_size);
- if (!img) {
- ERROR("Error allocating %d bytes\n", img_size);
- return NULL;
- }
+ img_size = w * h * sizeof(*img);
+ img = malloc(img_size);
+ if (!img)
+ {
+ ERROR("Error allocating %d bytes\n", img_size);
+ return NULL;
+ }
- switch (channels) {
- case 3: // red, green, blue
- case 4: // red, green, blue, alpha
- ERROR("Warning: averaging RGB PNG to create IA\n");
- for (int j = 0; j < h; j++) {
- for (int i = 0; i < w; i++) {
- int idx = j*w + i;
- int sum = data[channels*idx] + data[channels*idx + 1] + data[channels*idx + 2];
- img[idx].intensity = (sum + 1) / 3; // add 1 to round up where appropriate
- if (channels == 4) {
- img[idx].alpha = data[channels*idx + 3];
- } else {
- img[idx].alpha = 0xFF;
- }
+ switch (channels)
+ {
+ case 3: // red, green, blue
+ case 4: // red, green, blue, alpha
+ ERROR("Warning: averaging RGB PNG to create IA\n");
+ for (int j = 0; j < h; j++)
+ {
+ for (int i = 0; i < w; i++)
+ {
+ int idx = j * w + i;
+ int sum = data[channels * idx] + data[channels * idx + 1] + data[channels * idx + 2];
+ img[idx].intensity = (sum + 1) / 3; // add 1 to round up where appropriate
+ if (channels == 4)
+ {
+ img[idx].alpha = data[channels * idx + 3];
+ }
+ else
+ {
+ img[idx].alpha = 0xFF;
+ }
+ }
}
- }
- break;
- case 2: // grey, alpha
- for (int j = 0; j < h; j++) {
- for (int i = 0; i < w; i++) {
- int idx = j*w + i;
- img[idx].intensity = data[2*idx];
- img[idx].alpha = data[2*idx + 1];
+ break;
+ case 2: // grey, alpha
+ for (int j = 0; j < h; j++)
+ {
+ for (int i = 0; i < w; i++)
+ {
+ int idx = j * w + i;
+ img[idx].intensity = data[2 * idx];
+ img[idx].alpha = data[2 * idx + 1];
+ }
}
- }
- break;
- default:
- ERROR("Don't know how to read channels: %d\n", channels);
- free(img);
- img = NULL;
- }
+ break;
+ default:
+ ERROR("Don't know how to read channels: %d\n", channels);
+ free(img);
+ img = NULL;
+ }
- // cleanup
- stbi_image_free(data);
+ // cleanup
+ stbi_image_free(data);
- *width = w;
- *height = h;
- return img;
+ *width = w;
+ *height = h;
+ return img;
}
// find index of palette color
// return -1 if not found
static int pal_find_color(const palette_t *pal, uint16_t val)
{
- for (int i = 0; i < pal->used; i++) {
- if (pal->data[i] == val) {
- return i;
- }
- }
- return -1;
+ for (int i = 0; i < pal->used; i++)
+ {
+ if (pal->data[i] == val)
+ {
+ return i;
+ }
+ }
+ return -1;
}
// find value in palette, or add if not there
// returns palette index entered or -1 if palette full
static int pal_add_color(palette_t *pal, uint16_t val)
{
- int idx;
- idx = pal_find_color(pal, val);
- if (idx < 0) {
- if (pal->used == pal->max) {
- ERROR("Error: trying to use more than %d\n", pal->max);
- } else {
- idx = pal->used;
- pal->data[pal->used] = val;
- pal->used++;
- }
- }
- return idx;
+ int idx;
+ idx = pal_find_color(pal, val);
+ if (idx < 0)
+ {
+ if (pal->used == pal->max)
+ {
+ ERROR("Error: trying to use more than %d\n", pal->max);
+ }
+ else
+ {
+ idx = pal->used;
+ pal->data[pal->used] = val;
+ pal->used++;
+ }
+ }
+ return idx;
}
// convert from raw (RGBA16 or IA16) format to CI + palette
// returns 1 on success
int raw2ci(uint8_t *rawci, palette_t *pal, const uint8_t *raw, int raw_len, int ci_depth)
{
- // assign colors to palette
- pal->used = 0;
- memset(pal->data, 0, sizeof(pal->data));
- int ci_idx = 0;
- for (int i = 0; i < raw_len; i += sizeof(uint16_t)) {
- uint16_t val = read_u16_be(&raw[i]);
- int pal_idx = pal_add_color(pal, val);
- if (pal_idx < 0) {
- ERROR("Error adding color @ (%d): %d (used: %d/%d)\n", i, pal_idx, pal->used, pal->max);
- return 0;
- } else {
- switch (ci_depth) {
- case 8:
- rawci[ci_idx] = (uint8_t)pal_idx;
- break;
- case 4:
+ // assign colors to palette
+ pal->used = 0;
+ memset(pal->data, 0, sizeof(pal->data));
+ int ci_idx = 0;
+ for (int i = 0; i < raw_len; i += sizeof(uint16_t))
+ {
+ uint16_t val = read_u16_be(&raw[i]);
+ int pal_idx = pal_add_color(pal, val);
+ if (pal_idx < 0)
+ {
+ ERROR("Error adding color @ (%d): %d (used: %d/%d)\n", i, pal_idx, pal->used, pal->max);
+ return 0;
+ }
+ else
+ {
+ switch (ci_depth)
{
- int byte_idx = ci_idx / 2;
- int nibble = 1 - (ci_idx % 2);
- uint8_t mask = 0xF << (4 * (1 - nibble));
- rawci[byte_idx] = (rawci[byte_idx] & mask) | (pal_idx << (4 * nibble));
- break;
+ case 8:
+ rawci[ci_idx] = (uint8_t)pal_idx;
+ break;
+ case 4:
+ {
+ int byte_idx = ci_idx / 2;
+ int nibble = 1 - ci_idx % 2;
+ uint8_t mask = 0xF << (4 * (1 - nibble));
+ rawci[byte_idx] = rawci[byte_idx] & mask | pal_idx << (4 * nibble);
+ break;
+ }
}
- }
- ci_idx++;
- }
- }
- return 1;
+ ci_idx++;
+ }
+ }
+ return 1;
}
const char *n64graphics_get_read_version(void)
{
- return "stb_image 2.19";
+ return "stb_image 2.19";
}
const char *n64graphics_get_write_version(void)
{
- return "stb_image_write 1.09";
+ return "stb_image_write 1.09";
}
#ifdef N64GRAPHICS_STANDALONE
@@ -581,441 +668,488 @@ const char *n64graphics_get_write_version(void)
typedef enum
{
- MODE_EXPORT,
- MODE_IMPORT,
+ MODE_EXPORT, MODE_IMPORT,
} tool_mode;
typedef struct
{
- char *img_filename;
- char *bin_filename;
- char *pal_filename;
- tool_mode mode;
- unsigned int bin_offset;
- unsigned int pal_offset;
- img_format format;
- img_format pal_format;
- int width;
- int height;
- int bin_truncate;
- int pal_truncate;
+ char *img_filename;
+ char *bin_filename;
+ char *pal_filename;
+ tool_mode mode;
+ unsigned int bin_offset;
+ unsigned int pal_offset;
+ img_format format;
+ img_format pal_format;
+ int width;
+ int height;
+ int bin_truncate;
+ int pal_truncate;
} graphics_config;
static const graphics_config default_config =
{
- .img_filename = NULL,
- .bin_filename = NULL,
- .pal_filename = NULL,
- .mode = MODE_EXPORT,
- .bin_offset = 0,
- .pal_offset = 0,
- .format = {IMG_FORMAT_RGBA, 16},
- .pal_format = {IMG_FORMAT_RGBA, 16},
- .width = 32,
- .height = 32,
- .bin_truncate = 1,
- .pal_truncate = 1,
+ .img_filename = NULL,
+ .bin_filename = NULL,
+ .pal_filename = NULL,
+ .mode = MODE_EXPORT,
+ .bin_offset = 0,
+ .pal_offset = 0,
+ .format = {IMG_FORMAT_RGBA, 16},
+ .pal_format = {IMG_FORMAT_RGBA, 16},
+ .width = 32,
+ .height = 32,
+ .bin_truncate = 1,
+ .pal_truncate = 1,
};
typedef struct
{
- const char *name;
- img_format format;
+ const char *name;
+ img_format format;
} format_entry;
static const format_entry format_table[] =
{
- {"rgba16", {IMG_FORMAT_RGBA, 16}},
- {"rgba32", {IMG_FORMAT_RGBA, 32}},
- {"ia1", {IMG_FORMAT_IA, 1}},
- {"ia4", {IMG_FORMAT_IA, 4}},
- {"ia8", {IMG_FORMAT_IA, 8}},
- {"ia16", {IMG_FORMAT_IA, 16}},
- {"i4", {IMG_FORMAT_I, 4}},
- {"i8", {IMG_FORMAT_I, 8}},
- {"ci8", {IMG_FORMAT_CI, 8}},
- {"ci4", {IMG_FORMAT_CI, 4}},
+ {"rgba16", {IMG_FORMAT_RGBA, 16}},
+ {"rgba32", {IMG_FORMAT_RGBA, 32}},
+ {"ia1", {IMG_FORMAT_IA, 1}},
+ {"ia4", {IMG_FORMAT_IA, 4}},
+ {"ia8", {IMG_FORMAT_IA, 8}},
+ {"ia16", {IMG_FORMAT_IA, 16}},
+ {"i4", {IMG_FORMAT_I, 4}},
+ {"i8", {IMG_FORMAT_I, 8}},
+ {"ci8", {IMG_FORMAT_CI, 8}},
+ {"ci4", {IMG_FORMAT_CI, 4}},
};
static const char *format2str(const img_format *format)
{
- for (unsigned i = 0; i < DIM(format_table); i++) {
- if (format->format == format_table[i].format.format && format->depth == format_table[i].format.depth) {
- return format_table[i].name;
- }
- }
- return "unknown";
+ for (unsigned i = 0; i < DIM(format_table); i++)
+ {
+ if (format->format == format_table[i].format.format && format->depth == format_table[i].format.depth)
+ {
+ return format_table[i].name;
+ }
+ }
+ return "unknown";
}
static int parse_format(img_format *format, const char *str)
{
- for (unsigned i = 0; i < DIM(format_table); i++) {
- if (!strcasecmp(str, format_table[i].name)) {
- format->format = format_table[i].format.format;
- format->depth = format_table[i].format.depth;
- return 1;
- }
- }
- return 0;
+ for (unsigned i = 0; i < DIM(format_table); i++)
+ {
+ if (!strcasecmp(str, format_table[i].name))
+ {
+ format->format = format_table[i].format.format;
+ format->depth = format_table[i].format.depth;
+ return 1;
+ }
+ }
+ return 0;
}
static void print_usage(void)
{
- ERROR("Usage: n64graphics -e/-i BIN_FILE -g IMG_FILE [-p PAL_FILE] [-o BIN_OFFSET] [-P PAL_OFFSET] [-f FORMAT] [-c CI_FORMAT] [-w WIDTH] [-h HEIGHT] [-V]\n"
- "\n"
- "n64graphics v" N64GRAPHICS_VERSION ": N64 graphics manipulator\n"
- "\n"
- "Required arguments:\n"
- " -e BIN_FILE export from BIN_FILE to PNG_FILE\n"
- " -i BIN_FILE import from PNG_FILE to BIN_FILE\n"
- " -g IMG_FILE graphics file to import/export (.png)\n"
- "Optional arguments:\n"
- " -o BIN_OFFSET starting offset in BIN_FILE (prevents truncation during import)\n"
- " -f FORMAT texture format: rgba16, rgba32, ia1, ia4, ia8, ia16, i4, i8, ci4, ci8 (default: %s)\n"
- " -w WIDTH export texture width (default: %d)\n"
- " -h HEIGHT export texture height (default: %d)\n"
- "CI arguments:\n"
- " -c CI_FORMAT CI palette format: rgba16, ia16 (default: %s)\n"
- " -p PAL_FILE palette binary file to import/export from/to\n"
- " -P PAL_OFFSET starting offset in PAL_FILE (prevents truncation during import)\n"
- "Other arguments:\n"
- " -v verbose logging\n"
- " -V print version information\n",
- format2str(&default_config.format),
- default_config.width,
- default_config.height,
- format2str(&default_config.pal_format));
+ ERROR("Usage: n64graphics -e/-i BIN_FILE -g IMG_FILE [-p PAL_FILE] [-o BIN_OFFSET] [-P PAL_OFFSET] [-f FORMAT] [-c CI_FORMAT] [-w WIDTH] [-h HEIGHT] [-V]\n"
+ "\n"
+ "n64graphics v" N64GRAPHICS_VERSION ": N64 graphics manipulator\n"
+ "\n"
+ "Required arguments:\n"
+ " -e BIN_FILE export from BIN_FILE to PNG_FILE\n"
+ " -i BIN_FILE import from PNG_FILE to BIN_FILE\n"
+ " -g IMG_FILE graphics file to import/export (.png)\n"
+ "Optional arguments:\n"
+ " -o BIN_OFFSET starting offset in BIN_FILE (prevents truncation during import)\n"
+ " -f FORMAT texture format: rgba16, rgba32, ia1, ia4, ia8, ia16, i4, i8, ci4, ci8 (default: %s)\n"
+ " -w WIDTH export texture width (default: %d)\n"
+ " -h HEIGHT export texture height (default: %d)\n"
+ "CI arguments:\n"
+ " -c CI_FORMAT CI palette format: rgba16, ia16 (default: %s)\n"
+ " -p PAL_FILE palette binary file to import/export from/to\n"
+ " -P PAL_OFFSET starting offset in PAL_FILE (prevents truncation during import)\n"
+ "Other arguments:\n"
+ " -v verbose logging\n"
+ " -V print version information\n",
+ format2str(&default_config.format),
+ default_config.width,
+ default_config.height,
+ format2str(&default_config.pal_format));
}
static void print_version(void)
{
- ERROR("n64graphics v" N64GRAPHICS_VERSION ", using:\n"
- " %s\n"
- " %s\n",
- n64graphics_get_read_version(), n64graphics_get_write_version());
+ ERROR("n64graphics v" N64GRAPHICS_VERSION ", using:\n"
+ " %s\n"
+ " %s\n",
+ n64graphics_get_read_version(), n64graphics_get_write_version());
}
// parse command line arguments
static int parse_arguments(int argc, char *argv[], graphics_config *config)
{
- for (int i = 1; i < argc; i++) {
- if (argv[i][0] == '-') {
- switch (argv[i][1]) {
- case 'c':
- if (++i >= argc) return 0;
- if (!parse_format(&config->pal_format, argv[i])) {
- return 0;
- }
- break;
- case 'e':
- if (++i >= argc) return 0;
- config->bin_filename = argv[i];
- config->mode = MODE_EXPORT;
- break;
- case 'f':
- if (++i >= argc) return 0;
- if (!parse_format(&config->format, argv[i])) {
- return 0;
- }
- break;
- case 'g':
- if (++i >= argc) return 0;
- config->img_filename = argv[i];
- break;
- case 'h':
- if (++i >= argc) return 0;
- config->height = strtoul(argv[i], NULL, 0);
- break;
- case 'i':
- if (++i >= argc) return 0;
- config->bin_filename = argv[i];
- config->mode = MODE_IMPORT;
- break;
- case 'o':
- if (++i >= argc) return 0;
- config->bin_offset = strtoul(argv[i], NULL, 0);
- config->bin_truncate = 0;
- break;
- case 'p':
- if (++i >= argc) return 0;
- config->pal_filename = argv[i];
- break;
- case 'P':
- if (++i >= argc) return 0;
- config->pal_offset = strtoul(argv[i], NULL, 0);
- config->pal_truncate = 0;
- break;
- case 'v':
- g_verbosity = 1;
- break;
- case 'V':
- print_version();
- exit(0);
- break;
- case 'w':
- if (++i >= argc) return 0;
- config->width = strtoul(argv[i], NULL, 0);
- break;
- default:
- return 0;
- break;
- }
- } else {
- return 0;
- }
- }
- return 1;
+ for (int i = 1; i < argc; i++)
+ {
+ if (argv[i][0] == '-')
+ {
+ switch (argv[i][1])
+ {
+ case 'c':
+ if (++i >= argc) return 0;
+ if (!parse_format(&config->pal_format, argv[i]))
+ {
+ return 0;
+ }
+ break;
+ case 'e':
+ if (++i >= argc) return 0;
+ config->bin_filename = argv[i];
+ config->mode = MODE_EXPORT;
+ break;
+ case 'f':
+ if (++i >= argc) return 0;
+ if (!parse_format(&config->format, argv[i]))
+ {
+ return 0;
+ }
+ break;
+ case 'g':
+ if (++i >= argc) return 0;
+ config->img_filename = argv[i];
+ break;
+ case 'h':
+ if (++i >= argc) return 0;
+ config->height = strtoul(argv[i], NULL, 0);
+ break;
+ case 'i':
+ if (++i >= argc) return 0;
+ config->bin_filename = argv[i];
+ config->mode = MODE_IMPORT;
+ break;
+ case 'o':
+ if (++i >= argc) return 0;
+ config->bin_offset = strtoul(argv[i], NULL, 0);
+ config->bin_truncate = 0;
+ break;
+ case 'p':
+ if (++i >= argc) return 0;
+ config->pal_filename = argv[i];
+ break;
+ case 'P':
+ if (++i >= argc) return 0;
+ config->pal_offset = strtoul(argv[i], NULL, 0);
+ config->pal_truncate = 0;
+ break;
+ case 'v':
+ g_verbosity = 1;
+ break;
+ case 'V':
+ print_version();
+ exit(0);
+ break;
+ case 'w':
+ if (++i >= argc) return 0;
+ config->width = strtoul(argv[i], NULL, 0);
+ break;
+ default:
+ return 0;
+ break;
+ }
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ return 1;
}
// returns 1 if config is valid
static int valid_config(const graphics_config *config)
{
- if (!config->bin_filename || !config->img_filename) {
- return 0;
- }
- if (config->format.format == IMG_FORMAT_CI) {
- if (!config->pal_filename || (config->pal_format.depth != 16) ||
- (config->pal_format.format != IMG_FORMAT_RGBA && config->pal_format.format != IMG_FORMAT_IA)) {
- return 0;
- }
- }
- return 1;
+ if (!config->bin_filename || !config->img_filename)
+ {
+ return 0;
+ }
+ if (config->format.format == IMG_FORMAT_CI)
+ {
+ if (!config->pal_filename || (config->pal_format.depth != 16) ||
+ (config->pal_format.format != IMG_FORMAT_RGBA && config->pal_format.format != IMG_FORMAT_IA))
+ {
+ return 0;
+ }
+ }
+ return 1;
}
int main(int argc, char *argv[])
{
- graphics_config config = default_config;
- rgba *imgr;
- ia *imgi;
- FILE *bin_fp;
- uint8_t *raw;
- int raw_size;
- int length = 0;
- int flength;
- int res;
+ graphics_config config = default_config;
+ rgba *imgr;
+ ia *imgi;
+ FILE *bin_fp;
+ uint8_t *raw;
+ int raw_size;
+ int length = 0;
+ int flength;
+ int res;
- int valid = parse_arguments(argc, argv, &config);
- if (!valid || !valid_config(&config)) {
- print_usage();
- exit(EXIT_FAILURE);
- }
+ int valid = parse_arguments(argc, argv, &config);
+ if (!valid || !valid_config(&config))
+ {
+ print_usage();
+ exit(EXIT_FAILURE);
+ }
- if (config.mode == MODE_IMPORT) {
- if (config.bin_truncate) {
- bin_fp = fopen(config.bin_filename, "wb");
- } else {
- bin_fp = fopen(config.bin_filename, "r+b");
- }
- if (!bin_fp) {
- ERROR("Error opening \"%s\"\n", config.bin_filename);
- return -1;
- }
- if (!config.bin_truncate) {
- fseek(bin_fp, config.bin_offset, SEEK_SET);
- }
- switch (config.format.format) {
- case IMG_FORMAT_RGBA:
- imgr = png2rgba(config.img_filename, &config.width, &config.height);
- raw_size = (config.width * config.height * config.format.depth + 7) / 8;
- raw = malloc(raw_size);
- if (!raw) {
- ERROR("Error allocating %u bytes\n", raw_size);
- }
- length = rgba2raw(raw, imgr, config.width, config.height, config.format.depth);
- break;
- case IMG_FORMAT_IA:
- imgi = png2ia(config.img_filename, &config.width, &config.height);
- raw_size = (config.width * config.height * config.format.depth + 7) / 8;
- raw = malloc(raw_size);
- if (!raw) {
- ERROR("Error allocating %u bytes\n", raw_size);
- }
- length = ia2raw(raw, imgi, config.width, config.height, config.format.depth);
- break;
- case IMG_FORMAT_I:
- imgi = png2ia(config.img_filename, &config.width, &config.height);
- raw_size = (config.width * config.height * config.format.depth + 7) / 8;
- raw = malloc(raw_size);
- if (!raw) {
- ERROR("Error allocating %u bytes\n", raw_size);
- }
- length = i2raw(raw, imgi, config.width, config.height, config.format.depth);
- break;
- case IMG_FORMAT_CI:
- {
- palette_t pal;
- FILE *pal_fp;
- uint8_t *raw16;
- int raw16_size;
- int raw16_length;
- uint8_t *ci;
- int ci_length;
- int pal_success;
- int pal_length;
+ if (config.mode == MODE_IMPORT)
+ {
+ if (config.bin_truncate)
+ {
+ bin_fp = fopen(config.bin_filename, "wb");
+ }
+ else
+ {
+ bin_fp = fopen(config.bin_filename, "r+b");
+ }
+ if (!bin_fp)
+ {
+ ERROR("Error opening \"%s\"\n", config.bin_filename);
+ return -1;
+ }
+ if (!config.bin_truncate)
+ {
+ fseek(bin_fp, config.bin_offset, SEEK_SET);
+ }
+ switch (config.format.format)
+ {
+ case IMG_FORMAT_RGBA:
+ imgr = png2rgba(config.img_filename, &config.width, &config.height);
+ raw_size = (config.width * config.height * config.format.depth + 7) / 8;
+ raw = malloc(raw_size);
+ if (!raw)
+ {
+ ERROR("Error allocating %u bytes\n", raw_size);
+ }
+ length = rgba2raw(raw, imgr, config.width, config.height, config.format.depth);
+ break;
+ case IMG_FORMAT_IA:
+ imgi = png2ia(config.img_filename, &config.width, &config.height);
+ raw_size = (config.width * config.height * config.format.depth + 7) / 8;
+ raw = malloc(raw_size);
+ if (!raw)
+ {
+ ERROR("Error allocating %u bytes\n", raw_size);
+ }
+ length = ia2raw(raw, imgi, config.width, config.height, config.format.depth);
+ break;
+ case IMG_FORMAT_I:
+ imgi = png2ia(config.img_filename, &config.width, &config.height);
+ raw_size = (config.width * config.height * config.format.depth + 7) / 8;
+ raw = malloc(raw_size);
+ if (!raw)
+ {
+ ERROR("Error allocating %u bytes\n", raw_size);
+ }
+ length = i2raw(raw, imgi, config.width, config.height, config.format.depth);
+ break;
+ case IMG_FORMAT_CI:
+ {
+ palette_t pal;
+ FILE *pal_fp;
+ uint8_t *raw16;
+ int raw16_size;
+ int raw16_length;
+ uint8_t *ci;
+ int ci_length;
+ int pal_success;
+ int pal_length;
- if (config.pal_truncate) {
- pal_fp = fopen(config.pal_filename, "wb");
- } else {
- pal_fp = fopen(config.pal_filename, "r+b");
- }
- if (!pal_fp) {
- ERROR("Error opening \"%s\"\n", config.pal_filename);
- return EXIT_FAILURE;
- }
- if (!config.pal_truncate) {
- fseek(pal_fp, config.bin_offset, SEEK_SET);
- }
+ if (config.pal_truncate)
+ {
+ pal_fp = fopen(config.pal_filename, "wb");
+ }
+ else
+ {
+ pal_fp = fopen(config.pal_filename, "r+b");
+ }
+ if (!pal_fp)
+ {
+ ERROR("Error opening \"%s\"\n", config.pal_filename);
+ return EXIT_FAILURE;
+ }
+ if (!config.pal_truncate)
+ {
+ fseek(pal_fp, config.bin_offset, SEEK_SET);
+ }
- raw16_size = config.width * config.height * config.pal_format.depth / 8;
- raw16 = malloc(raw16_size);
- if (!raw16) {
- ERROR("Error allocating %d bytes\n", raw16_size);
- return EXIT_FAILURE;
- }
- switch (config.pal_format.format) {
- case IMG_FORMAT_RGBA:
- imgr = png2rgba(config.img_filename, &config.width, &config.height);
- raw16_length = rgba2raw(raw16, imgr, config.width, config.height, config.pal_format.depth);
- break;
- case IMG_FORMAT_IA:
- imgi = png2ia(config.img_filename, &config.width, &config.height);
- raw16_length = ia2raw(raw16, imgi, config.width, config.height, config.pal_format.depth);
- break;
- default:
- ERROR("Unsupported palette format: %s\n", format2str(&config.pal_format));
- exit(EXIT_FAILURE);
- }
+ raw16_size = config.width * config.height * config.pal_format.depth / 8;
+ raw16 = malloc(raw16_size);
+ if (!raw16)
+ {
+ ERROR("Error allocating %d bytes\n", raw16_size);
+ return EXIT_FAILURE;
+ }
+ switch (config.pal_format.format)
+ {
+ case IMG_FORMAT_RGBA:
+ imgr = png2rgba(config.img_filename, &config.width, &config.height);
+ raw16_length = rgba2raw(raw16, imgr, config.width, config.height, config.pal_format.depth);
+ break;
+ case IMG_FORMAT_IA:
+ imgi = png2ia(config.img_filename, &config.width, &config.height);
+ raw16_length = ia2raw(raw16, imgi, config.width, config.height, config.pal_format.depth);
+ break;
+ default:
+ ERROR("Unsupported palette format: %s\n", format2str(&config.pal_format));
+ exit(EXIT_FAILURE);
+ }
- // convert raw to palette
- pal.max = (1 << config.format.depth);
- ci_length = config.width * config.height * config.format.depth / 8;
- ci = malloc(ci_length);
- pal_success = raw2ci(ci, &pal, raw16, raw16_length, config.format.depth);
- if (!pal_success) {
- ERROR("Error converting palette\n");
- exit(EXIT_FAILURE);
- }
+ // convert raw to palette
+ pal.max = (1 << config.format.depth);
+ ci_length = config.width * config.height * config.format.depth / 8;
+ ci = malloc(ci_length);
+ pal_success = raw2ci(ci, &pal, raw16, raw16_length, config.format.depth);
+ if (!pal_success)
+ {
+ ERROR("Error converting palette\n");
+ exit(EXIT_FAILURE);
+ }
- pal_length = pal.max * sizeof(pal.data[0]);
- INFO("Writing 0x%X bytes to offset 0x%X of \"%s\"\n", pal_length, config.pal_offset, config.pal_filename);
- flength = 0;
- for (int i = 0; i < pal.max; i++) {
- uint8_t entry[2];
- write_u16_be(entry, pal.data[i]);
- flength += fwrite(entry, 1, sizeof(entry), pal_fp);
- }
- if (flength != pal_length) {
- ERROR("Error writing %d bytes to \"%s\"\n", pal_length, config.pal_filename);
- }
+ pal_length = pal.max * sizeof(pal.data[0]);
+ INFO("Writing 0x%X bytes to offset 0x%X of \"%s\"\n", pal_length, config.pal_offset, config.pal_filename);
+ flength = 0;
+ for (int i = 0; i < pal.max; i++)
+ {
+ uint8_t entry[2];
+ write_u16_be(entry, pal.data[i]);
+ flength += fwrite(entry, 1, sizeof(entry), pal_fp);
+ }
+ if (flength != pal_length)
+ {
+ ERROR("Error writing %d bytes to \"%s\"\n", pal_length, config.pal_filename);
+ }
- raw = ci;
- length = ci_length;
+ raw = ci;
+ length = ci_length;
- free(raw16);
- fclose(pal_fp);
- break;
- }
- default:
+ free(raw16);
+ fclose(pal_fp);
+ break;
+ }
+ default:
+ return EXIT_FAILURE;
+ }
+ if (length <= 0)
+ {
+ ERROR("Error converting to raw format\n");
return EXIT_FAILURE;
- }
- if (length <= 0) {
- ERROR("Error converting to raw format\n");
- return EXIT_FAILURE;
- }
- INFO("Writing 0x%X bytes to offset 0x%X of \"%s\"\n", length, config.bin_offset, config.bin_filename);
- flength = fwrite(raw, 1, length, bin_fp);
- if (flength != length) {
- ERROR("Error writing %d bytes to \"%s\"\n", length, config.bin_filename);
- }
- fclose(bin_fp);
-
- } else {
- if (config.width <= 0 || config.height <= 0 || config.format.depth <= 0) {
- ERROR("Error: must set position width and height for export\n");
- return EXIT_FAILURE;
- }
- bin_fp = fopen(config.bin_filename, "rb");
- if (!bin_fp) {
- ERROR("Error opening \"%s\"\n", config.bin_filename);
- return -1;
- }
- raw_size = (config.width * config.height * config.format.depth + 7) / 8;
- raw = malloc(raw_size);
- if (config.bin_offset > 0) {
- fseek(bin_fp, config.bin_offset, SEEK_SET);
- }
- flength = fread(raw, 1, raw_size, bin_fp);
- if (flength != raw_size) {
- ERROR("Error reading %d bytes from \"%s\"\n", raw_size, config.bin_filename);
- }
- switch (config.format.format) {
- case IMG_FORMAT_RGBA:
- imgr = raw2rgba(raw, config.width, config.height, config.format.depth);
- res = rgba2png(config.img_filename, imgr, config.width, config.height);
- break;
- case IMG_FORMAT_IA:
- imgi = raw2ia(raw, config.width, config.height, config.format.depth);
- res = ia2png(config.img_filename, imgi, config.width, config.height);
- break;
- case IMG_FORMAT_I:
- imgi = raw2i(raw, config.width, config.height, config.format.depth);
- res = ia2png(config.img_filename, imgi, config.width, config.height);
- break;
- case IMG_FORMAT_CI:
- {
- FILE *pal_fp;
- uint8_t *pal;
- uint8_t *raw_fmt;
- int pal_size;
-
- INFO("Extracting %s offset 0x%X, pal.offset 0x%0X, pal.format %s\n", format2str(&config.format),
- config.bin_offset, config.pal_offset, format2str(&config.pal_format));
-
- pal_fp = fopen(config.pal_filename, "rb");
- if (!pal_fp) {
- ERROR("Error opening \"%s\"\n", config.bin_filename);
- return EXIT_FAILURE;
- }
- if (config.pal_offset > 0) {
- fseek(pal_fp, config.pal_offset, SEEK_SET);
- }
-
- pal_size = sizeof(uint16_t) * (1 << config.format.depth);
- INFO("Palette size: %d\n", pal_size);
- pal = malloc(pal_size);
- flength = fread(pal, 1, pal_size, pal_fp);
- if (flength != pal_size) {
- ERROR("Error reading %d bytes from \"%s\"\n", pal_size, config.pal_filename);
- }
- raw_fmt = ci2raw(raw, pal, config.width, config.height, config.format.depth);
- switch (config.pal_format.format) {
- case IMG_FORMAT_RGBA:
- INFO("Converting raw to RGBA16\n");
- imgr = raw2rgba(raw_fmt, config.width, config.height, config.pal_format.depth);
- res = rgba2png(config.img_filename, imgr, config.width, config.height);
- break;
- case IMG_FORMAT_IA:
- INFO("Converting raw to IA16\n");
- imgi = raw2ia(raw_fmt, config.width, config.height, config.pal_format.depth);
- res = ia2png(config.img_filename, imgi, config.width, config.height);
- break;
- default:
- ERROR("Unsupported palette format: %s\n", format2str(&config.pal_format));
- return EXIT_FAILURE;
- }
- free(raw_fmt);
- free(pal);
- break;
- }
- default:
+ }
+ INFO("Writing 0x%X bytes to offset 0x%X of \"%s\"\n", length, config.bin_offset, config.bin_filename);
+ flength = fwrite(raw, 1, length, bin_fp);
+ if (flength != length)
+ {
+ ERROR("Error writing %d bytes to \"%s\"\n", length, config.bin_filename);
+ }
+ fclose(bin_fp);
+ }
+ else
+ {
+ if (config.width <= 0 || config.height <= 0 || config.format.depth <= 0)
+ {
+ ERROR("Error: must set position width and height for export\n");
return EXIT_FAILURE;
- }
- if (!res) {
- ERROR("Error writing to \"%s\"\n", config.img_filename);
- return EXIT_FAILURE;
- }
- }
+ }
+ bin_fp = fopen(config.bin_filename, "rb");
+ if (!bin_fp)
+ {
+ ERROR("Error opening \"%s\"\n", config.bin_filename);
+ return -1;
+ }
+ raw_size = (config.width * config.height * config.format.depth + 7) / 8;
+ raw = malloc(raw_size);
+ if (config.bin_offset > 0)
+ {
+ fseek(bin_fp, config.bin_offset, SEEK_SET);
+ }
+ flength = fread(raw, 1, raw_size, bin_fp);
+ if (flength != raw_size)
+ {
+ ERROR("Error reading %d bytes from \"%s\"\n", raw_size, config.bin_filename);
+ }
+ switch (config.format.format)
+ {
+ case IMG_FORMAT_RGBA:
+ imgr = raw2rgba(raw, config.width, config.height, config.format.depth);
+ res = rgba2png(config.img_filename, imgr, config.width, config.height);
+ break;
+ case IMG_FORMAT_IA:
+ imgi = raw2ia(raw, config.width, config.height, config.format.depth);
+ res = ia2png(config.img_filename, imgi, config.width, config.height);
+ break;
+ case IMG_FORMAT_I:
+ imgi = raw2i(raw, config.width, config.height, config.format.depth);
+ res = ia2png(config.img_filename, imgi, config.width, config.height);
+ break;
+ case IMG_FORMAT_CI:
+ {
+ FILE *pal_fp;
+ uint8_t *pal;
+ uint8_t *raw_fmt;
+ int pal_size;
- return EXIT_SUCCESS;
+ INFO("Extracting %s offset 0x%X, pal.offset 0x%0X, pal.format %s\n", format2str(&config.format),
+ config.bin_offset, config.pal_offset, format2str(&config.pal_format));
+
+ pal_fp = fopen(config.pal_filename, "rb");
+ if (!pal_fp)
+ {
+ ERROR("Error opening \"%s\"\n", config.bin_filename);
+ return EXIT_FAILURE;
+ }
+ if (config.pal_offset > 0)
+ {
+ fseek(pal_fp, config.pal_offset, SEEK_SET);
+ }
+
+ pal_size = sizeof(uint16_t) * (1 << config.format.depth);
+ INFO("Palette size: %d\n", pal_size);
+ pal = malloc(pal_size);
+ flength = fread(pal, 1, pal_size, pal_fp);
+ if (flength != pal_size)
+ {
+ ERROR("Error reading %d bytes from \"%s\"\n", pal_size, config.pal_filename);
+ }
+ raw_fmt = ci2raw(raw, pal, config.width, config.height, config.format.depth);
+ switch (config.pal_format.format)
+ {
+ case IMG_FORMAT_RGBA:
+ INFO("Converting raw to RGBA16\n");
+ imgr = raw2rgba(raw_fmt, config.width, config.height, config.pal_format.depth);
+ res = rgba2png(config.img_filename, imgr, config.width, config.height);
+ break;
+ case IMG_FORMAT_IA:
+ INFO("Converting raw to IA16\n");
+ imgi = raw2ia(raw_fmt, config.width, config.height, config.pal_format.depth);
+ res = ia2png(config.img_filename, imgi, config.width, config.height);
+ break;
+ default:
+ ERROR("Unsupported palette format: %s\n", format2str(&config.pal_format));
+ return EXIT_FAILURE;
+ }
+ free(raw_fmt);
+ free(pal);
+ break;
+ }
+ default:
+ return EXIT_FAILURE;
+ }
+ if (!res)
+ {
+ ERROR("Error writing to \"%s\"\n", config.img_filename);
+ return EXIT_FAILURE;
+ }
+ }
+
+ return EXIT_SUCCESS;
}
#endif // N64GRAPHICS_STANDALONE
diff --git a/src/decomp/tools/n64graphics.h b/src/decomp/tools/n64graphics.h
index 9ced50e..1150915 100644
--- a/src/decomp/tools/n64graphics.h
+++ b/src/decomp/tools/n64graphics.h
@@ -6,24 +6,24 @@
// intermediate formats
typedef struct _rgba
{
- uint8_t red;
- uint8_t green;
- uint8_t blue;
- uint8_t alpha;
+ uint8_t red;
+ uint8_t green;
+ uint8_t blue;
+ uint8_t alpha;
} rgba;
typedef struct _ia
{
- uint8_t intensity;
- uint8_t alpha;
+ uint8_t intensity;
+ uint8_t alpha;
} ia;
// CI palette
typedef struct
{
- uint16_t data[256];
- int max; // max number of entries
- int used; // number of entries used
+ uint16_t data[256];
+ int max; // max number of entries
+ int used; // number of entries used
} palette_t;
//---------------------------------------------------------
diff --git a/src/decomp/tools/stb/stb_image.h b/src/decomp/tools/stb/stb_image.h
index d9c21bc..b64d361 100644
--- a/src/decomp/tools/stb/stb_image.h
+++ b/src/decomp/tools/stb/stb_image.h
@@ -311,19 +311,22 @@ RECENT REVISION HISTORY:
enum
{
- STBI_default = 0, // only used for desired_channels
+ STBI_default = 0,
+ // only used for desired_channels
- STBI_grey = 1,
- STBI_grey_alpha = 2,
- STBI_rgb = 3,
- STBI_rgb_alpha = 4
+ STBI_grey = 1,
+ STBI_grey_alpha = 2,
+ STBI_rgb = 3,
+ STBI_rgb_alpha = 4
};
typedef unsigned char stbi_uc;
typedef unsigned short stbi_us;
#ifdef __cplusplus
-extern "C" {
+extern "C"
+{
+
#endif
#ifdef STB_IMAGE_STATIC
@@ -343,9 +346,9 @@ extern "C" {
typedef struct
{
- int (*read) (void *user,char *data,int size); // fill 'data' with 'size' bytes. return number of bytes actually read
- void (*skip) (void *user,int n); // skip the next 'n' bytes, or 'unget' the last -n bytes if negative
- int (*eof) (void *user); // returns nonzero if we are at end of file/data
+ int (*read)(void *user, char *data, int size); // fill 'data' with 'size' bytes. return number of bytes actually read
+ void (*skip)(void *user, int n); // skip the next 'n' bytes, or 'unget' the last -n bytes if negative
+ int (*eof)(void *user); // returns nonzero if we are at end of file/data
} stbi_io_callbacks;
////////////////////////////////////
@@ -353,16 +356,19 @@ typedef struct
// 8-bits-per-channel interface
//
-STBIDEF stbi_uc *stbi_load_from_memory (stbi_uc const *buffer, int len , int *x, int *y, int *channels_in_file, int desired_channels);
-STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk , void *user, int *x, int *y, int *channels_in_file, int desired_channels);
+STBIDEF stbi_uc *stbi_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *channels_in_file, int desired_channels);
+
+STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *channels_in_file, int desired_channels);
#ifndef STBI_NO_GIF
STBIDEF stbi_uc *stbi_load_gif_from_memory(stbi_uc const *buffer, int len, int **delays, int *x, int *y, int *z, int *comp, int req_comp);
#endif
#ifndef STBI_NO_STDIO
-STBIDEF stbi_uc *stbi_load (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels);
-STBIDEF stbi_uc *stbi_load_from_file (FILE *f, int *x, int *y, int *channels_in_file, int desired_channels);
+STBIDEF stbi_uc *stbi_load(char const *filename, int *x, int *y, int *channels_in_file, int desired_channels);
+
+STBIDEF stbi_uc *stbi_load_from_file(FILE *f, int *x, int *y, int *channels_in_file, int desired_channels);
+
// for stbi_load_from_file, file pointer is left pointing immediately after image
#endif
@@ -371,11 +377,13 @@ STBIDEF stbi_uc *stbi_load_from_file (FILE *f, int *x, int *y, int *channels_in
// 16-bits-per-channel interface
//
-STBIDEF stbi_us *stbi_load_16_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *channels_in_file, int desired_channels);
+STBIDEF stbi_us *stbi_load_16_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *channels_in_file, int desired_channels);
+
STBIDEF stbi_us *stbi_load_16_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *channels_in_file, int desired_channels);
#ifndef STBI_NO_STDIO
-STBIDEF stbi_us *stbi_load_16 (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels);
+STBIDEF stbi_us *stbi_load_16(char const *filename, int *x, int *y, int *channels_in_file, int desired_channels);
+
STBIDEF stbi_us *stbi_load_from_file_16(FILE *f, int *x, int *y, int *channels_in_file, int desired_channels);
#endif
@@ -384,54 +392,65 @@ STBIDEF stbi_us *stbi_load_from_file_16(FILE *f, int *x, int *y, int *channels_i
// float-per-channel interface
//
#ifndef STBI_NO_LINEAR
- STBIDEF float *stbi_loadf_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *channels_in_file, int desired_channels);
- STBIDEF float *stbi_loadf_from_callbacks (stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *channels_in_file, int desired_channels);
+STBIDEF float *stbi_loadf_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *channels_in_file, int desired_channels);
- #ifndef STBI_NO_STDIO
- STBIDEF float *stbi_loadf (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels);
- STBIDEF float *stbi_loadf_from_file (FILE *f, int *x, int *y, int *channels_in_file, int desired_channels);
- #endif
+STBIDEF float *stbi_loadf_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *channels_in_file, int desired_channels);
+
+#ifndef STBI_NO_STDIO
+STBIDEF float *stbi_loadf(char const *filename, int *x, int *y, int *channels_in_file, int desired_channels);
+
+STBIDEF float *stbi_loadf_from_file(FILE *f, int *x, int *y, int *channels_in_file, int desired_channels);
+#endif
#endif
#ifndef STBI_NO_HDR
- STBIDEF void stbi_hdr_to_ldr_gamma(float gamma);
- STBIDEF void stbi_hdr_to_ldr_scale(float scale);
+STBIDEF void stbi_hdr_to_ldr_gamma(float gamma);
+
+STBIDEF void stbi_hdr_to_ldr_scale(float scale);
#endif // STBI_NO_HDR
#ifndef STBI_NO_LINEAR
- STBIDEF void stbi_ldr_to_hdr_gamma(float gamma);
- STBIDEF void stbi_ldr_to_hdr_scale(float scale);
+STBIDEF void stbi_ldr_to_hdr_gamma(float gamma);
+
+STBIDEF void stbi_ldr_to_hdr_scale(float scale);
#endif // STBI_NO_LINEAR
// stbi_is_hdr is always defined, but always returns false if STBI_NO_HDR
-STBIDEF int stbi_is_hdr_from_callbacks(stbi_io_callbacks const *clbk, void *user);
-STBIDEF int stbi_is_hdr_from_memory(stbi_uc const *buffer, int len);
+STBIDEF int stbi_is_hdr_from_callbacks(stbi_io_callbacks const *clbk, void *user);
+
+STBIDEF int stbi_is_hdr_from_memory(stbi_uc const *buffer, int len);
#ifndef STBI_NO_STDIO
-STBIDEF int stbi_is_hdr (char const *filename);
-STBIDEF int stbi_is_hdr_from_file(FILE *f);
+STBIDEF int stbi_is_hdr(char const *filename);
+
+STBIDEF int stbi_is_hdr_from_file(FILE *f);
#endif // STBI_NO_STDIO
// get a VERY brief reason for failure
// NOT THREADSAFE
-STBIDEF const char *stbi_failure_reason (void);
+STBIDEF const char *stbi_failure_reason(void);
// free the loaded image -- this is just free()
-STBIDEF void stbi_image_free (void *retval_from_stbi_load);
+STBIDEF void stbi_image_free(void *retval_from_stbi_load);
// get image dimensions & components without fully decoding
-STBIDEF int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp);
-STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp);
-STBIDEF int stbi_is_16_bit_from_memory(stbi_uc const *buffer, int len);
-STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const *clbk, void *user);
+STBIDEF int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp);
+
+STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp);
+
+STBIDEF int stbi_is_16_bit_from_memory(stbi_uc const *buffer, int len);
+
+STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const *clbk, void *user);
#ifndef STBI_NO_STDIO
-STBIDEF int stbi_info (char const *filename, int *x, int *y, int *comp);
-STBIDEF int stbi_info_from_file (FILE *f, int *x, int *y, int *comp);
-STBIDEF int stbi_is_16_bit (char const *filename);
-STBIDEF int stbi_is_16_bit_from_file(FILE *f);
-#endif
+STBIDEF int stbi_info(char const *filename, int *x, int *y, int *comp);
+STBIDEF int stbi_info_from_file(FILE *f, int *x, int *y, int *comp);
+
+STBIDEF int stbi_is_16_bit(char const *filename);
+
+STBIDEF int stbi_is_16_bit_from_file(FILE *f);
+#endif
// for image formats that explicitly notate that they have premultiplied alpha,
@@ -449,12 +468,16 @@ STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip);
// ZLIB client - used by PNG, available for other purposes
STBIDEF char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen);
+
STBIDEF char *stbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, int len, int initial_size, int *outlen, int parse_header);
+
STBIDEF char *stbi_zlib_decode_malloc(const char *buffer, int len, int *outlen);
-STBIDEF int stbi_zlib_decode_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);
+
+STBIDEF int stbi_zlib_decode_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);
STBIDEF char *stbi_zlib_decode_noheader_malloc(const char *buffer, int len, int *outlen);
-STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);
+
+STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);
#ifdef __cplusplus
@@ -472,33 +495,33 @@ STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const ch
|| defined(STBI_ONLY_TGA) || defined(STBI_ONLY_GIF) || defined(STBI_ONLY_PSD) \
|| defined(STBI_ONLY_HDR) || defined(STBI_ONLY_PIC) || defined(STBI_ONLY_PNM) \
|| defined(STBI_ONLY_ZLIB)
- #ifndef STBI_ONLY_JPEG
- #define STBI_NO_JPEG
- #endif
- #ifndef STBI_ONLY_PNG
- #define STBI_NO_PNG
- #endif
- #ifndef STBI_ONLY_BMP
- #define STBI_NO_BMP
- #endif
- #ifndef STBI_ONLY_PSD
- #define STBI_NO_PSD
- #endif
- #ifndef STBI_ONLY_TGA
- #define STBI_NO_TGA
- #endif
- #ifndef STBI_ONLY_GIF
- #define STBI_NO_GIF
- #endif
- #ifndef STBI_ONLY_HDR
- #define STBI_NO_HDR
- #endif
- #ifndef STBI_ONLY_PIC
- #define STBI_NO_PIC
- #endif
- #ifndef STBI_ONLY_PNM
- #define STBI_NO_PNM
- #endif
+#ifndef STBI_ONLY_JPEG
+#define STBI_NO_JPEG
+#endif
+#ifndef STBI_ONLY_PNG
+#define STBI_NO_PNG
+#endif
+#ifndef STBI_ONLY_BMP
+#define STBI_NO_BMP
+#endif
+#ifndef STBI_ONLY_PSD
+#define STBI_NO_PSD
+#endif
+#ifndef STBI_ONLY_TGA
+#define STBI_NO_TGA
+#endif
+#ifndef STBI_ONLY_GIF
+#define STBI_NO_GIF
+#endif
+#ifndef STBI_ONLY_HDR
+#define STBI_NO_HDR
+#endif
+#ifndef STBI_ONLY_PIC
+#define STBI_NO_PIC
+#endif
+#ifndef STBI_ONLY_PNM
+#define STBI_NO_PNM
+#endif
#endif
#if defined(STBI_NO_PNG) && !defined(STBI_SUPPORT_ZLIB) && !defined(STBI_NO_ZLIB)
@@ -527,31 +550,31 @@ STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const ch
#ifndef _MSC_VER
- #ifdef __cplusplus
- #define stbi_inline inline
- #else
- #define stbi_inline
- #endif
+#ifdef __cplusplus
+#define stbi_inline inline
#else
- #define stbi_inline __forceinline
+#define stbi_inline
+#endif
+#else
+#define stbi_inline __forceinline
#endif
#ifdef _MSC_VER
typedef unsigned short stbi__uint16;
-typedef signed short stbi__int16;
-typedef unsigned int stbi__uint32;
-typedef signed int stbi__int32;
+typedef signed short stbi__int16;
+typedef unsigned int stbi__uint32;
+typedef signed int stbi__int32;
#else
#include
typedef uint16_t stbi__uint16;
-typedef int16_t stbi__int16;
+typedef int16_t stbi__int16;
typedef uint32_t stbi__uint32;
-typedef int32_t stbi__int32;
+typedef int32_t stbi__int32;
#endif
// should produce compiler error if size is wrong
-typedef unsigned char validate_uint32[sizeof(stbi__uint32)==4 ? 1 : -1];
+typedef unsigned char validate_uint32[sizeof(stbi__uint32) == 4 ? 1 : -1];
#ifdef _MSC_VER
#define STBI_NOTUSED(v) (void)(v)
@@ -564,9 +587,9 @@ typedef unsigned char validate_uint32[sizeof(stbi__uint32)==4 ? 1 : -1];
#endif
#ifdef STBI_HAS_LROTL
- #define stbi_lrot(x,y) _lrotl(x,y)
+#define stbi_lrot(x,y) _lrotl(x,y)
#else
- #define stbi_lrot(x,y) (((x) << (y)) | ((x) >> (32 - (y))))
+#define stbi_lrot(x,y) (((x) << (y)) | ((x) >> (32 - (y))))
#endif
#if defined(STBI_MALLOC) && defined(STBI_FREE) && (defined(STBI_REALLOC) || defined(STBI_REALLOC_SIZED))
@@ -630,20 +653,20 @@ typedef unsigned char validate_uint32[sizeof(stbi__uint32)==4 ? 1 : -1];
#include // __cpuid
static int stbi__cpuid3(void)
{
- int info[4];
- __cpuid(info,1);
- return info[3];
+ int info[4];
+ __cpuid(info, 1);
+ return info[3];
}
#else
static int stbi__cpuid3(void)
{
- int res;
- __asm {
- mov eax,1
- cpuid
- mov res,edx
- }
- return res;
+ int res;
+ __asm {
+ mov eax,1
+ cpuid
+ mov res,edx
+ }
+ return res;
}
#endif
@@ -651,18 +674,18 @@ static int stbi__cpuid3(void)
static int stbi__sse2_available(void)
{
- int info3 = stbi__cpuid3();
- return ((info3 >> 26) & 1) != 0;
+ int info3 = stbi__cpuid3();
+ return ((info3 >> 26) & 1) != 0;
}
#else // assume GCC-style if not VC++
#define STBI_SIMD_ALIGN(type, name) type name __attribute__((aligned(16)))
static int stbi__sse2_available(void)
{
- // If we're even attempting to compile this on GCC/Clang, that means
- // -msse2 is on, which means the compiler is allowed to use SSE2
- // instructions at will, and so are we.
- return 1;
+ // If we're even attempting to compile this on GCC/Clang, that means
+ // -msse2 is on, which means the compiler is allowed to use SSE2
+ // instructions at will, and so are we.
+ return 1;
}
#endif
#endif
@@ -690,18 +713,18 @@ static int stbi__sse2_available(void)
// contains all the IO context, plus some basic image information
typedef struct
{
- stbi__uint32 img_x, img_y;
- int img_n, img_out_n;
+ stbi__uint32 img_x, img_y;
+ int img_n, img_out_n;
- stbi_io_callbacks io;
- void *io_user_data;
+ stbi_io_callbacks io;
+ void *io_user_data;
- int read_from_callbacks;
- int buflen;
- stbi_uc buffer_start[128];
+ int read_from_callbacks;
+ int buflen;
+ stbi_uc buffer_start[128];
- stbi_uc *img_buffer, *img_buffer_end;
- stbi_uc *img_buffer_original, *img_buffer_original_end;
+ stbi_uc *img_buffer, *img_buffer_end;
+ stbi_uc *img_buffer_original, *img_buffer_original_end;
} stbi__context;
@@ -710,51 +733,51 @@ static void stbi__refill_buffer(stbi__context *s);
// initialize a memory-decode context
static void stbi__start_mem(stbi__context *s, stbi_uc const *buffer, int len)
{
- s->io.read = NULL;
- s->read_from_callbacks = 0;
- s->img_buffer = s->img_buffer_original = (stbi_uc *) buffer;
- s->img_buffer_end = s->img_buffer_original_end = (stbi_uc *) buffer+len;
+ s->io.read = NULL;
+ s->read_from_callbacks = 0;
+ s->img_buffer = s->img_buffer_original = (stbi_uc *)buffer;
+ s->img_buffer_end = s->img_buffer_original_end = (stbi_uc *)buffer + len;
}
// initialize a callback-based context
static void stbi__start_callbacks(stbi__context *s, stbi_io_callbacks *c, void *user)
{
- s->io = *c;
- s->io_user_data = user;
- s->buflen = sizeof(s->buffer_start);
- s->read_from_callbacks = 1;
- s->img_buffer_original = s->buffer_start;
- stbi__refill_buffer(s);
- s->img_buffer_original_end = s->img_buffer_end;
+ s->io = *c;
+ s->io_user_data = user;
+ s->buflen = sizeof(s->buffer_start);
+ s->read_from_callbacks = 1;
+ s->img_buffer_original = s->buffer_start;
+ stbi__refill_buffer(s);
+ s->img_buffer_original_end = s->img_buffer_end;
}
#ifndef STBI_NO_STDIO
static int stbi__stdio_read(void *user, char *data, int size)
{
- return (int) fread(data,1,size,(FILE*) user);
+ return (int)fread(data, 1, size, user);
}
static void stbi__stdio_skip(void *user, int n)
{
- fseek((FILE*) user, n, SEEK_CUR);
+ fseek(user, n, SEEK_CUR);
}
static int stbi__stdio_eof(void *user)
{
- return feof((FILE*) user);
+ return feof(user);
}
static stbi_io_callbacks stbi__stdio_callbacks =
{
- stbi__stdio_read,
- stbi__stdio_skip,
- stbi__stdio_eof,
+ stbi__stdio_read,
+ stbi__stdio_skip,
+ stbi__stdio_eof,
};
static void stbi__start_file(stbi__context *s, FILE *f)
{
- stbi__start_callbacks(s, &stbi__stdio_callbacks, (void *) f);
+ stbi__start_callbacks(s, &stbi__stdio_callbacks, f);
}
//static void stop_file(stbi__context *s) { }
@@ -763,81 +786,97 @@ static void stbi__start_file(stbi__context *s, FILE *f)
static void stbi__rewind(stbi__context *s)
{
- // conceptually rewind SHOULD rewind to the beginning of the stream,
- // but we just rewind to the beginning of the initial buffer, because
- // we only use it after doing 'test', which only ever looks at at most 92 bytes
- s->img_buffer = s->img_buffer_original;
- s->img_buffer_end = s->img_buffer_original_end;
+ // conceptually rewind SHOULD rewind to the beginning of the stream,
+ // but we just rewind to the beginning of the initial buffer, because
+ // we only use it after doing 'test', which only ever looks at at most 92 bytes
+ s->img_buffer = s->img_buffer_original;
+ s->img_buffer_end = s->img_buffer_original_end;
}
enum
{
- STBI_ORDER_RGB,
- STBI_ORDER_BGR
+ STBI_ORDER_RGB, STBI_ORDER_BGR
};
typedef struct
{
- int bits_per_channel;
- int num_channels;
- int channel_order;
+ int bits_per_channel;
+ int num_channels;
+ int channel_order;
} stbi__result_info;
#ifndef STBI_NO_JPEG
-static int stbi__jpeg_test(stbi__context *s);
-static void *stbi__jpeg_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);
-static int stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp);
+static int stbi__jpeg_test(stbi__context *s);
+
+static void *stbi__jpeg_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);
+
+static int stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp);
#endif
#ifndef STBI_NO_PNG
-static int stbi__png_test(stbi__context *s);
-static void *stbi__png_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);
-static int stbi__png_info(stbi__context *s, int *x, int *y, int *comp);
-static int stbi__png_is16(stbi__context *s);
+static int stbi__png_test(stbi__context *s);
+
+static void *stbi__png_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);
+
+static int stbi__png_info(stbi__context *s, int *x, int *y, int *comp);
+
+static int stbi__png_is16(stbi__context *s);
#endif
#ifndef STBI_NO_BMP
-static int stbi__bmp_test(stbi__context *s);
-static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);
-static int stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp);
+static int stbi__bmp_test(stbi__context *s);
+
+static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);
+
+static int stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp);
#endif
#ifndef STBI_NO_TGA
-static int stbi__tga_test(stbi__context *s);
-static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);
-static int stbi__tga_info(stbi__context *s, int *x, int *y, int *comp);
+static int stbi__tga_test(stbi__context *s);
+static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);
+static int stbi__tga_info(stbi__context *s, int *x, int *y, int *comp);
#endif
#ifndef STBI_NO_PSD
-static int stbi__psd_test(stbi__context *s);
-static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc);
-static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp);
-static int stbi__psd_is16(stbi__context *s);
+static int stbi__psd_test(stbi__context *s);
+
+static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc);
+
+static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp);
+
+static int stbi__psd_is16(stbi__context *s);
#endif
#ifndef STBI_NO_HDR
-static int stbi__hdr_test(stbi__context *s);
-static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);
-static int stbi__hdr_info(stbi__context *s, int *x, int *y, int *comp);
+static int stbi__hdr_test(stbi__context *s);
+static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);
+static int stbi__hdr_info(stbi__context *s, int *x, int *y, int *comp);
#endif
#ifndef STBI_NO_PIC
-static int stbi__pic_test(stbi__context *s);
-static void *stbi__pic_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);
-static int stbi__pic_info(stbi__context *s, int *x, int *y, int *comp);
+static int stbi__pic_test(stbi__context *s);
+
+static void *stbi__pic_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);
+
+static int stbi__pic_info(stbi__context *s, int *x, int *y, int *comp);
#endif
#ifndef STBI_NO_GIF
-static int stbi__gif_test(stbi__context *s);
-static void *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);
-static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, int *z, int *comp, int req_comp);
-static int stbi__gif_info(stbi__context *s, int *x, int *y, int *comp);
+static int stbi__gif_test(stbi__context *s);
+
+static void *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);
+
+static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, int *z, int *comp, int req_comp);
+
+static int stbi__gif_info(stbi__context *s, int *x, int *y, int *comp);
#endif
#ifndef STBI_NO_PNM
-static int stbi__pnm_test(stbi__context *s);
-static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);
-static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp);
+static int stbi__pnm_test(stbi__context *s);
+
+static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);
+
+static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp);
#endif
// this is not threadsafe
@@ -845,13 +884,13 @@ static const char *stbi__g_failure_reason;
STBIDEF const char *stbi_failure_reason(void)
{
- return stbi__g_failure_reason;
+ return stbi__g_failure_reason;
}
static int stbi__err(const char *str)
{
- stbi__g_failure_reason = str;
- return 0;
+ stbi__g_failure_reason = str;
+ return 0;
}
static void *stbi__malloc(size_t size)
@@ -873,64 +912,64 @@ static void *stbi__malloc(size_t size)
// negative terms are considered invalid.
static int stbi__addsizes_valid(int a, int b)
{
- if (b < 0) return 0;
- // now 0 <= b <= INT_MAX, hence also
- // 0 <= INT_MAX - b <= INTMAX.
- // And "a + b <= INT_MAX" (which might overflow) is the
- // same as a <= INT_MAX - b (no overflow)
- return a <= INT_MAX - b;
+ if (b < 0) return 0;
+ // now 0 <= b <= INT_MAX, hence also
+ // 0 <= INT_MAX - b <= INTMAX.
+ // And "a + b <= INT_MAX" (which might overflow) is the
+ // same as a <= INT_MAX - b (no overflow)
+ return a <= INT_MAX - b;
}
// returns 1 if the product is valid, 0 on overflow.
// negative factors are considered invalid.
static int stbi__mul2sizes_valid(int a, int b)
{
- if (a < 0 || b < 0) return 0;
- if (b == 0) return 1; // mul-by-0 is always safe
- // portable way to check for no overflows in a*b
- return a <= INT_MAX/b;
+ if (a < 0 || b < 0) return 0;
+ if (b == 0) return 1; // mul-by-0 is always safe
+ // portable way to check for no overflows in a*b
+ return a <= INT_MAX / b;
}
// returns 1 if "a*b + add" has no negative terms/factors and doesn't overflow
static int stbi__mad2sizes_valid(int a, int b, int add)
{
- return stbi__mul2sizes_valid(a, b) && stbi__addsizes_valid(a*b, add);
+ return stbi__mul2sizes_valid(a, b) && stbi__addsizes_valid(a * b, add);
}
// returns 1 if "a*b*c + add" has no negative terms/factors and doesn't overflow
static int stbi__mad3sizes_valid(int a, int b, int c, int add)
{
- return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a*b, c) &&
- stbi__addsizes_valid(a*b*c, add);
+ return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a * b, c) &&
+ stbi__addsizes_valid(a * b * c, add);
}
// returns 1 if "a*b*c*d + add" has no negative terms/factors and doesn't overflow
#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR)
static int stbi__mad4sizes_valid(int a, int b, int c, int d, int add)
{
- return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a*b, c) &&
- stbi__mul2sizes_valid(a*b*c, d) && stbi__addsizes_valid(a*b*c*d, add);
+ return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a * b, c) &&
+ stbi__mul2sizes_valid(a * b * c, d) && stbi__addsizes_valid(a * b * c * d, add);
}
#endif
// mallocs with size overflow checking
static void *stbi__malloc_mad2(int a, int b, int add)
{
- if (!stbi__mad2sizes_valid(a, b, add)) return NULL;
- return stbi__malloc(a*b + add);
+ if (!stbi__mad2sizes_valid(a, b, add)) return NULL;
+ return stbi__malloc(a * b + add);
}
static void *stbi__malloc_mad3(int a, int b, int c, int add)
{
- if (!stbi__mad3sizes_valid(a, b, c, add)) return NULL;
- return stbi__malloc(a*b*c + add);
+ if (!stbi__mad3sizes_valid(a, b, c, add)) return NULL;
+ return stbi__malloc(a * b * c + add);
}
#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR)
static void *stbi__malloc_mad4(int a, int b, int c, int d, int add)
{
- if (!stbi__mad4sizes_valid(a, b, c, d, add)) return NULL;
- return stbi__malloc(a*b*c*d + add);
+ if (!stbi__mad4sizes_valid(a, b, c, d, add)) return NULL;
+ return stbi__malloc(a * b * c * d + add);
}
#endif
@@ -939,11 +978,11 @@ static void *stbi__malloc_mad4(int a, int b, int c, int d, int add)
// stbi__errpuc - error returning pointer to unsigned char
#ifdef STBI_NO_FAILURE_STRINGS
- #define stbi__err(x,y) 0
+#define stbi__err(x,y) 0
#elif defined(STBI_FAILURE_USERMSG)
- #define stbi__err(x,y) stbi__err(y)
+#define stbi__err(x,y) stbi__err(y)
#else
- #define stbi__err(x,y) stbi__err(x)
+#define stbi__err(x,y) stbi__err(x)
#endif
#define stbi__errpf(x,y) ((float *)(size_t) (stbi__err(x,y)?NULL:NULL))
@@ -951,15 +990,15 @@ static void *stbi__malloc_mad4(int a, int b, int c, int d, int add)
STBIDEF void stbi_image_free(void *retval_from_stbi_load)
{
- STBI_FREE(retval_from_stbi_load);
+ STBI_FREE(retval_from_stbi_load);
}
#ifndef STBI_NO_LINEAR
-static float *stbi__ldr_to_hdr(stbi_uc *data, int x, int y, int comp);
+static float *stbi__ldr_to_hdr(stbi_uc *data, int x, int y, int comp);
#endif
#ifndef STBI_NO_HDR
-static stbi_uc *stbi__hdr_to_ldr(float *data, int x, int y, int comp);
+static stbi_uc *stbi__hdr_to_ldr(float *data, int x, int y, int comp);
#endif
static int stbi__vertically_flip_on_load = 0;
@@ -971,173 +1010,185 @@ STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip)
static void *stbi__load_main(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc)
{
- memset(ri, 0, sizeof(*ri)); // make sure it's initialized if we add new fields
- ri->bits_per_channel = 8; // default is 8 so most paths don't have to be changed
- ri->channel_order = STBI_ORDER_RGB; // all current input & output are this, but this is here so we can add BGR order
- ri->num_channels = 0;
+ memset(ri, 0, sizeof(*ri)); // make sure it's initialized if we add new fields
+ ri->bits_per_channel = 8; // default is 8 so most paths don't have to be changed
+ ri->channel_order = STBI_ORDER_RGB; // all current input & output are this, but this is here so we can add BGR order
+ ri->num_channels = 0;
- #ifndef STBI_NO_JPEG
- if (stbi__jpeg_test(s)) return stbi__jpeg_load(s,x,y,comp,req_comp, ri);
- #endif
- #ifndef STBI_NO_PNG
- if (stbi__png_test(s)) return stbi__png_load(s,x,y,comp,req_comp, ri);
- #endif
- #ifndef STBI_NO_BMP
- if (stbi__bmp_test(s)) return stbi__bmp_load(s,x,y,comp,req_comp, ri);
- #endif
- #ifndef STBI_NO_GIF
- if (stbi__gif_test(s)) return stbi__gif_load(s,x,y,comp,req_comp, ri);
- #endif
- #ifndef STBI_NO_PSD
- if (stbi__psd_test(s)) return stbi__psd_load(s,x,y,comp,req_comp, ri, bpc);
- #endif
- #ifndef STBI_NO_PIC
- if (stbi__pic_test(s)) return stbi__pic_load(s,x,y,comp,req_comp, ri);
- #endif
- #ifndef STBI_NO_PNM
- if (stbi__pnm_test(s)) return stbi__pnm_load(s,x,y,comp,req_comp, ri);
- #endif
+ #ifndef STBI_NO_JPEG
+ if (stbi__jpeg_test(s)) return stbi__jpeg_load(s, x, y, comp, req_comp, ri);
+ #endif
+ #ifndef STBI_NO_PNG
+ if (stbi__png_test(s)) return stbi__png_load(s, x, y, comp, req_comp, ri);
+ #endif
+ #ifndef STBI_NO_BMP
+ if (stbi__bmp_test(s)) return stbi__bmp_load(s, x, y, comp, req_comp, ri);
+ #endif
+ #ifndef STBI_NO_GIF
+ if (stbi__gif_test(s)) return stbi__gif_load(s, x, y, comp, req_comp, ri);
+ #endif
+ #ifndef STBI_NO_PSD
+ if (stbi__psd_test(s)) return stbi__psd_load(s, x, y, comp, req_comp, ri, bpc);
+ #endif
+ #ifndef STBI_NO_PIC
+ if (stbi__pic_test(s)) return stbi__pic_load(s, x, y, comp, req_comp, ri);
+ #endif
+ #ifndef STBI_NO_PNM
+ if (stbi__pnm_test(s)) return stbi__pnm_load(s, x, y, comp, req_comp, ri);
+ #endif
- #ifndef STBI_NO_HDR
- if (stbi__hdr_test(s)) {
- float *hdr = stbi__hdr_load(s, x,y,comp,req_comp, ri);
- return stbi__hdr_to_ldr(hdr, *x, *y, req_comp ? req_comp : *comp);
- }
- #endif
+ #ifndef STBI_NO_HDR
+ if (stbi__hdr_test(s))
+ {
+ float *hdr = stbi__hdr_load(s, x, y, comp, req_comp, ri);
+ return stbi__hdr_to_ldr(hdr, *x, *y, req_comp ? req_comp : *comp);
+ }
+ #endif
- #ifndef STBI_NO_TGA
- // test tga last because it's a crappy test!
- if (stbi__tga_test(s))
- return stbi__tga_load(s,x,y,comp,req_comp, ri);
- #endif
+ #ifndef STBI_NO_TGA
+ // test tga last because it's a crappy test!
+ if (stbi__tga_test(s))
+ return stbi__tga_load(s, x, y, comp, req_comp, ri);
+ #endif
- return stbi__errpuc("unknown image type", "Image not of any known type, or corrupt");
+ return stbi__errpuc("unknown image type", "Image not of any known type, or corrupt");
}
static stbi_uc *stbi__convert_16_to_8(stbi__uint16 *orig, int w, int h, int channels)
{
- int i;
- int img_len = w * h * channels;
- stbi_uc *reduced;
+ int i;
+ int img_len = w * h * channels;
+ stbi_uc *reduced;
- reduced = (stbi_uc *) stbi__malloc(img_len);
- if (reduced == NULL) return stbi__errpuc("outofmem", "Out of memory");
+ reduced = (stbi_uc *)stbi__malloc(img_len);
+ if (reduced == NULL) return stbi__errpuc("outofmem", "Out of memory");
- for (i = 0; i < img_len; ++i)
- reduced[i] = (stbi_uc)((orig[i] >> 8) & 0xFF); // top half of each byte is sufficient approx of 16->8 bit scaling
+ for (i = 0; i < img_len; ++i)
+ reduced[i] = (stbi_uc)(orig[i] >> 8 & 0xFF); // top half of each byte is sufficient approx of 16->8 bit scaling
- STBI_FREE(orig);
- return reduced;
+ STBI_FREE(orig);
+ return reduced;
}
static stbi__uint16 *stbi__convert_8_to_16(stbi_uc *orig, int w, int h, int channels)
{
- int i;
- int img_len = w * h * channels;
- stbi__uint16 *enlarged;
+ int i;
+ int img_len = w * h * channels;
+ stbi__uint16 *enlarged;
- enlarged = (stbi__uint16 *) stbi__malloc(img_len*2);
- if (enlarged == NULL) return (stbi__uint16 *) stbi__errpuc("outofmem", "Out of memory");
+ enlarged = (stbi__uint16 *)stbi__malloc(img_len * 2);
+ if (enlarged == NULL) return (stbi__uint16 *)stbi__errpuc("outofmem", "Out of memory");
- for (i = 0; i < img_len; ++i)
- enlarged[i] = (stbi__uint16)((orig[i] << 8) + orig[i]); // replicate to high and low byte, maps 0->0, 255->0xffff
+ for (i = 0; i < img_len; ++i)
+ enlarged[i] = (stbi__uint16)((orig[i] << 8) + orig[i]); // replicate to high and low byte, maps 0->0, 255->0xffff
- STBI_FREE(orig);
- return enlarged;
+ STBI_FREE(orig);
+ return enlarged;
}
static void stbi__vertical_flip(void *image, int w, int h, int bytes_per_pixel)
{
- int row;
- size_t bytes_per_row = (size_t)w * bytes_per_pixel;
- stbi_uc temp[2048];
- stbi_uc *bytes = (stbi_uc *)image;
+ int row;
+ size_t bytes_per_row = (size_t)w * bytes_per_pixel;
+ stbi_uc temp[2048];
+ stbi_uc *bytes = image;
- for (row = 0; row < (h>>1); row++) {
- stbi_uc *row0 = bytes + row*bytes_per_row;
- stbi_uc *row1 = bytes + (h - row - 1)*bytes_per_row;
- // swap row0 with row1
- size_t bytes_left = bytes_per_row;
- while (bytes_left) {
- size_t bytes_copy = (bytes_left < sizeof(temp)) ? bytes_left : sizeof(temp);
- memcpy(temp, row0, bytes_copy);
- memcpy(row0, row1, bytes_copy);
- memcpy(row1, temp, bytes_copy);
- row0 += bytes_copy;
- row1 += bytes_copy;
- bytes_left -= bytes_copy;
- }
- }
+ for (row = 0; row < h >> 1; row++)
+ {
+ stbi_uc *row0 = bytes + row * bytes_per_row;
+ stbi_uc *row1 = bytes + (h - row - 1) * bytes_per_row;
+ // swap row0 with row1
+ size_t bytes_left = bytes_per_row;
+ while (bytes_left)
+ {
+ size_t bytes_copy = bytes_left < sizeof(temp) ? bytes_left : sizeof(temp);
+ memcpy(temp, row0, bytes_copy);
+ memcpy(row0, row1, bytes_copy);
+ memcpy(row1, temp, bytes_copy);
+ row0 += bytes_copy;
+ row1 += bytes_copy;
+ bytes_left -= bytes_copy;
+ }
+ }
}
static void stbi__vertical_flip_slices(void *image, int w, int h, int z, int bytes_per_pixel)
{
- int slice;
- int slice_size = w * h * bytes_per_pixel;
+ int slice;
+ int slice_size = w * h * bytes_per_pixel;
- stbi_uc *bytes = (stbi_uc *)image;
- for (slice = 0; slice < z; ++slice) {
- stbi__vertical_flip(bytes, w, h, bytes_per_pixel);
- bytes += slice_size;
- }
+ stbi_uc *bytes = image;
+ for (slice = 0; slice < z; ++slice)
+ {
+ stbi__vertical_flip(bytes, w, h, bytes_per_pixel);
+ bytes += slice_size;
+ }
}
static unsigned char *stbi__load_and_postprocess_8bit(stbi__context *s, int *x, int *y, int *comp, int req_comp)
{
- stbi__result_info ri;
- void *result = stbi__load_main(s, x, y, comp, req_comp, &ri, 8);
+ stbi__result_info ri;
+ void *result = stbi__load_main(s, x, y, comp, req_comp, &ri, 8);
- if (result == NULL)
- return NULL;
+ if (result == NULL)
+ return NULL;
- if (ri.bits_per_channel != 8) {
- STBI_ASSERT(ri.bits_per_channel == 16);
- result = stbi__convert_16_to_8((stbi__uint16 *) result, *x, *y, req_comp == 0 ? *comp : req_comp);
- ri.bits_per_channel = 8;
- }
+ if (ri.bits_per_channel != 8)
+ {
+ STBI_ASSERT(ri.bits_per_channel == 16);
+ result = stbi__convert_16_to_8(result, *x, *y, req_comp == 0 ? *comp : req_comp);
+ ri.bits_per_channel = 8;
+ }
- // @TODO: move stbi__convert_format to here
+ // @TODO: move stbi__convert_format to here
- if (stbi__vertically_flip_on_load) {
- int channels = req_comp ? req_comp : *comp;
- stbi__vertical_flip(result, *x, *y, channels * sizeof(stbi_uc));
- }
+ if (stbi__vertically_flip_on_load)
+ {
+ int channels = req_comp ? req_comp : *comp;
+ stbi__vertical_flip(result, *x, *y, channels * sizeof(stbi_uc));
+ }
- return (unsigned char *) result;
+ return result;
}
static stbi__uint16 *stbi__load_and_postprocess_16bit(stbi__context *s, int *x, int *y, int *comp, int req_comp)
{
- stbi__result_info ri;
- void *result = stbi__load_main(s, x, y, comp, req_comp, &ri, 16);
+ stbi__result_info ri;
+ void *result = stbi__load_main(s, x, y, comp, req_comp, &ri, 16);
- if (result == NULL)
- return NULL;
+ if (result == NULL)
+ return NULL;
- if (ri.bits_per_channel != 16) {
- STBI_ASSERT(ri.bits_per_channel == 8);
- result = stbi__convert_8_to_16((stbi_uc *) result, *x, *y, req_comp == 0 ? *comp : req_comp);
- ri.bits_per_channel = 16;
- }
+ if (ri.bits_per_channel != 16)
+ {
+ STBI_ASSERT(ri.bits_per_channel == 8);
+ result = stbi__convert_8_to_16(result, *x, *y, req_comp == 0 ? *comp : req_comp);
+ ri.bits_per_channel = 16;
+ }
- // @TODO: move stbi__convert_format16 to here
- // @TODO: special case RGB-to-Y (and RGBA-to-YA) for 8-bit-to-16-bit case to keep more precision
+ // @TODO: move stbi__convert_format16 to here
+ // @TODO: special case RGB-to-Y (and RGBA-to-YA) for 8-bit-to-16-bit case to keep more precision
- if (stbi__vertically_flip_on_load) {
- int channels = req_comp ? req_comp : *comp;
- stbi__vertical_flip(result, *x, *y, channels * sizeof(stbi__uint16));
- }
+ if (stbi__vertically_flip_on_load)
+ {
+ int channels = req_comp ? req_comp : *comp;
+ stbi__vertical_flip(result, *x, *y, channels * sizeof(stbi__uint16));
+ }
- return (stbi__uint16 *) result;
+ return result;
}
#if !defined(STBI_NO_HDR) || !defined(STBI_NO_LINEAR)
static void stbi__float_postprocess(float *result, int *x, int *y, int *comp, int req_comp)
{
- if (stbi__vertically_flip_on_load && result != NULL) {
- int channels = req_comp ? req_comp : *comp;
- stbi__vertical_flip(result, *x, *y, channels * sizeof(float));
- }
+ if (stbi__vertically_flip_on_load && result
+ !=
+ NULL
+ )
+ {
+ int channels = req_comp ? req_comp : *comp;
+ stbi__vertical_flip(result, *x, *y, channels * sizeof(float));
+ }
}
#endif
@@ -1145,61 +1196,63 @@ static void stbi__float_postprocess(float *result, int *x, int *y, int *comp, in
static FILE *stbi__fopen(char const *filename, char const *mode)
{
- FILE *f;
-#if defined(_MSC_VER) && _MSC_VER >= 1400
- if (0 != fopen_s(&f, filename, mode))
- f=0;
-#else
- f = fopen(filename, mode);
-#endif
- return f;
+ FILE *f;
+ #if defined(_MSC_VER) && _MSC_VER >= 1400
+ if (0 != fopen_s(&f, filename, mode))
+ f = 0;
+ #else
+ f = fopen(filename, mode);
+ #endif
+ return f;
}
STBIDEF stbi_uc *stbi_load(char const *filename, int *x, int *y, int *comp, int req_comp)
{
- FILE *f = stbi__fopen(filename, "rb");
- unsigned char *result;
- if (!f) return stbi__errpuc("can't fopen", "Unable to open file");
- result = stbi_load_from_file(f,x,y,comp,req_comp);
- fclose(f);
- return result;
+ FILE *f = stbi__fopen(filename, "rb");
+ unsigned char *result;
+ if (!f) return stbi__errpuc("can't fopen", "Unable to open file");
+ result = stbi_load_from_file(f, x, y, comp, req_comp);
+ fclose(f);
+ return result;
}
STBIDEF stbi_uc *stbi_load_from_file(FILE *f, int *x, int *y, int *comp, int req_comp)
{
- unsigned char *result;
- stbi__context s;
- stbi__start_file(&s,f);
- result = stbi__load_and_postprocess_8bit(&s,x,y,comp,req_comp);
- if (result) {
- // need to 'unget' all the characters in the IO buffer
- fseek(f, - (int) (s.img_buffer_end - s.img_buffer), SEEK_CUR);
- }
- return result;
+ unsigned char *result;
+ stbi__context s;
+ stbi__start_file(&s, f);
+ result = stbi__load_and_postprocess_8bit(&s, x, y, comp, req_comp);
+ if (result)
+ {
+ // need to 'unget' all the characters in the IO buffer
+ fseek(f, -(int)(s.img_buffer_end - s.img_buffer), SEEK_CUR);
+ }
+ return result;
}
STBIDEF stbi__uint16 *stbi_load_from_file_16(FILE *f, int *x, int *y, int *comp, int req_comp)
{
- stbi__uint16 *result;
- stbi__context s;
- stbi__start_file(&s,f);
- result = stbi__load_and_postprocess_16bit(&s,x,y,comp,req_comp);
- if (result) {
- // need to 'unget' all the characters in the IO buffer
- fseek(f, - (int) (s.img_buffer_end - s.img_buffer), SEEK_CUR);
- }
- return result;
+ stbi__uint16 *result;
+ stbi__context s;
+ stbi__start_file(&s, f);
+ result = stbi__load_and_postprocess_16bit(&s, x, y, comp, req_comp);
+ if (result)
+ {
+ // need to 'unget' all the characters in the IO buffer
+ fseek(f, -(int)(s.img_buffer_end - s.img_buffer), SEEK_CUR);
+ }
+ return result;
}
STBIDEF stbi_us *stbi_load_16(char const *filename, int *x, int *y, int *comp, int req_comp)
{
- FILE *f = stbi__fopen(filename, "rb");
- stbi__uint16 *result;
- if (!f) return (stbi_us *) stbi__errpuc("can't fopen", "Unable to open file");
- result = stbi_load_from_file_16(f,x,y,comp,req_comp);
- fclose(f);
- return result;
+ FILE *f = stbi__fopen(filename, "rb");
+ stbi__uint16 *result;
+ if (!f) return (stbi_us *)stbi__errpuc("can't fopen", "Unable to open file");
+ result = stbi_load_from_file_16(f, x, y, comp, req_comp);
+ fclose(f);
+ return result;
}
@@ -1207,97 +1260,99 @@ STBIDEF stbi_us *stbi_load_16(char const *filename, int *x, int *y, int *comp, i
STBIDEF stbi_us *stbi_load_16_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *channels_in_file, int desired_channels)
{
- stbi__context s;
- stbi__start_mem(&s,buffer,len);
- return stbi__load_and_postprocess_16bit(&s,x,y,channels_in_file,desired_channels);
+ stbi__context s;
+ stbi__start_mem(&s, buffer, len);
+ return stbi__load_and_postprocess_16bit(&s, x, y, channels_in_file, desired_channels);
}
STBIDEF stbi_us *stbi_load_16_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *channels_in_file, int desired_channels)
{
- stbi__context s;
- stbi__start_callbacks(&s, (stbi_io_callbacks *)clbk, user);
- return stbi__load_and_postprocess_16bit(&s,x,y,channels_in_file,desired_channels);
+ stbi__context s;
+ stbi__start_callbacks(&s, (stbi_io_callbacks *)clbk, user);
+ return stbi__load_and_postprocess_16bit(&s, x, y, channels_in_file, desired_channels);
}
STBIDEF stbi_uc *stbi_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp)
{
- stbi__context s;
- stbi__start_mem(&s,buffer,len);
- return stbi__load_and_postprocess_8bit(&s,x,y,comp,req_comp);
+ stbi__context s;
+ stbi__start_mem(&s, buffer, len);
+ return stbi__load_and_postprocess_8bit(&s, x, y, comp, req_comp);
}
STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp)
{
- stbi__context s;
- stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user);
- return stbi__load_and_postprocess_8bit(&s,x,y,comp,req_comp);
+ stbi__context s;
+ stbi__start_callbacks(&s, (stbi_io_callbacks *)clbk, user);
+ return stbi__load_and_postprocess_8bit(&s, x, y, comp, req_comp);
}
#ifndef STBI_NO_GIF
STBIDEF stbi_uc *stbi_load_gif_from_memory(stbi_uc const *buffer, int len, int **delays, int *x, int *y, int *z, int *comp, int req_comp)
{
- unsigned char *result;
- stbi__context s;
- stbi__start_mem(&s,buffer,len);
-
- result = (unsigned char*) stbi__load_gif_main(&s, delays, x, y, z, comp, req_comp);
- if (stbi__vertically_flip_on_load) {
- stbi__vertical_flip_slices( result, *x, *y, *z, *comp );
- }
+ unsigned char *result;
+ stbi__context s;
+ stbi__start_mem(&s, buffer, len);
- return result;
+ result = (unsigned char *)stbi__load_gif_main(&s, delays, x, y, z, comp, req_comp);
+ if (stbi__vertically_flip_on_load)
+ {
+ stbi__vertical_flip_slices(result, *x, *y, *z, *comp);
+ }
+
+ return result;
}
#endif
#ifndef STBI_NO_LINEAR
static float *stbi__loadf_main(stbi__context *s, int *x, int *y, int *comp, int req_comp)
{
- unsigned char *data;
- #ifndef STBI_NO_HDR
- if (stbi__hdr_test(s)) {
- stbi__result_info ri;
- float *hdr_data = stbi__hdr_load(s,x,y,comp,req_comp, &ri);
- if (hdr_data)
- stbi__float_postprocess(hdr_data,x,y,comp,req_comp);
- return hdr_data;
- }
- #endif
- data = stbi__load_and_postprocess_8bit(s, x, y, comp, req_comp);
+ unsigned char *data;
+#ifndef STBI_NO_HDR
+if (stbi__hdr_test(s))
+{
+ stbi__result_info ri;
+ float *hdr_data = stbi__hdr_load(s, x, y, comp, req_comp, &ri);
+ if (hdr_data)
+ stbi__float_postprocess(hdr_data, x, y, comp, req_comp);
+ return hdr_data;
+}
+#endif
+data = stbi__load_and_postprocess_8bit(s, x, y, comp, req_comp);
if (data)
- return stbi__ldr_to_hdr(data, *x, *y, req_comp ? req_comp : *comp);
+ return stbi__ldr_to_hdr(data, *x, *y, req_comp? req_comp: *comp);
return stbi__errpf("unknown image type", "Image not of any known type, or corrupt");
}
STBIDEF float *stbi_loadf_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp)
{
- stbi__context s;
- stbi__start_mem(&s,buffer,len);
- return stbi__loadf_main(&s,x,y,comp,req_comp);
+ stbi__context s;
+ stbi__start_mem(&s, buffer, len);
+ return stbi__loadf_main(&s, x, y, comp, req_comp);
}
STBIDEF float *stbi_loadf_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp)
{
- stbi__context s;
- stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user);
- return stbi__loadf_main(&s,x,y,comp,req_comp);
+ stbi__context s;
+ stbi__start_callbacks(&s, (stbi_io_callbacks *)clbk, user);
+ return stbi__loadf_main(&s, x, y, comp, req_comp);
}
#ifndef STBI_NO_STDIO
STBIDEF float *stbi_loadf(char const *filename, int *x, int *y, int *comp, int req_comp)
{
- float *result;
- FILE *f = stbi__fopen(filename, "rb");
- if (!f) return stbi__errpf("can't fopen", "Unable to open file");
- result = stbi_loadf_from_file(f,x,y,comp,req_comp);
- fclose(f);
- return result;
+ float *result;
+ FILE *f = stbi__fopen(filename, "rb");
+ if (!f) return stbi__errpf("can't fopen", "Unable to open file");
+ result = stbi_loadf_from_file(f, x, y, comp, req_comp);
+ fclose(f);
+ return result;
}
STBIDEF float *stbi_loadf_from_file(FILE *f, int *x, int *y, int *comp, int req_comp)
{
- stbi__context s;
- stbi__start_file(&s,f);
- return stbi__loadf_main(&s,x,y,comp,req_comp);
+ stbi__context s;
+ stbi__start_file(&s, f);
+ return stbi__loadf_main(&s, x, y, comp, req_comp);
}
#endif // !STBI_NO_STDIO
@@ -1309,70 +1364,71 @@ STBIDEF float *stbi_loadf_from_file(FILE *f, int *x, int *y, int *comp, int req_
STBIDEF int stbi_is_hdr_from_memory(stbi_uc const *buffer, int len)
{
- #ifndef STBI_NO_HDR
- stbi__context s;
- stbi__start_mem(&s,buffer,len);
- return stbi__hdr_test(&s);
- #else
- STBI_NOTUSED(buffer);
- STBI_NOTUSED(len);
- return 0;
- #endif
+ #ifndef STBI_NO_HDR
+ stbi__context s;
+ stbi__start_mem(&s, buffer, len);
+ return stbi__hdr_test(&s);
+ #else
+ STBI_NOTUSED(buffer);
+ STBI_NOTUSED(len);
+ return 0;
+ #endif
}
#ifndef STBI_NO_STDIO
-STBIDEF int stbi_is_hdr (char const *filename)
+STBIDEF int stbi_is_hdr(char const *filename)
{
- FILE *f = stbi__fopen(filename, "rb");
- int result=0;
- if (f) {
- result = stbi_is_hdr_from_file(f);
- fclose(f);
- }
- return result;
+ FILE *f = stbi__fopen(filename, "rb");
+ int result = 0;
+ if (f)
+ {
+ result = stbi_is_hdr_from_file(f);
+ fclose(f);
+ }
+ return result;
}
STBIDEF int stbi_is_hdr_from_file(FILE *f)
{
- #ifndef STBI_NO_HDR
- long pos = ftell(f);
- int res;
- stbi__context s;
- stbi__start_file(&s,f);
- res = stbi__hdr_test(&s);
- fseek(f, pos, SEEK_SET);
- return res;
- #else
- STBI_NOTUSED(f);
- return 0;
- #endif
+ #ifndef STBI_NO_HDR
+ long pos = ftell(f);
+ int res;
+ stbi__context s;
+ stbi__start_file(&s, f);
+ res = stbi__hdr_test(&s);
+ fseek(f, pos, SEEK_SET);
+ return res;
+ #else
+ STBI_NOTUSED(f);
+ return 0;
+ #endif
}
#endif // !STBI_NO_STDIO
-STBIDEF int stbi_is_hdr_from_callbacks(stbi_io_callbacks const *clbk, void *user)
+STBIDEF int stbi_is_hdr_from_callbacks(stbi_io_callbacks const *clbk, void *user)
{
- #ifndef STBI_NO_HDR
- stbi__context s;
- stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user);
- return stbi__hdr_test(&s);
- #else
- STBI_NOTUSED(clbk);
- STBI_NOTUSED(user);
- return 0;
- #endif
+ #ifndef STBI_NO_HDR
+ stbi__context s;
+ stbi__start_callbacks(&s, (stbi_io_callbacks *)clbk, user);
+ return stbi__hdr_test(&s);
+ #else
+ STBI_NOTUSED(clbk);
+ STBI_NOTUSED(user);
+ return 0;
+ #endif
}
#ifndef STBI_NO_LINEAR
-static float stbi__l2h_gamma=2.2f, stbi__l2h_scale=1.0f;
+static float stbi__l2h_gamma = 2.2f, stbi__l2h_scale = 1.0f;
-STBIDEF void stbi_ldr_to_hdr_gamma(float gamma) { stbi__l2h_gamma = gamma; }
-STBIDEF void stbi_ldr_to_hdr_scale(float scale) { stbi__l2h_scale = scale; }
+STBIDEF void stbi_ldr_to_hdr_gamma(float gamma) { stbi__l2h_gamma = gamma; }
+STBIDEF void stbi_ldr_to_hdr_scale(float scale) { stbi__l2h_scale = scale; }
#endif
-static float stbi__h2l_gamma_i=1.0f/2.2f, stbi__h2l_scale_i=1.0f;
+static float stbi__h2l_gamma_i = 1.0f / 2.2f, stbi__h2l_scale_i = 1.0f;
-STBIDEF void stbi_hdr_to_ldr_gamma(float gamma) { stbi__h2l_gamma_i = 1/gamma; }
-STBIDEF void stbi_hdr_to_ldr_scale(float scale) { stbi__h2l_scale_i = 1/scale; }
+STBIDEF void stbi_hdr_to_ldr_gamma(float gamma) { stbi__h2l_gamma_i = 1 / gamma; }
+STBIDEF void stbi_hdr_to_ldr_scale(float scale) { stbi__h2l_scale_i = 1 / scale; }
//////////////////////////////////////////////////////////////////////////////
@@ -1382,101 +1438,111 @@ STBIDEF void stbi_hdr_to_ldr_scale(float scale) { stbi__h2l_scale_i = 1/scale;
enum
{
- STBI__SCAN_load=0,
- STBI__SCAN_type,
- STBI__SCAN_header
+ STBI__SCAN_load = 0, STBI__SCAN_type, STBI__SCAN_header
};
static void stbi__refill_buffer(stbi__context *s)
{
- int n = (s->io.read)(s->io_user_data,(char*)s->buffer_start,s->buflen);
- if (n == 0) {
- // at end of file, treat same as if from memory, but need to handle case
- // where s->img_buffer isn't pointing to safe memory, e.g. 0-byte file
- s->read_from_callbacks = 0;
- s->img_buffer = s->buffer_start;
- s->img_buffer_end = s->buffer_start+1;
- *s->img_buffer = 0;
- } else {
- s->img_buffer = s->buffer_start;
- s->img_buffer_end = s->buffer_start + n;
- }
+ int n = s->io.read(s->io_user_data, (char *)s->buffer_start, s->buflen);
+ if (n == 0)
+ {
+ // at end of file, treat same as if from memory, but need to handle case
+ // where s->img_buffer isn't pointing to safe memory, e.g. 0-byte file
+ s->read_from_callbacks = 0;
+ s->img_buffer = s->buffer_start;
+ s->img_buffer_end = s->buffer_start + 1;
+ *s->img_buffer = 0;
+ }
+ else
+ {
+ s->img_buffer = s->buffer_start;
+ s->img_buffer_end = s->buffer_start + n;
+ }
}
stbi_inline static stbi_uc stbi__get8(stbi__context *s)
{
- if (s->img_buffer < s->img_buffer_end)
- return *s->img_buffer++;
- if (s->read_from_callbacks) {
- stbi__refill_buffer(s);
- return *s->img_buffer++;
- }
- return 0;
+ if (s->img_buffer < s->img_buffer_end)
+ return *s->img_buffer++;
+ if (s->read_from_callbacks)
+ {
+ stbi__refill_buffer(s);
+ return *s->img_buffer++;
+ }
+ return 0;
}
stbi_inline static int stbi__at_eof(stbi__context *s)
{
- if (s->io.read) {
- if (!(s->io.eof)(s->io_user_data)) return 0;
- // if feof() is true, check if buffer = end
- // special case: we've only got the special 0 character at the end
- if (s->read_from_callbacks == 0) return 1;
- }
+ if (s->io.read)
+ {
+ if (!s->io.eof(s->io_user_data)) return 0;
+ // if feof() is true, check if buffer = end
+ // special case: we've only got the special 0 character at the end
+ if (s->read_from_callbacks == 0) return 1;
+ }
- return s->img_buffer >= s->img_buffer_end;
+ return s->img_buffer >= s->img_buffer_end;
}
static void stbi__skip(stbi__context *s, int n)
{
- if (n < 0) {
- s->img_buffer = s->img_buffer_end;
- return;
- }
- if (s->io.read) {
- int blen = (int) (s->img_buffer_end - s->img_buffer);
- if (blen < n) {
- s->img_buffer = s->img_buffer_end;
- (s->io.skip)(s->io_user_data, n - blen);
- return;
- }
- }
- s->img_buffer += n;
+ if (n < 0)
+ {
+ s->img_buffer = s->img_buffer_end;
+ return;
+ }
+ if (s->io.read)
+ {
+ int blen = (int)(s->img_buffer_end - s->img_buffer);
+ if (blen < n)
+ {
+ s->img_buffer = s->img_buffer_end;
+ s->io.skip(s->io_user_data, n - blen);
+ return;
+ }
+ }
+ s->img_buffer += n;
}
static int stbi__getn(stbi__context *s, stbi_uc *buffer, int n)
{
- if (s->io.read) {
- int blen = (int) (s->img_buffer_end - s->img_buffer);
- if (blen < n) {
- int res, count;
+ if (s->io.read)
+ {
+ int blen = (int)(s->img_buffer_end - s->img_buffer);
+ if (blen < n)
+ {
+ int res, count;
- memcpy(buffer, s->img_buffer, blen);
+ memcpy(buffer, s->img_buffer, blen);
- count = (s->io.read)(s->io_user_data, (char*) buffer + blen, n - blen);
- res = (count == (n-blen));
- s->img_buffer = s->img_buffer_end;
- return res;
- }
- }
+ count = s->io.read(s->io_user_data, (char *)buffer + blen, n - blen);
+ res = count == n - blen;
+ s->img_buffer = s->img_buffer_end;
+ return res;
+ }
+ }
- if (s->img_buffer+n <= s->img_buffer_end) {
- memcpy(buffer, s->img_buffer, n);
- s->img_buffer += n;
- return 1;
- } else
- return 0;
+ if (s->img_buffer + n <= s->img_buffer_end)
+ {
+ memcpy(buffer, s->img_buffer, n);
+ s->img_buffer += n;
+ return 1;
+ }
+ else
+ return 0;
}
static int stbi__get16be(stbi__context *s)
{
- int z = stbi__get8(s);
- return (z << 8) + stbi__get8(s);
+ int z = stbi__get8(s);
+ return (z << 8) + stbi__get8(s);
}
static stbi__uint32 stbi__get32be(stbi__context *s)
{
- stbi__uint32 z = stbi__get16be(s);
- return (z << 16) + stbi__get16be(s);
+ stbi__uint32 z = stbi__get16be(s);
+ return (z << 16) + stbi__get16be(s);
}
#if defined(STBI_NO_BMP) && defined(STBI_NO_TGA) && defined(STBI_NO_GIF)
@@ -1484,16 +1550,16 @@ static stbi__uint32 stbi__get32be(stbi__context *s)
#else
static int stbi__get16le(stbi__context *s)
{
- int z = stbi__get8(s);
- return z + (stbi__get8(s) << 8);
+ int z = stbi__get8(s);
+ return z + (stbi__get8(s) << 8);
}
#endif
#ifndef STBI_NO_BMP
static stbi__uint32 stbi__get32le(stbi__context *s)
{
- stbi__uint32 z = stbi__get16le(s);
- return z + (stbi__get16le(s) << 16);
+ stbi__uint32 z = stbi__get16le(s);
+ return z + (stbi__get16le(s) << 16);
}
#endif
@@ -1513,150 +1579,269 @@ static stbi__uint32 stbi__get32le(stbi__context *s)
static stbi_uc stbi__compute_y(int r, int g, int b)
{
- return (stbi_uc) (((r*77) + (g*150) + (29*b)) >> 8);
+ return (stbi_uc)((r * 77 + g * 150 + 29 * b) >> 8);
}
static unsigned char *stbi__convert_format(unsigned char *data, int img_n, int req_comp, unsigned int x, unsigned int y)
{
- int i,j;
- unsigned char *good;
+ int i, j;
+ unsigned char *good;
- if (req_comp == img_n) return data;
- STBI_ASSERT(req_comp >= 1 && req_comp <= 4);
+ if (req_comp == img_n) return data;
+ STBI_ASSERT(req_comp >= 1 && req_comp <= 4);
- good = (unsigned char *) stbi__malloc_mad3(req_comp, x, y, 0);
- if (good == NULL) {
- STBI_FREE(data);
- return stbi__errpuc("outofmem", "Out of memory");
- }
+ good = (unsigned char *)stbi__malloc_mad3(req_comp, x, y, 0);
+ if (good == NULL)
+ {
+ STBI_FREE(data);
+ return stbi__errpuc("outofmem", "Out of memory");
+ }
- for (j=0; j < (int) y; ++j) {
- unsigned char *src = data + j * x * img_n ;
- unsigned char *dest = good + j * x * req_comp;
+ for (j = 0; j < (int)y; ++j)
+ {
+ unsigned char *src = data + j * x * img_n;
+ unsigned char *dest = good + j * x * req_comp;
- #define STBI__COMBO(a,b) ((a)*8+(b))
- #define STBI__CASE(a,b) case STBI__COMBO(a,b): for(i=x-1; i >= 0; --i, src += a, dest += b)
- // convert source image with img_n components to one with req_comp components;
- // avoid switch per pixel, so use switch per scanline and massive macros
- switch (STBI__COMBO(img_n, req_comp)) {
- STBI__CASE(1,2) { dest[0]=src[0], dest[1]=255; } break;
- STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
- STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=255; } break;
- STBI__CASE(2,1) { dest[0]=src[0]; } break;
- STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
- STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=src[1]; } break;
- STBI__CASE(3,4) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2],dest[3]=255; } break;
- STBI__CASE(3,1) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); } break;
- STBI__CASE(3,2) { dest[0]=stbi__compute_y(src[0],src[1],src[2]), dest[1] = 255; } break;
- STBI__CASE(4,1) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); } break;
- STBI__CASE(4,2) { dest[0]=stbi__compute_y(src[0],src[1],src[2]), dest[1] = src[3]; } break;
- STBI__CASE(4,3) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2]; } break;
- default: STBI_ASSERT(0);
- }
- #undef STBI__CASE
- }
+ #define STBI__COMBO(a,b) ((a)*8+(b))
+ #define STBI__CASE(a,b) case STBI__COMBO(a,b): for(i=x-1; i >= 0; --i, src += a, dest += b)
+ // convert source image with img_n components to one with req_comp components;
+ // avoid switch per pixel, so use switch per scanline and massive macros
+ switch (STBI__COMBO(img_n, req_comp))
+ {
+ STBI__CASE(1, 2)
+ {
+ dest[0] = src[0], dest[1] = 255;
+ }
+ break;
+ STBI__CASE(1, 3)
+ {
+ dest[0] = dest[1] = dest[2] = src[0];
+ }
+ break;
+ STBI__CASE(1, 4)
+ {
+ dest[0] = dest[1] = dest[2] = src[0], dest[3] = 255;
+ }
+ break;
+ STBI__CASE(2, 1)
+ {
+ dest[0] = src[0];
+ }
+ break;
+ STBI__CASE(2, 3)
+ {
+ dest[0] = dest[1] = dest[2] = src[0];
+ }
+ break;
+ STBI__CASE(2, 4)
+ {
+ dest[0] = dest[1] = dest[2] = src[0], dest[3] = src[1];
+ }
+ break;
+ STBI__CASE(3, 4)
+ {
+ dest[0] = src[0], dest[1] = src[1], dest[2] = src[2], dest[3] = 255;
+ }
+ break;
+ STBI__CASE(3, 1)
+ {
+ dest[0] = stbi__compute_y(src[0], src[1], src[2]);
+ }
+ break;
+ STBI__CASE(3, 2)
+ {
+ dest[0] = stbi__compute_y(src[0], src[1], src[2]), dest[1] = 255;
+ }
+ break;
+ STBI__CASE(4, 1)
+ {
+ dest[0] = stbi__compute_y(src[0], src[1], src[2]);
+ }
+ break;
+ STBI__CASE(4, 2)
+ {
+ dest[0] = stbi__compute_y(src[0], src[1], src[2]), dest[1] = src[3];
+ }
+ break;
+ STBI__CASE(4, 3)
+ {
+ dest[0] = src[0], dest[1] = src[1], dest[2] = src[2];
+ }
+ break;
+ default:
+ STBI_ASSERT(0);
+ }
+ #undef STBI__CASE
+ }
- STBI_FREE(data);
- return good;
+ STBI_FREE(data);
+ return good;
}
static stbi__uint16 stbi__compute_y_16(int r, int g, int b)
{
- return (stbi__uint16) (((r*77) + (g*150) + (29*b)) >> 8);
+ return (stbi__uint16)((r * 77 + g * 150 + 29 * b) >> 8);
}
static stbi__uint16 *stbi__convert_format16(stbi__uint16 *data, int img_n, int req_comp, unsigned int x, unsigned int y)
{
- int i,j;
- stbi__uint16 *good;
+ int i, j;
+ stbi__uint16 *good;
- if (req_comp == img_n) return data;
- STBI_ASSERT(req_comp >= 1 && req_comp <= 4);
+ if (req_comp == img_n) return data;
+ STBI_ASSERT(req_comp >= 1 && req_comp <= 4);
- good = (stbi__uint16 *) stbi__malloc(req_comp * x * y * 2);
- if (good == NULL) {
- STBI_FREE(data);
- return (stbi__uint16 *) stbi__errpuc("outofmem", "Out of memory");
- }
+ good = (stbi__uint16 *)stbi__malloc(req_comp * x * y * 2);
+ if (good == NULL)
+ {
+ STBI_FREE(data);
+ return (stbi__uint16 *)stbi__errpuc("outofmem", "Out of memory");
+ }
- for (j=0; j < (int) y; ++j) {
- stbi__uint16 *src = data + j * x * img_n ;
- stbi__uint16 *dest = good + j * x * req_comp;
+ for (j = 0; j < (int)y; ++j)
+ {
+ stbi__uint16 *src = data + j * x * img_n;
+ stbi__uint16 *dest = good + j * x * req_comp;
- #define STBI__COMBO(a,b) ((a)*8+(b))
- #define STBI__CASE(a,b) case STBI__COMBO(a,b): for(i=x-1; i >= 0; --i, src += a, dest += b)
- // convert source image with img_n components to one with req_comp components;
- // avoid switch per pixel, so use switch per scanline and massive macros
- switch (STBI__COMBO(img_n, req_comp)) {
- STBI__CASE(1,2) { dest[0]=src[0], dest[1]=0xffff; } break;
- STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
- STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=0xffff; } break;
- STBI__CASE(2,1) { dest[0]=src[0]; } break;
- STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
- STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=src[1]; } break;
- STBI__CASE(3,4) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2],dest[3]=0xffff; } break;
- STBI__CASE(3,1) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); } break;
- STBI__CASE(3,2) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]), dest[1] = 0xffff; } break;
- STBI__CASE(4,1) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); } break;
- STBI__CASE(4,2) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]), dest[1] = src[3]; } break;
- STBI__CASE(4,3) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2]; } break;
- default: STBI_ASSERT(0);
- }
- #undef STBI__CASE
- }
+ #define STBI__COMBO(a,b) ((a)*8+(b))
+ #define STBI__CASE(a,b) case STBI__COMBO(a,b): for(i=x-1; i >= 0; --i, src += a, dest += b)
+ // convert source image with img_n components to one with req_comp components;
+ // avoid switch per pixel, so use switch per scanline and massive macros
+ switch (STBI__COMBO(img_n, req_comp))
+ {
+ STBI__CASE(1, 2)
+ {
+ dest[0] = src[0], dest[1] = 0xffff;
+ }
+ break;
+ STBI__CASE(1, 3)
+ {
+ dest[0] = dest[1] = dest[2] = src[0];
+ }
+ break;
+ STBI__CASE(1, 4)
+ {
+ dest[0] = dest[1] = dest[2] = src[0], dest[3] = 0xffff;
+ }
+ break;
+ STBI__CASE(2, 1)
+ {
+ dest[0] = src[0];
+ }
+ break;
+ STBI__CASE(2, 3)
+ {
+ dest[0] = dest[1] = dest[2] = src[0];
+ }
+ break;
+ STBI__CASE(2, 4)
+ {
+ dest[0] = dest[1] = dest[2] = src[0], dest[3] = src[1];
+ }
+ break;
+ STBI__CASE(3, 4)
+ {
+ dest[0] = src[0], dest[1] = src[1], dest[2] = src[2], dest[3] = 0xffff;
+ }
+ break;
+ STBI__CASE(3, 1)
+ {
+ dest[0] = stbi__compute_y_16(src[0], src[1], src[2]);
+ }
+ break;
+ STBI__CASE(3, 2)
+ {
+ dest[0] = stbi__compute_y_16(src[0], src[1], src[2]), dest[1] = 0xffff;
+ }
+ break;
+ STBI__CASE(4, 1)
+ {
+ dest[0] = stbi__compute_y_16(src[0], src[1], src[2]);
+ }
+ break;
+ STBI__CASE(4, 2)
+ {
+ dest[0] = stbi__compute_y_16(src[0], src[1], src[2]), dest[1] = src[3];
+ }
+ break;
+ STBI__CASE(4, 3)
+ {
+ dest[0] = src[0], dest[1] = src[1], dest[2] = src[2];
+ }
+ break;
+ default:
+ STBI_ASSERT(0);
+ }
+ #undef STBI__CASE
+ }
- STBI_FREE(data);
- return good;
+ STBI_FREE(data);
+ return good;
}
#ifndef STBI_NO_LINEAR
-static float *stbi__ldr_to_hdr(stbi_uc *data, int x, int y, int comp)
+static float *stbi__ldr_to_hdr(stbi_uc *data, int x, int y, int comp)
{
- int i,k,n;
- float *output;
- if (!data) return NULL;
- output = (float *) stbi__malloc_mad4(x, y, comp, sizeof(float), 0);
- if (output == NULL) { STBI_FREE(data); return stbi__errpf("outofmem", "Out of memory"); }
- // compute number of non-alpha components
- if (comp & 1) n = comp; else n = comp-1;
- for (i=0; i < x*y; ++i) {
- for (k=0; k < n; ++k) {
- output[i*comp + k] = (float) (pow(data[i*comp+k]/255.0f, stbi__l2h_gamma) * stbi__l2h_scale);
- }
- if (k < comp) output[i*comp + k] = data[i*comp+k]/255.0f;
- }
- STBI_FREE(data);
- return output;
+ int i, k, n;
+ float *output;
+ if (!data) return NULL;
+ output = (float *)stbi__malloc_mad4(x, y, comp, sizeof(float), 0);
+ if (output == NULL)
+ {
+ STBI_FREE(data);
+ return stbi__errpf("outofmem", "Out of memory");
+ }
+ // compute number of non-alpha components
+ if (comp & 1) n = comp;
+ else n = comp - 1;
+ for (i = 0; i < x * y; ++i)
+ {
+ for (k = 0; k < n; ++k)
+ {
+ output[i * comp + k] = (float)(pow(data[i * comp + k] / 255.0f, stbi__l2h_gamma) * stbi__l2h_scale);
+ }
+ if (k < comp) output[i * comp + k] = data[i * comp + k] / 255.0f;
+ }
+ STBI_FREE(data);
+ return output;
}
#endif
#ifndef STBI_NO_HDR
#define stbi__float2int(x) ((int) (x))
-static stbi_uc *stbi__hdr_to_ldr(float *data, int x, int y, int comp)
+static stbi_uc *stbi__hdr_to_ldr(float *data, int x, int y, int comp)
{
- int i,k,n;
- stbi_uc *output;
- if (!data) return NULL;
- output = (stbi_uc *) stbi__malloc_mad3(x, y, comp, 0);
- if (output == NULL) { STBI_FREE(data); return stbi__errpuc("outofmem", "Out of memory"); }
- // compute number of non-alpha components
- if (comp & 1) n = comp; else n = comp-1;
- for (i=0; i < x*y; ++i) {
- for (k=0; k < n; ++k) {
- float z = (float) pow(data[i*comp+k]*stbi__h2l_scale_i, stbi__h2l_gamma_i) * 255 + 0.5f;
- if (z < 0) z = 0;
- if (z > 255) z = 255;
- output[i*comp + k] = (stbi_uc) stbi__float2int(z);
- }
- if (k < comp) {
- float z = data[i*comp+k] * 255 + 0.5f;
- if (z < 0) z = 0;
- if (z > 255) z = 255;
- output[i*comp + k] = (stbi_uc) stbi__float2int(z);
- }
- }
- STBI_FREE(data);
- return output;
+ int i, k, n;
+ stbi_uc *output;
+ if (!data) return NULL;
+ output = (stbi_uc *)stbi__malloc_mad3(x, y, comp, 0);
+ if (output == NULL)
+ {
+ STBI_FREE(data);
+ return stbi__errpuc("outofmem", "Out of memory");
+ }
+ // compute number of non-alpha components
+ if (comp & 1) n = comp;
+ else n = comp - 1;
+ for (i = 0; i < x * y; ++i)
+ {
+ for (k = 0; k < n; ++k)
+ {
+ float z = (float)pow(data[i * comp + k] * stbi__h2l_scale_i, stbi__h2l_gamma_i) * 255 + 0.5f;
+ if (z < 0) z = 0;
+ if (z > 255) z = 255;
+ output[i * comp + k] = (stbi_uc)stbi__float2int(z);
+ }
+ if (k < comp)
+ {
+ float z = data[i * comp + k] * 255 + 0.5f;
+ if (z < 0) z = 0;
+ if (z > 255) z = 255;
+ output[i * comp + k] = (stbi_uc)stbi__float2int(z);
+ }
+ }
+ STBI_FREE(data);
+ return output;
}
#endif
@@ -1688,476 +1873,536 @@ static stbi_uc *stbi__hdr_to_ldr(float *data, int x, int y, int comp)
typedef struct
{
- stbi_uc fast[1 << FAST_BITS];
- // weirdly, repacking this into AoS is a 10% speed loss, instead of a win
- stbi__uint16 code[256];
- stbi_uc values[256];
- stbi_uc size[257];
- unsigned int maxcode[18];
- int delta[17]; // old 'firstsymbol' - old 'firstcode'
+ stbi_uc fast[1 << FAST_BITS];
+ // weirdly, repacking this into AoS is a 10% speed loss, instead of a win
+ stbi__uint16 code[256];
+ stbi_uc values[256];
+ stbi_uc size[257];
+ unsigned int maxcode[18];
+ int delta[17]; // old 'firstsymbol' - old 'firstcode'
} stbi__huffman;
typedef struct
{
- stbi__context *s;
- stbi__huffman huff_dc[4];
- stbi__huffman huff_ac[4];
- stbi__uint16 dequant[4][64];
- stbi__int16 fast_ac[4][1 << FAST_BITS];
+ stbi__context *s;
+ stbi__huffman huff_dc[4];
+ stbi__huffman huff_ac[4];
+ stbi__uint16 dequant[4][64];
+ stbi__int16 fast_ac[4][1 << FAST_BITS];
-// sizes for components, interleaved MCUs
- int img_h_max, img_v_max;
- int img_mcu_x, img_mcu_y;
- int img_mcu_w, img_mcu_h;
+ // sizes for components, interleaved MCUs
+ int img_h_max, img_v_max;
+ int img_mcu_x, img_mcu_y;
+ int img_mcu_w, img_mcu_h;
-// definition of jpeg image component
- struct
- {
- int id;
- int h,v;
- int tq;
- int hd,ha;
- int dc_pred;
+ // definition of jpeg image component
+ struct
+ {
+ int id;
+ int h, v;
+ int tq;
+ int hd, ha;
+ int dc_pred;
- int x,y,w2,h2;
- stbi_uc *data;
- void *raw_data, *raw_coeff;
- stbi_uc *linebuf;
- short *coeff; // progressive only
- int coeff_w, coeff_h; // number of 8x8 coefficient blocks
- } img_comp[4];
+ int x, y, w2, h2;
+ stbi_uc *data;
+ void *raw_data, *raw_coeff;
+ stbi_uc *linebuf;
+ short *coeff; // progressive only
+ int coeff_w, coeff_h; // number of 8x8 coefficient blocks
+ } img_comp[4];
- stbi__uint32 code_buffer; // jpeg entropy-coded buffer
- int code_bits; // number of valid bits
- unsigned char marker; // marker seen while filling entropy buffer
- int nomore; // flag if we saw a marker so must stop
+ stbi__uint32 code_buffer; // jpeg entropy-coded buffer
+ int code_bits; // number of valid bits
+ unsigned char marker; // marker seen while filling entropy buffer
+ int nomore; // flag if we saw a marker so must stop
- int progressive;
- int spec_start;
- int spec_end;
- int succ_high;
- int succ_low;
- int eob_run;
- int jfif;
- int app14_color_transform; // Adobe APP14 tag
- int rgb;
+ int progressive;
+ int spec_start;
+ int spec_end;
+ int succ_high;
+ int succ_low;
+ int eob_run;
+ int jfif;
+ int app14_color_transform; // Adobe APP14 tag
+ int rgb;
- int scan_n, order[4];
- int restart_interval, todo;
+ int scan_n, order[4];
+ int restart_interval, todo;
-// kernels
- void (*idct_block_kernel)(stbi_uc *out, int out_stride, short data[64]);
- void (*YCbCr_to_RGB_kernel)(stbi_uc *out, const stbi_uc *y, const stbi_uc *pcb, const stbi_uc *pcr, int count, int step);
- stbi_uc *(*resample_row_hv_2_kernel)(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs);
+ // kernels
+ void (*idct_block_kernel)(stbi_uc *out, int out_stride, short data[64]);
+
+ void (*YCbCr_to_RGB_kernel)(stbi_uc *out, const stbi_uc *y, const stbi_uc *pcb, const stbi_uc *pcr, int count, int step);
+
+ stbi_uc *(*resample_row_hv_2_kernel)(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs);
} stbi__jpeg;
static int stbi__build_huffman(stbi__huffman *h, int *count)
{
- int i,j,k=0;
- unsigned int code;
- // build size list for each symbol (from JPEG spec)
- for (i=0; i < 16; ++i)
- for (j=0; j < count[i]; ++j)
- h->size[k++] = (stbi_uc) (i+1);
- h->size[k] = 0;
+ int i, j, k = 0;
+ unsigned int code;
+ // build size list for each symbol (from JPEG spec)
+ for (i = 0; i < 16; ++i)
+ for (j = 0; j < count[i]; ++j)
+ h->size[k++] = (stbi_uc)(i + 1);
+ h->size[k] = 0;
- // compute actual symbols (from jpeg spec)
- code = 0;
- k = 0;
- for(j=1; j <= 16; ++j) {
- // compute delta to add to code to compute symbol id
- h->delta[j] = k - code;
- if (h->size[k] == j) {
- while (h->size[k] == j)
- h->code[k++] = (stbi__uint16) (code++);
- if (code-1 >= (1u << j)) return stbi__err("bad code lengths","Corrupt JPEG");
- }
- // compute largest code + 1 for this size, preshifted as needed later
- h->maxcode[j] = code << (16-j);
- code <<= 1;
- }
- h->maxcode[j] = 0xffffffff;
+ // compute actual symbols (from jpeg spec)
+ code = 0;
+ k = 0;
+ for (j = 1; j <= 16; ++j)
+ {
+ // compute delta to add to code to compute symbol id
+ h->delta[j] = k - code;
+ if (h->size[k] == j)
+ {
+ while (h->size[k] == j)
+ h->code[k++] = (stbi__uint16)code++;
+ if (code - 1 >= 1u << j) return stbi__err("bad code lengths", "Corrupt JPEG");
+ }
+ // compute largest code + 1 for this size, preshifted as needed later
+ h->maxcode[j] = code << (16 - j);
+ code <<= 1;
+ }
+ h->maxcode[j] = 0xffffffff;
- // build non-spec acceleration table; 255 is flag for not-accelerated
- memset(h->fast, 255, 1 << FAST_BITS);
- for (i=0; i < k; ++i) {
- int s = h->size[i];
- if (s <= FAST_BITS) {
- int c = h->code[i] << (FAST_BITS-s);
- int m = 1 << (FAST_BITS-s);
- for (j=0; j < m; ++j) {
- h->fast[c+j] = (stbi_uc) i;
- }
- }
- }
- return 1;
+ // build non-spec acceleration table; 255 is flag for not-accelerated
+ memset(h->fast, 255, 1 << FAST_BITS);
+ for (i = 0; i < k; ++i)
+ {
+ int s = h->size[i];
+ if (s <= FAST_BITS)
+ {
+ int c = h->code[i] << (FAST_BITS - s);
+ int m = 1 << (FAST_BITS - s);
+ for (j = 0; j < m; ++j)
+ {
+ h->fast[c + j] = (stbi_uc)i;
+ }
+ }
+ }
+ return 1;
}
// build a table that decodes both magnitude and value of small ACs in
// one go.
static void stbi__build_fast_ac(stbi__int16 *fast_ac, stbi__huffman *h)
{
- int i;
- for (i=0; i < (1 << FAST_BITS); ++i) {
- stbi_uc fast = h->fast[i];
- fast_ac[i] = 0;
- if (fast < 255) {
- int rs = h->values[fast];
- int run = (rs >> 4) & 15;
- int magbits = rs & 15;
- int len = h->size[fast];
+ int i;
+ for (i = 0; i < 1 << FAST_BITS; ++i)
+ {
+ stbi_uc fast = h->fast[i];
+ fast_ac[i] = 0;
+ if (fast < 255)
+ {
+ int rs = h->values[fast];
+ int run = rs >> 4 & 15;
+ int magbits = rs & 15;
+ int len = h->size[fast];
- if (magbits && len + magbits <= FAST_BITS) {
- // magnitude code followed by receive_extend code
- int k = ((i << len) & ((1 << FAST_BITS) - 1)) >> (FAST_BITS - magbits);
- int m = 1 << (magbits - 1);
- if (k < m) k += (~0U << magbits) + 1;
- // if the result is small enough, we can fit it in fast_ac table
- if (k >= -128 && k <= 127)
- fast_ac[i] = (stbi__int16) ((k * 256) + (run * 16) + (len + magbits));
- }
- }
- }
+ if (magbits && len + magbits <= FAST_BITS)
+ {
+ // magnitude code followed by receive_extend code
+ int k = (i << len & (1 << FAST_BITS) - 1) >> (FAST_BITS - magbits);
+ int m = 1 << (magbits - 1);
+ if (k < m) k += (~0U << magbits) + 1;
+ // if the result is small enough, we can fit it in fast_ac table
+ if (k >= -128 && k <= 127)
+ fast_ac[i] = (stbi__int16)(k * 256 + run * 16 + (len + magbits));
+ }
+ }
+ }
}
static void stbi__grow_buffer_unsafe(stbi__jpeg *j)
{
- do {
- unsigned int b = j->nomore ? 0 : stbi__get8(j->s);
- if (b == 0xff) {
- int c = stbi__get8(j->s);
- while (c == 0xff) c = stbi__get8(j->s); // consume fill bytes
- if (c != 0) {
- j->marker = (unsigned char) c;
- j->nomore = 1;
- return;
- }
- }
- j->code_buffer |= b << (24 - j->code_bits);
- j->code_bits += 8;
- } while (j->code_bits <= 24);
+ do
+ {
+ unsigned int b = j->nomore ? 0 : stbi__get8(j->s);
+ if (b == 0xff)
+ {
+ int c = stbi__get8(j->s);
+ while (c == 0xff) c = stbi__get8(j->s); // consume fill bytes
+ if (c != 0)
+ {
+ j->marker = (unsigned char)c;
+ j->nomore = 1;
+ return;
+ }
+ }
+ j->code_buffer |= b << (24 - j->code_bits);
+ j->code_bits += 8;
+ }
+ while (j->code_bits <= 24);
}
// (1 << n) - 1
-static const stbi__uint32 stbi__bmask[17]={0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535};
+static const stbi__uint32 stbi__bmask[17] = {0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535};
// decode a jpeg huffman value from the bitstream
stbi_inline static int stbi__jpeg_huff_decode(stbi__jpeg *j, stbi__huffman *h)
{
- unsigned int temp;
- int c,k;
+ unsigned int temp;
+ int c, k;
- if (j->code_bits < 16) stbi__grow_buffer_unsafe(j);
+ if (j->code_bits < 16) stbi__grow_buffer_unsafe(j);
- // look at the top FAST_BITS and determine what symbol ID it is,
- // if the code is <= FAST_BITS
- c = (j->code_buffer >> (32 - FAST_BITS)) & ((1 << FAST_BITS)-1);
- k = h->fast[c];
- if (k < 255) {
- int s = h->size[k];
- if (s > j->code_bits)
- return -1;
- j->code_buffer <<= s;
- j->code_bits -= s;
- return h->values[k];
- }
+ // look at the top FAST_BITS and determine what symbol ID it is,
+ // if the code is <= FAST_BITS
+ c = j->code_buffer >> (32 - FAST_BITS) & (1 << FAST_BITS) - 1;
+ k = h->fast[c];
+ if (k < 255)
+ {
+ int s = h->size[k];
+ if (s > j->code_bits)
+ return -1;
+ j->code_buffer <<= s;
+ j->code_bits -= s;
+ return h->values[k];
+ }
- // naive test is to shift the code_buffer down so k bits are
- // valid, then test against maxcode. To speed this up, we've
- // preshifted maxcode left so that it has (16-k) 0s at the
- // end; in other words, regardless of the number of bits, it
- // wants to be compared against something shifted to have 16;
- // that way we don't need to shift inside the loop.
- temp = j->code_buffer >> 16;
- for (k=FAST_BITS+1 ; ; ++k)
- if (temp < h->maxcode[k])
- break;
- if (k == 17) {
- // error! code not found
- j->code_bits -= 16;
- return -1;
- }
+ // naive test is to shift the code_buffer down so k bits are
+ // valid, then test against maxcode. To speed this up, we've
+ // preshifted maxcode left so that it has (16-k) 0s at the
+ // end; in other words, regardless of the number of bits, it
+ // wants to be compared against something shifted to have 16;
+ // that way we don't need to shift inside the loop.
+ temp = j->code_buffer >> 16;
+ for (k = FAST_BITS + 1; ; ++k)
+ if (temp < h->maxcode[k])
+ break;
+ if (k == 17)
+ {
+ // error! code not found
+ j->code_bits -= 16;
+ return -1;
+ }
- if (k > j->code_bits)
- return -1;
+ if (k > j->code_bits)
+ return -1;
- // convert the huffman code to the symbol id
- c = ((j->code_buffer >> (32 - k)) & stbi__bmask[k]) + h->delta[k];
- STBI_ASSERT((((j->code_buffer) >> (32 - h->size[c])) & stbi__bmask[h->size[c]]) == h->code[c]);
+ // convert the huffman code to the symbol id
+ c = (j->code_buffer >> (32 - k) & stbi__bmask[k]) + h->delta[k];
+ STBI_ASSERT((((j->code_buffer) >> (32 - h->size[c])) & stbi__bmask[h->size[c]]) == h->code[c]);
- // convert the id to a symbol
- j->code_bits -= k;
- j->code_buffer <<= k;
- return h->values[c];
+ // convert the id to a symbol
+ j->code_bits -= k;
+ j->code_buffer <<= k;
+ return h->values[c];
}
// bias[n] = (-1<code_bits < n) stbi__grow_buffer_unsafe(j);
+ unsigned int k;
+ int sgn;
+ if (j->code_bits < n) stbi__grow_buffer_unsafe(j);
- sgn = (stbi__int32)j->code_buffer >> 31; // sign bit is always in MSB
- k = stbi_lrot(j->code_buffer, n);
- STBI_ASSERT(n >= 0 && n < (int) (sizeof(stbi__bmask)/sizeof(*stbi__bmask)));
- j->code_buffer = k & ~stbi__bmask[n];
- k &= stbi__bmask[n];
- j->code_bits -= n;
- return k + (stbi__jbias[n] & ~sgn);
+ sgn = (stbi__int32)j->code_buffer >> 31; // sign bit is always in MSB
+ k = stbi_lrot(j->code_buffer, n);
+ STBI_ASSERT(n >= 0 && n < (int)(sizeof(stbi__bmask) / sizeof(*stbi__bmask)));
+ j->code_buffer = k & ~stbi__bmask[n];
+ k &= stbi__bmask[n];
+ j->code_bits -= n;
+ return k + (stbi__jbias[n] & ~sgn);
}
// get some unsigned bits
stbi_inline static int stbi__jpeg_get_bits(stbi__jpeg *j, int n)
{
- unsigned int k;
- if (j->code_bits < n) stbi__grow_buffer_unsafe(j);
- k = stbi_lrot(j->code_buffer, n);
- j->code_buffer = k & ~stbi__bmask[n];
- k &= stbi__bmask[n];
- j->code_bits -= n;
- return k;
+ unsigned int k;
+ if (j->code_bits < n) stbi__grow_buffer_unsafe(j);
+ k = stbi_lrot(j->code_buffer, n);
+ j->code_buffer = k & ~stbi__bmask[n];
+ k &= stbi__bmask[n];
+ j->code_bits -= n;
+ return k;
}
stbi_inline static int stbi__jpeg_get_bit(stbi__jpeg *j)
{
- unsigned int k;
- if (j->code_bits < 1) stbi__grow_buffer_unsafe(j);
- k = j->code_buffer;
- j->code_buffer <<= 1;
- --j->code_bits;
- return k & 0x80000000;
+ unsigned int k;
+ if (j->code_bits < 1) stbi__grow_buffer_unsafe(j);
+ k = j->code_buffer;
+ j->code_buffer <<= 1;
+ --j->code_bits;
+ return k & 0x80000000;
}
// given a value that's at position X in the zigzag stream,
// where does it appear in the 8x8 matrix coded as row-major?
-static const stbi_uc stbi__jpeg_dezigzag[64+15] =
+static const stbi_uc stbi__jpeg_dezigzag[64 + 15] =
{
- 0, 1, 8, 16, 9, 2, 3, 10,
- 17, 24, 32, 25, 18, 11, 4, 5,
- 12, 19, 26, 33, 40, 48, 41, 34,
- 27, 20, 13, 6, 7, 14, 21, 28,
- 35, 42, 49, 56, 57, 50, 43, 36,
- 29, 22, 15, 23, 30, 37, 44, 51,
- 58, 59, 52, 45, 38, 31, 39, 46,
- 53, 60, 61, 54, 47, 55, 62, 63,
- // let corrupt input sample past end
- 63, 63, 63, 63, 63, 63, 63, 63,
- 63, 63, 63, 63, 63, 63, 63
+ 0, 1, 8, 16, 9, 2, 3, 10,
+ 17, 24, 32, 25, 18, 11, 4, 5,
+ 12, 19, 26, 33, 40, 48, 41, 34,
+ 27, 20, 13, 6, 7, 14, 21, 28,
+ 35, 42, 49, 56, 57, 50, 43, 36,
+ 29, 22, 15, 23, 30, 37, 44, 51,
+ 58, 59, 52, 45, 38, 31, 39, 46,
+ 53, 60, 61, 54, 47, 55, 62, 63,
+ // let corrupt input sample past end
+ 63, 63, 63, 63, 63, 63, 63, 63,
+ 63, 63, 63, 63, 63, 63, 63
};
// decode one 64-entry block--
static int stbi__jpeg_decode_block(stbi__jpeg *j, short data[64], stbi__huffman *hdc, stbi__huffman *hac, stbi__int16 *fac, int b, stbi__uint16 *dequant)
{
- int diff,dc,k;
- int t;
+ int diff, dc, k;
+ int t;
- if (j->code_bits < 16) stbi__grow_buffer_unsafe(j);
- t = stbi__jpeg_huff_decode(j, hdc);
- if (t < 0) return stbi__err("bad huffman code","Corrupt JPEG");
+ if (j->code_bits < 16) stbi__grow_buffer_unsafe(j);
+ t = stbi__jpeg_huff_decode(j, hdc);
+ if (t < 0) return stbi__err("bad huffman code", "Corrupt JPEG");
- // 0 all the ac values now so we can do it 32-bits at a time
- memset(data,0,64*sizeof(data[0]));
+ // 0 all the ac values now so we can do it 32-bits at a time
+ memset(data, 0, 64 * sizeof(data[0]));
- diff = t ? stbi__extend_receive(j, t) : 0;
- dc = j->img_comp[b].dc_pred + diff;
- j->img_comp[b].dc_pred = dc;
- data[0] = (short) (dc * dequant[0]);
+ diff = t ? stbi__extend_receive(j, t) : 0;
+ dc = j->img_comp[b].dc_pred + diff;
+ j->img_comp[b].dc_pred = dc;
+ data[0] = (short)(dc * dequant[0]);
- // decode AC components, see JPEG spec
- k = 1;
- do {
- unsigned int zig;
- int c,r,s;
- if (j->code_bits < 16) stbi__grow_buffer_unsafe(j);
- c = (j->code_buffer >> (32 - FAST_BITS)) & ((1 << FAST_BITS)-1);
- r = fac[c];
- if (r) { // fast-AC path
- k += (r >> 4) & 15; // run
- s = r & 15; // combined length
- j->code_buffer <<= s;
- j->code_bits -= s;
- // decode into unzigzag'd location
- zig = stbi__jpeg_dezigzag[k++];
- data[zig] = (short) ((r >> 8) * dequant[zig]);
- } else {
- int rs = stbi__jpeg_huff_decode(j, hac);
- if (rs < 0) return stbi__err("bad huffman code","Corrupt JPEG");
- s = rs & 15;
- r = rs >> 4;
- if (s == 0) {
- if (rs != 0xf0) break; // end block
- k += 16;
- } else {
- k += r;
+ // decode AC components, see JPEG spec
+ k = 1;
+ do
+ {
+ unsigned int zig;
+ int c, r, s;
+ if (j->code_bits < 16) stbi__grow_buffer_unsafe(j);
+ c = j->code_buffer >> (32 - FAST_BITS) & (1 << FAST_BITS) - 1;
+ r = fac[c];
+ if (r)
+ { // fast-AC path
+ k += r >> 4 & 15; // run
+ s = r & 15; // combined length
+ j->code_buffer <<= s;
+ j->code_bits -= s;
// decode into unzigzag'd location
zig = stbi__jpeg_dezigzag[k++];
- data[zig] = (short) (stbi__extend_receive(j,s) * dequant[zig]);
- }
- }
- } while (k < 64);
- return 1;
+ data[zig] = (short)((r >> 8) * dequant[zig]);
+ }
+ else
+ {
+ int rs = stbi__jpeg_huff_decode(j, hac);
+ if (rs < 0) return stbi__err("bad huffman code", "Corrupt JPEG");
+ s = rs & 15;
+ r = rs >> 4;
+ if (s == 0)
+ {
+ if (rs != 0xf0) break; // end block
+ k += 16;
+ }
+ else
+ {
+ k += r;
+ // decode into unzigzag'd location
+ zig = stbi__jpeg_dezigzag[k++];
+ data[zig] = (short)(stbi__extend_receive(j, s) * dequant[zig]);
+ }
+ }
+ }
+ while (k < 64);
+ return 1;
}
static int stbi__jpeg_decode_block_prog_dc(stbi__jpeg *j, short data[64], stbi__huffman *hdc, int b)
{
- int diff,dc;
- int t;
- if (j->spec_end != 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG");
+ int diff, dc;
+ int t;
+ if (j->spec_end != 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG");
- if (j->code_bits < 16) stbi__grow_buffer_unsafe(j);
+ if (j->code_bits < 16) stbi__grow_buffer_unsafe(j);
- if (j->succ_high == 0) {
- // first scan for DC coefficient, must be first
- memset(data,0,64*sizeof(data[0])); // 0 all the ac values now
- t = stbi__jpeg_huff_decode(j, hdc);
- diff = t ? stbi__extend_receive(j, t) : 0;
+ if (j->succ_high == 0)
+ {
+ // first scan for DC coefficient, must be first
+ memset(data, 0, 64 * sizeof(data[0])); // 0 all the ac values now
+ t = stbi__jpeg_huff_decode(j, hdc);
+ diff = t ? stbi__extend_receive(j, t) : 0;
- dc = j->img_comp[b].dc_pred + diff;
- j->img_comp[b].dc_pred = dc;
- data[0] = (short) (dc << j->succ_low);
- } else {
- // refinement scan for DC coefficient
- if (stbi__jpeg_get_bit(j))
- data[0] += (short) (1 << j->succ_low);
- }
- return 1;
+ dc = j->img_comp[b].dc_pred + diff;
+ j->img_comp[b].dc_pred = dc;
+ data[0] = (short)(dc << j->succ_low);
+ }
+ else
+ {
+ // refinement scan for DC coefficient
+ if (stbi__jpeg_get_bit(j))
+ data[0] += (short)(1 << j->succ_low);
+ }
+ return 1;
}
// @OPTIMIZE: store non-zigzagged during the decode passes,
// and only de-zigzag when dequantizing
static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg *j, short data[64], stbi__huffman *hac, stbi__int16 *fac)
{
- int k;
- if (j->spec_start == 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG");
+ int k;
+ if (j->spec_start == 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG");
- if (j->succ_high == 0) {
- int shift = j->succ_low;
+ if (j->succ_high == 0)
+ {
+ int shift = j->succ_low;
- if (j->eob_run) {
- --j->eob_run;
- return 1;
- }
+ if (j->eob_run)
+ {
+ --j->eob_run;
+ return 1;
+ }
- k = j->spec_start;
- do {
- unsigned int zig;
- int c,r,s;
- if (j->code_bits < 16) stbi__grow_buffer_unsafe(j);
- c = (j->code_buffer >> (32 - FAST_BITS)) & ((1 << FAST_BITS)-1);
- r = fac[c];
- if (r) { // fast-AC path
- k += (r >> 4) & 15; // run
- s = r & 15; // combined length
- j->code_buffer <<= s;
- j->code_bits -= s;
- zig = stbi__jpeg_dezigzag[k++];
- data[zig] = (short) ((r >> 8) << shift);
- } else {
- int rs = stbi__jpeg_huff_decode(j, hac);
- if (rs < 0) return stbi__err("bad huffman code","Corrupt JPEG");
- s = rs & 15;
- r = rs >> 4;
- if (s == 0) {
- if (r < 15) {
- j->eob_run = (1 << r);
- if (r)
- j->eob_run += stbi__jpeg_get_bits(j, r);
- --j->eob_run;
- break;
- }
- k += 16;
- } else {
- k += r;
- zig = stbi__jpeg_dezigzag[k++];
- data[zig] = (short) (stbi__extend_receive(j,s) << shift);
+ k = j->spec_start;
+ do
+ {
+ unsigned int zig;
+ int c, r, s;
+ if (j->code_bits < 16) stbi__grow_buffer_unsafe(j);
+ c = j->code_buffer >> (32 - FAST_BITS) & (1 << FAST_BITS) - 1;
+ r = fac[c];
+ if (r)
+ { // fast-AC path
+ k += r >> 4 & 15; // run
+ s = r & 15; // combined length
+ j->code_buffer <<= s;
+ j->code_bits -= s;
+ zig = stbi__jpeg_dezigzag[k++];
+ data[zig] = (short)((r >> 8) << shift);
}
- }
- } while (k <= j->spec_end);
- } else {
- // refinement scan for these AC coefficients
-
- short bit = (short) (1 << j->succ_low);
-
- if (j->eob_run) {
- --j->eob_run;
- for (k = j->spec_start; k <= j->spec_end; ++k) {
- short *p = &data[stbi__jpeg_dezigzag[k]];
- if (*p != 0)
- if (stbi__jpeg_get_bit(j))
- if ((*p & bit)==0) {
- if (*p > 0)
- *p += bit;
- else
- *p -= bit;
- }
- }
- } else {
- k = j->spec_start;
- do {
- int r,s;
- int rs = stbi__jpeg_huff_decode(j, hac); // @OPTIMIZE see if we can use the fast path here, advance-by-r is so slow, eh
- if (rs < 0) return stbi__err("bad huffman code","Corrupt JPEG");
- s = rs & 15;
- r = rs >> 4;
- if (s == 0) {
- if (r < 15) {
- j->eob_run = (1 << r) - 1;
- if (r)
- j->eob_run += stbi__jpeg_get_bits(j, r);
- r = 64; // force end of block
- } else {
- // r=15 s=0 should write 16 0s, so we just do
- // a run of 15 0s and then write s (which is 0),
- // so we don't have to do anything special here
- }
- } else {
- if (s != 1) return stbi__err("bad huffman code", "Corrupt JPEG");
- // sign bit
- if (stbi__jpeg_get_bit(j))
- s = bit;
- else
- s = -bit;
+ else
+ {
+ int rs = stbi__jpeg_huff_decode(j, hac);
+ if (rs < 0) return stbi__err("bad huffman code", "Corrupt JPEG");
+ s = rs & 15;
+ r = rs >> 4;
+ if (s == 0)
+ {
+ if (r < 15)
+ {
+ j->eob_run = 1 << r;
+ if (r)
+ j->eob_run += stbi__jpeg_get_bits(j, r);
+ --j->eob_run;
+ break;
+ }
+ k += 16;
+ }
+ else
+ {
+ k += r;
+ zig = stbi__jpeg_dezigzag[k++];
+ data[zig] = (short)(stbi__extend_receive(j, s) << shift);
+ }
}
+ }
+ while (k <= j->spec_end);
+ }
+ else
+ {
+ // refinement scan for these AC coefficients
- // advance by r
- while (k <= j->spec_end) {
- short *p = &data[stbi__jpeg_dezigzag[k++]];
- if (*p != 0) {
- if (stbi__jpeg_get_bit(j))
- if ((*p & bit)==0) {
- if (*p > 0)
- *p += bit;
- else
- *p -= bit;
- }
- } else {
- if (r == 0) {
- *p = (short) s;
- break;
- }
- --r;
- }
+ short bit = (short)(1 << j->succ_low);
+
+ if (j->eob_run)
+ {
+ --j->eob_run;
+ for (k = j->spec_start; k <= j->spec_end; ++k)
+ {
+ short *p = &data[stbi__jpeg_dezigzag[k]];
+ if (*p != 0)
+ if (stbi__jpeg_get_bit(j))
+ if ((*p & bit) == 0)
+ {
+ if (*p > 0)
+ *p += bit;
+ else
+ *p -= bit;
+ }
}
- } while (k <= j->spec_end);
- }
- }
- return 1;
+ }
+ else
+ {
+ k = j->spec_start;
+ do
+ {
+ int r, s;
+ int rs = stbi__jpeg_huff_decode(j, hac); // @OPTIMIZE see if we can use the fast path here, advance-by-r is so slow, eh
+ if (rs < 0) return stbi__err("bad huffman code", "Corrupt JPEG");
+ s = rs & 15;
+ r = rs >> 4;
+ if (s == 0)
+ {
+ if (r < 15)
+ {
+ j->eob_run = (1 << r) - 1;
+ if (r)
+ j->eob_run += stbi__jpeg_get_bits(j, r);
+ r = 64; // force end of block
+ }
+ else
+ {
+ // r=15 s=0 should write 16 0s, so we just do
+ // a run of 15 0s and then write s (which is 0),
+ // so we don't have to do anything special here
+ }
+ }
+ else
+ {
+ if (s != 1) return stbi__err("bad huffman code", "Corrupt JPEG");
+ // sign bit
+ if (stbi__jpeg_get_bit(j))
+ s = bit;
+ else
+ s = -bit;
+ }
+
+ // advance by r
+ while (k <= j->spec_end)
+ {
+ short *p = &data[stbi__jpeg_dezigzag[k++]];
+ if (*p != 0)
+ {
+ if (stbi__jpeg_get_bit(j))
+ if ((*p & bit) == 0)
+ {
+ if (*p > 0)
+ *p += bit;
+ else
+ *p -= bit;
+ }
+ }
+ else
+ {
+ if (r == 0)
+ {
+ *p = (short)s;
+ break;
+ }
+ --r;
+ }
+ }
+ }
+ while (k <= j->spec_end);
+ }
+ }
+ return 1;
}
// take a -128..127 value and stbi__clamp it and convert to 0..255
stbi_inline static stbi_uc stbi__clamp(int x)
{
- // trick to use a single test to catch both cases
- if ((unsigned int) x > 255) {
- if (x < 0) return 0;
- if (x > 255) return 255;
- }
- return (stbi_uc) x;
+ // trick to use a single test to catch both cases
+ if ((unsigned int)x > 255)
+ {
+ if (x < 0) return 0;
+ if (x > 255) return 255;
+ }
+ return (stbi_uc)x;
}
#define stbi__f2f(x) ((int) (((x) * 4096 + 0.5)))
@@ -2203,61 +2448,69 @@ stbi_inline static stbi_uc stbi__clamp(int x)
static void stbi__idct_block(stbi_uc *out, int out_stride, short data[64])
{
- int i,val[64],*v=val;
- stbi_uc *o;
- short *d = data;
+ int i, val[64], *v = val;
+ stbi_uc *o;
+ short *d = data;
- // columns
- for (i=0; i < 8; ++i,++d, ++v) {
- // if all zeroes, shortcut -- this avoids dequantizing 0s and IDCTing
- if (d[ 8]==0 && d[16]==0 && d[24]==0 && d[32]==0
- && d[40]==0 && d[48]==0 && d[56]==0) {
- // no shortcut 0 seconds
- // (1|2|3|4|5|6|7)==0 0 seconds
- // all separate -0.047 seconds
- // 1 && 2|3 && 4|5 && 6|7: -0.047 seconds
- int dcterm = d[0]*4;
- v[0] = v[8] = v[16] = v[24] = v[32] = v[40] = v[48] = v[56] = dcterm;
- } else {
- STBI__IDCT_1D(d[ 0],d[ 8],d[16],d[24],d[32],d[40],d[48],d[56])
- // constants scaled things up by 1<<12; let's bring them back
- // down, but keep 2 extra bits of precision
- x0 += 512; x1 += 512; x2 += 512; x3 += 512;
- v[ 0] = (x0+t3) >> 10;
- v[56] = (x0-t3) >> 10;
- v[ 8] = (x1+t2) >> 10;
- v[48] = (x1-t2) >> 10;
- v[16] = (x2+t1) >> 10;
- v[40] = (x2-t1) >> 10;
- v[24] = (x3+t0) >> 10;
- v[32] = (x3-t0) >> 10;
- }
- }
+ // columns
+ for (i = 0; i < 8; ++i, ++d, ++v)
+ {
+ // if all zeroes, shortcut -- this avoids dequantizing 0s and IDCTing
+ if (d[8] == 0 && d[16] == 0 && d[24] == 0 && d[32] == 0
+ && d[40] == 0 && d[48] == 0 && d[56] == 0)
+ {
+ // no shortcut 0 seconds
+ // (1|2|3|4|5|6|7)==0 0 seconds
+ // all separate -0.047 seconds
+ // 1 && 2|3 && 4|5 && 6|7: -0.047 seconds
+ int dcterm = d[0] * 4;
+ v[0] = v[8] = v[16] = v[24] = v[32] = v[40] = v[48] = v[56] = dcterm;
+ }
+ else
+ {
+ STBI__IDCT_1D(d[0], d[8], d[16], d[24], d[32], d[40], d[48], d[56])
+ // constants scaled things up by 1<<12; let's bring them back
+ // down, but keep 2 extra bits of precision
+ x0 += 512;
+ x1 += 512;
+ x2 += 512;
+ x3 += 512;
+ v[0] = (x0 + t3) >> 10;
+ v[56] = (x0 - t3) >> 10;
+ v[8] = (x1 + t2) >> 10;
+ v[48] = (x1 - t2) >> 10;
+ v[16] = (x2 + t1) >> 10;
+ v[40] = (x2 - t1) >> 10;
+ v[24] = (x3 + t0) >> 10;
+ v[32] = (x3 - t0) >> 10;
+ }
+ }
- for (i=0, v=val, o=out; i < 8; ++i,v+=8,o+=out_stride) {
- // no fast case since the first 1D IDCT spread components out
- STBI__IDCT_1D(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7])
- // constants scaled things up by 1<<12, plus we had 1<<2 from first
- // loop, plus horizontal and vertical each scale by sqrt(8) so together
- // we've got an extra 1<<3, so 1<<17 total we need to remove.
- // so we want to round that, which means adding 0.5 * 1<<17,
- // aka 65536. Also, we'll end up with -128 to 127 that we want
- // to encode as 0..255 by adding 128, so we'll add that before the shift
- x0 += 65536 + (128<<17);
- x1 += 65536 + (128<<17);
- x2 += 65536 + (128<<17);
- x3 += 65536 + (128<<17);
- // tried computing the shifts into temps, or'ing the temps to see
- // if any were out of range, but that was slower
- o[0] = stbi__clamp((x0+t3) >> 17);
- o[7] = stbi__clamp((x0-t3) >> 17);
- o[1] = stbi__clamp((x1+t2) >> 17);
- o[6] = stbi__clamp((x1-t2) >> 17);
- o[2] = stbi__clamp((x2+t1) >> 17);
- o[5] = stbi__clamp((x2-t1) >> 17);
- o[3] = stbi__clamp((x3+t0) >> 17);
- o[4] = stbi__clamp((x3-t0) >> 17);
- }
+ for (i = 0, v = val, o = out; i < 8; ++i, v += 8, o += out_stride)
+ {
+ // no fast case since the first 1D IDCT spread components out
+ STBI__IDCT_1D(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7])
+ // constants scaled things up by 1<<12, plus we had 1<<2 from first
+ // loop, plus horizontal and vertical each scale by sqrt(8) so together
+ // we've got an extra 1<<3, so 1<<17 total we need to remove.
+ // so we want to round that, which means adding 0.5 * 1<<17,
+ // aka 65536. Also, we'll end up with -128 to 127 that we want
+ // to encode as 0..255 by adding 128, so we'll add that before the shift
+ x0 += 65536 + (128 << 17);
+ x1 += 65536 + (128 << 17);
+ x2 += 65536 + (128 << 17);
+ x3 += 65536 + (128 << 17);
+ // tried computing the shifts into temps, or'ing the temps to see
+ // if any were out of range, but that was slower
+ o[0] = stbi__clamp((x0 + t3) >> 17);
+ o[7] = stbi__clamp((x0 - t3) >> 17);
+ o[1] = stbi__clamp((x1 + t2) >> 17);
+ o[6] = stbi__clamp((x1 - t2) >> 17);
+ o[2] = stbi__clamp((x2 + t1) >> 17);
+ o[5] = stbi__clamp((x2 - t1) >> 17);
+ o[3] = stbi__clamp((x3 + t0) >> 17);
+ o[4] = stbi__clamp((x3 - t0) >> 17);
+ }
}
#ifdef STBI_SSE2
@@ -2266,16 +2519,16 @@ static void stbi__idct_block(stbi_uc *out, int out_stride, short data[64])
// fully "transparent".
static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64])
{
- // This is constructed to match our regular (generic) integer IDCT exactly.
- __m128i row0, row1, row2, row3, row4, row5, row6, row7;
- __m128i tmp;
+ // This is constructed to match our regular (generic) integer IDCT exactly.
+ __m128i row0, row1, row2, row3, row4, row5, row6, row7;
+ __m128i tmp;
- // dot product constant: even elems=x, odd elems=y
- #define dct_const(x,y) _mm_setr_epi16((x),(y),(x),(y),(x),(y),(x),(y))
+ // dot product constant: even elems=x, odd elems=y
+ #define dct_const(x,y) _mm_setr_epi16((x),(y),(x),(y),(x),(y),(x),(y))
- // out(0) = c0[even]*x + c0[odd]*y (c0, x, y 16-bit, out 32-bit)
- // out(1) = c1[even]*x + c1[odd]*y
- #define dct_rot(out0,out1, x,y,c0,c1) \
+ // out(0) = c0[even]*x + c0[odd]*y (c0, x, y 16-bit, out 32-bit)
+ // out(1) = c1[even]*x + c1[odd]*y
+ #define dct_rot(out0,out1, x,y,c0,c1) \
__m128i c0##lo = _mm_unpacklo_epi16((x),(y)); \
__m128i c0##hi = _mm_unpackhi_epi16((x),(y)); \
__m128i out0##_l = _mm_madd_epi16(c0##lo, c0); \
@@ -2283,23 +2536,23 @@ static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64])
__m128i out1##_l = _mm_madd_epi16(c0##lo, c1); \
__m128i out1##_h = _mm_madd_epi16(c0##hi, c1)
- // out = in << 12 (in 16-bit, out 32-bit)
- #define dct_widen(out, in) \
+ // out = in << 12 (in 16-bit, out 32-bit)
+ #define dct_widen(out, in) \
__m128i out##_l = _mm_srai_epi32(_mm_unpacklo_epi16(_mm_setzero_si128(), (in)), 4); \
__m128i out##_h = _mm_srai_epi32(_mm_unpackhi_epi16(_mm_setzero_si128(), (in)), 4)
- // wide add
- #define dct_wadd(out, a, b) \
+ // wide add
+ #define dct_wadd(out, a, b) \
__m128i out##_l = _mm_add_epi32(a##_l, b##_l); \
__m128i out##_h = _mm_add_epi32(a##_h, b##_h)
- // wide sub
- #define dct_wsub(out, a, b) \
+ // wide sub
+ #define dct_wsub(out, a, b) \
__m128i out##_l = _mm_sub_epi32(a##_l, b##_l); \
__m128i out##_h = _mm_sub_epi32(a##_h, b##_h)
- // butterfly a/b, add bias, then shift by "s" and pack
- #define dct_bfly32o(out0, out1, a,b,bias,s) \
+ // butterfly a/b, add bias, then shift by "s" and pack
+ #define dct_bfly32o(out0, out1, a,b,bias,s) \
{ \
__m128i abiased_l = _mm_add_epi32(a##_l, bias); \
__m128i abiased_h = _mm_add_epi32(a##_h, bias); \
@@ -2309,19 +2562,19 @@ static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64])
out1 = _mm_packs_epi32(_mm_srai_epi32(dif_l, s), _mm_srai_epi32(dif_h, s)); \
}
- // 8-bit interleave step (for transposes)
- #define dct_interleave8(a, b) \
+ // 8-bit interleave step (for transposes)
+ #define dct_interleave8(a, b) \
tmp = a; \
a = _mm_unpacklo_epi8(a, b); \
b = _mm_unpackhi_epi8(tmp, b)
- // 16-bit interleave step (for transposes)
- #define dct_interleave16(a, b) \
+ // 16-bit interleave step (for transposes)
+ #define dct_interleave16(a, b) \
tmp = a; \
a = _mm_unpacklo_epi16(a, b); \
b = _mm_unpackhi_epi16(tmp, b)
- #define dct_pass(bias,shift) \
+ #define dct_pass(bias,shift) \
{ \
/* even part */ \
dct_rot(t2e,t3e, row2,row6, rot0_0,rot0_1); \
@@ -2349,94 +2602,101 @@ static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64])
dct_bfly32o(row3,row4, x3,x4,bias,shift); \
}
- __m128i rot0_0 = dct_const(stbi__f2f(0.5411961f), stbi__f2f(0.5411961f) + stbi__f2f(-1.847759065f));
- __m128i rot0_1 = dct_const(stbi__f2f(0.5411961f) + stbi__f2f( 0.765366865f), stbi__f2f(0.5411961f));
- __m128i rot1_0 = dct_const(stbi__f2f(1.175875602f) + stbi__f2f(-0.899976223f), stbi__f2f(1.175875602f));
- __m128i rot1_1 = dct_const(stbi__f2f(1.175875602f), stbi__f2f(1.175875602f) + stbi__f2f(-2.562915447f));
- __m128i rot2_0 = dct_const(stbi__f2f(-1.961570560f) + stbi__f2f( 0.298631336f), stbi__f2f(-1.961570560f));
- __m128i rot2_1 = dct_const(stbi__f2f(-1.961570560f), stbi__f2f(-1.961570560f) + stbi__f2f( 3.072711026f));
- __m128i rot3_0 = dct_const(stbi__f2f(-0.390180644f) + stbi__f2f( 2.053119869f), stbi__f2f(-0.390180644f));
- __m128i rot3_1 = dct_const(stbi__f2f(-0.390180644f), stbi__f2f(-0.390180644f) + stbi__f2f( 1.501321110f));
+ __m128i rot0_0 = dct_const(stbi__f2f(0.5411961f), stbi__f2f(0.5411961f) + stbi__f2f(-1.847759065f));
+ __m128i rot0_1 = dct_const(stbi__f2f(0.5411961f) + stbi__f2f(0.765366865f), stbi__f2f(0.5411961f));
+ __m128i rot1_0 = dct_const(stbi__f2f(1.175875602f) + stbi__f2f(-0.899976223f), stbi__f2f(1.175875602f));
+ __m128i rot1_1 = dct_const(stbi__f2f(1.175875602f), stbi__f2f(1.175875602f) + stbi__f2f(-2.562915447f));
+ __m128i rot2_0 = dct_const(stbi__f2f(-1.961570560f) + stbi__f2f(0.298631336f), stbi__f2f(-1.961570560f));
+ __m128i rot2_1 = dct_const(stbi__f2f(-1.961570560f), stbi__f2f(-1.961570560f) + stbi__f2f(3.072711026f));
+ __m128i rot3_0 = dct_const(stbi__f2f(-0.390180644f) + stbi__f2f(2.053119869f), stbi__f2f(-0.390180644f));
+ __m128i rot3_1 = dct_const(stbi__f2f(-0.390180644f), stbi__f2f(-0.390180644f) + stbi__f2f(1.501321110f));
- // rounding biases in column/row passes, see stbi__idct_block for explanation.
- __m128i bias_0 = _mm_set1_epi32(512);
- __m128i bias_1 = _mm_set1_epi32(65536 + (128<<17));
+ // rounding biases in column/row passes, see stbi__idct_block for explanation.
+ __m128i bias_0 = _mm_set1_epi32(512);
+ __m128i bias_1 = _mm_set1_epi32(65536 + (128 << 17));
- // load
- row0 = _mm_load_si128((const __m128i *) (data + 0*8));
- row1 = _mm_load_si128((const __m128i *) (data + 1*8));
- row2 = _mm_load_si128((const __m128i *) (data + 2*8));
- row3 = _mm_load_si128((const __m128i *) (data + 3*8));
- row4 = _mm_load_si128((const __m128i *) (data + 4*8));
- row5 = _mm_load_si128((const __m128i *) (data + 5*8));
- row6 = _mm_load_si128((const __m128i *) (data + 6*8));
- row7 = _mm_load_si128((const __m128i *) (data + 7*8));
+ // load
+ row0 = _mm_load_si128((const __m128i *)(data + 0 * 8));
+ row1 = _mm_load_si128((const __m128i *)(data + 1 * 8));
+ row2 = _mm_load_si128((const __m128i *)(data + 2 * 8));
+ row3 = _mm_load_si128((const __m128i *)(data + 3 * 8));
+ row4 = _mm_load_si128((const __m128i *)(data + 4 * 8));
+ row5 = _mm_load_si128((const __m128i *)(data + 5 * 8));
+ row6 = _mm_load_si128((const __m128i *)(data + 6 * 8));
+ row7 = _mm_load_si128((const __m128i *)(data + 7 * 8));
- // column pass
- dct_pass(bias_0, 10);
+ // column pass
+ dct_pass(bias_0, 10);
- {
- // 16bit 8x8 transpose pass 1
- dct_interleave16(row0, row4);
- dct_interleave16(row1, row5);
- dct_interleave16(row2, row6);
- dct_interleave16(row3, row7);
+ {
+ // 16bit 8x8 transpose pass 1
+ dct_interleave16(row0, row4);
+ dct_interleave16(row1, row5);
+ dct_interleave16(row2, row6);
+ dct_interleave16(row3, row7);
- // transpose pass 2
- dct_interleave16(row0, row2);
- dct_interleave16(row1, row3);
- dct_interleave16(row4, row6);
- dct_interleave16(row5, row7);
+ // transpose pass 2
+ dct_interleave16(row0, row2);
+ dct_interleave16(row1, row3);
+ dct_interleave16(row4, row6);
+ dct_interleave16(row5, row7);
- // transpose pass 3
- dct_interleave16(row0, row1);
- dct_interleave16(row2, row3);
- dct_interleave16(row4, row5);
- dct_interleave16(row6, row7);
- }
+ // transpose pass 3
+ dct_interleave16(row0, row1);
+ dct_interleave16(row2, row3);
+ dct_interleave16(row4, row5);
+ dct_interleave16(row6, row7);
+ }
- // row pass
- dct_pass(bias_1, 17);
+ // row pass
+ dct_pass(bias_1, 17);
- {
- // pack
- __m128i p0 = _mm_packus_epi16(row0, row1); // a0a1a2a3...a7b0b1b2b3...b7
- __m128i p1 = _mm_packus_epi16(row2, row3);
- __m128i p2 = _mm_packus_epi16(row4, row5);
- __m128i p3 = _mm_packus_epi16(row6, row7);
+ {
+ // pack
+ __m128i p0 = _mm_packus_epi16(row0, row1); // a0a1a2a3...a7b0b1b2b3...b7
+ __m128i p1 = _mm_packus_epi16(row2, row3);
+ __m128i p2 = _mm_packus_epi16(row4, row5);
+ __m128i p3 = _mm_packus_epi16(row6, row7);
- // 8bit 8x8 transpose pass 1
- dct_interleave8(p0, p2); // a0e0a1e1...
- dct_interleave8(p1, p3); // c0g0c1g1...
+ // 8bit 8x8 transpose pass 1
+ dct_interleave8(p0, p2); // a0e0a1e1...
+ dct_interleave8(p1, p3); // c0g0c1g1...
- // transpose pass 2
- dct_interleave8(p0, p1); // a0c0e0g0...
- dct_interleave8(p2, p3); // b0d0f0h0...
+ // transpose pass 2
+ dct_interleave8(p0, p1); // a0c0e0g0...
+ dct_interleave8(p2, p3); // b0d0f0h0...
- // transpose pass 3
- dct_interleave8(p0, p2); // a0b0c0d0...
- dct_interleave8(p1, p3); // a4b4c4d4...
+ // transpose pass 3
+ dct_interleave8(p0, p2); // a0b0c0d0...
+ dct_interleave8(p1, p3); // a4b4c4d4...
- // store
- _mm_storel_epi64((__m128i *) out, p0); out += out_stride;
- _mm_storel_epi64((__m128i *) out, _mm_shuffle_epi32(p0, 0x4e)); out += out_stride;
- _mm_storel_epi64((__m128i *) out, p2); out += out_stride;
- _mm_storel_epi64((__m128i *) out, _mm_shuffle_epi32(p2, 0x4e)); out += out_stride;
- _mm_storel_epi64((__m128i *) out, p1); out += out_stride;
- _mm_storel_epi64((__m128i *) out, _mm_shuffle_epi32(p1, 0x4e)); out += out_stride;
- _mm_storel_epi64((__m128i *) out, p3); out += out_stride;
- _mm_storel_epi64((__m128i *) out, _mm_shuffle_epi32(p3, 0x4e));
- }
+ // store
+ _mm_storel_epi64((__m128i *)out, p0);
+ out += out_stride;
+ _mm_storel_epi64((__m128i *)out, _mm_shuffle_epi32(p0, 0x4e));
+ out += out_stride;
+ _mm_storel_epi64((__m128i *)out, p2);
+ out += out_stride;
+ _mm_storel_epi64((__m128i *)out, _mm_shuffle_epi32(p2, 0x4e));
+ out += out_stride;
+ _mm_storel_epi64((__m128i *)out, p1);
+ out += out_stride;
+ _mm_storel_epi64((__m128i *)out, _mm_shuffle_epi32(p1, 0x4e));
+ out += out_stride;
+ _mm_storel_epi64((__m128i *)out, p3);
+ out += out_stride;
+ _mm_storel_epi64((__m128i *)out, _mm_shuffle_epi32(p3, 0x4e));
+ }
-#undef dct_const
-#undef dct_rot
-#undef dct_widen
-#undef dct_wadd
-#undef dct_wsub
-#undef dct_bfly32o
-#undef dct_interleave8
-#undef dct_interleave16
-#undef dct_pass
+ #undef dct_const
+ #undef dct_rot
+ #undef dct_widen
+ #undef dct_wadd
+ #undef dct_wsub
+ #undef dct_bfly32o
+ #undef dct_interleave8
+ #undef dct_interleave16
+ #undef dct_pass
}
#endif // STBI_SSE2
@@ -2447,45 +2707,45 @@ static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64])
// results to the generic C version.
static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64])
{
- int16x8_t row0, row1, row2, row3, row4, row5, row6, row7;
+ int16x8_t row0, row1, row2, row3, row4, row5, row6, row7;
- int16x4_t rot0_0 = vdup_n_s16(stbi__f2f(0.5411961f));
- int16x4_t rot0_1 = vdup_n_s16(stbi__f2f(-1.847759065f));
- int16x4_t rot0_2 = vdup_n_s16(stbi__f2f( 0.765366865f));
- int16x4_t rot1_0 = vdup_n_s16(stbi__f2f( 1.175875602f));
- int16x4_t rot1_1 = vdup_n_s16(stbi__f2f(-0.899976223f));
- int16x4_t rot1_2 = vdup_n_s16(stbi__f2f(-2.562915447f));
- int16x4_t rot2_0 = vdup_n_s16(stbi__f2f(-1.961570560f));
- int16x4_t rot2_1 = vdup_n_s16(stbi__f2f(-0.390180644f));
- int16x4_t rot3_0 = vdup_n_s16(stbi__f2f( 0.298631336f));
- int16x4_t rot3_1 = vdup_n_s16(stbi__f2f( 2.053119869f));
- int16x4_t rot3_2 = vdup_n_s16(stbi__f2f( 3.072711026f));
- int16x4_t rot3_3 = vdup_n_s16(stbi__f2f( 1.501321110f));
+ int16x4_t rot0_0 = vdup_n_s16(stbi__f2f(0.5411961f));
+ int16x4_t rot0_1 = vdup_n_s16(stbi__f2f(-1.847759065f));
+ int16x4_t rot0_2 = vdup_n_s16(stbi__f2f(0.765366865f));
+ int16x4_t rot1_0 = vdup_n_s16(stbi__f2f(1.175875602f));
+ int16x4_t rot1_1 = vdup_n_s16(stbi__f2f(-0.899976223f));
+ int16x4_t rot1_2 = vdup_n_s16(stbi__f2f(-2.562915447f));
+ int16x4_t rot2_0 = vdup_n_s16(stbi__f2f(-1.961570560f));
+ int16x4_t rot2_1 = vdup_n_s16(stbi__f2f(-0.390180644f));
+ int16x4_t rot3_0 = vdup_n_s16(stbi__f2f(0.298631336f));
+ int16x4_t rot3_1 = vdup_n_s16(stbi__f2f(2.053119869f));
+ int16x4_t rot3_2 = vdup_n_s16(stbi__f2f(3.072711026f));
+ int16x4_t rot3_3 = vdup_n_s16(stbi__f2f(1.501321110f));
-#define dct_long_mul(out, inq, coeff) \
+ #define dct_long_mul(out, inq, coeff) \
int32x4_t out##_l = vmull_s16(vget_low_s16(inq), coeff); \
int32x4_t out##_h = vmull_s16(vget_high_s16(inq), coeff)
-#define dct_long_mac(out, acc, inq, coeff) \
+ #define dct_long_mac(out, acc, inq, coeff) \
int32x4_t out##_l = vmlal_s16(acc##_l, vget_low_s16(inq), coeff); \
int32x4_t out##_h = vmlal_s16(acc##_h, vget_high_s16(inq), coeff)
-#define dct_widen(out, inq) \
+ #define dct_widen(out, inq) \
int32x4_t out##_l = vshll_n_s16(vget_low_s16(inq), 12); \
int32x4_t out##_h = vshll_n_s16(vget_high_s16(inq), 12)
-// wide add
-#define dct_wadd(out, a, b) \
+ // wide add
+ #define dct_wadd(out, a, b) \
int32x4_t out##_l = vaddq_s32(a##_l, b##_l); \
int32x4_t out##_h = vaddq_s32(a##_h, b##_h)
-// wide sub
-#define dct_wsub(out, a, b) \
+ // wide sub
+ #define dct_wsub(out, a, b) \
int32x4_t out##_l = vsubq_s32(a##_l, b##_l); \
int32x4_t out##_h = vsubq_s32(a##_h, b##_h)
-// butterfly a/b, then shift using "shiftop" by "s" and pack
-#define dct_bfly32o(out0,out1, a,b,shiftop,s) \
+ // butterfly a/b, then shift using "shiftop" by "s" and pack
+ #define dct_bfly32o(out0,out1, a,b,shiftop,s) \
{ \
dct_wadd(sum, a, b); \
dct_wsub(dif, a, b); \
@@ -2493,7 +2753,7 @@ static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64])
out1 = vcombine_s16(shiftop(dif_l, s), shiftop(dif_h, s)); \
}
-#define dct_pass(shiftop, shift) \
+ #define dct_pass(shiftop, shift) \
{ \
/* even part */ \
int16x8_t sum26 = vaddq_s16(row2, row6); \
@@ -2533,118 +2793,125 @@ static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64])
dct_bfly32o(row3,row4, x3,x4,shiftop,shift); \
}
- // load
- row0 = vld1q_s16(data + 0*8);
- row1 = vld1q_s16(data + 1*8);
- row2 = vld1q_s16(data + 2*8);
- row3 = vld1q_s16(data + 3*8);
- row4 = vld1q_s16(data + 4*8);
- row5 = vld1q_s16(data + 5*8);
- row6 = vld1q_s16(data + 6*8);
- row7 = vld1q_s16(data + 7*8);
+ // load
+ row0 = vld1q_s16(data + 0 * 8);
+ row1 = vld1q_s16(data + 1 * 8);
+ row2 = vld1q_s16(data + 2 * 8);
+ row3 = vld1q_s16(data + 3 * 8);
+ row4 = vld1q_s16(data + 4 * 8);
+ row5 = vld1q_s16(data + 5 * 8);
+ row6 = vld1q_s16(data + 6 * 8);
+ row7 = vld1q_s16(data + 7 * 8);
- // add DC bias
- row0 = vaddq_s16(row0, vsetq_lane_s16(1024, vdupq_n_s16(0), 0));
+ // add DC bias
+ row0 = vaddq_s16(row0, vsetq_lane_s16(1024, vdupq_n_s16(0), 0));
- // column pass
- dct_pass(vrshrn_n_s32, 10);
+ // column pass
+ dct_pass(vrshrn_n_s32, 10);
- // 16bit 8x8 transpose
- {
-// these three map to a single VTRN.16, VTRN.32, and VSWP, respectively.
-// whether compilers actually get this is another story, sadly.
-#define dct_trn16(x, y) { int16x8x2_t t = vtrnq_s16(x, y); x = t.val[0]; y = t.val[1]; }
-#define dct_trn32(x, y) { int32x4x2_t t = vtrnq_s32(vreinterpretq_s32_s16(x), vreinterpretq_s32_s16(y)); x = vreinterpretq_s16_s32(t.val[0]); y = vreinterpretq_s16_s32(t.val[1]); }
-#define dct_trn64(x, y) { int16x8_t x0 = x; int16x8_t y0 = y; x = vcombine_s16(vget_low_s16(x0), vget_low_s16(y0)); y = vcombine_s16(vget_high_s16(x0), vget_high_s16(y0)); }
+ // 16bit 8x8 transpose
+ {
+ // these three map to a single VTRN.16, VTRN.32, and VSWP, respectively.
+ // whether compilers actually get this is another story, sadly.
+ #define dct_trn16(x, y) { int16x8x2_t t = vtrnq_s16(x, y); x = t.val[0]; y = t.val[1]; }
+ #define dct_trn32(x, y) { int32x4x2_t t = vtrnq_s32(vreinterpretq_s32_s16(x), vreinterpretq_s32_s16(y)); x = vreinterpretq_s16_s32(t.val[0]); y = vreinterpretq_s16_s32(t.val[1]); }
+ #define dct_trn64(x, y) { int16x8_t x0 = x; int16x8_t y0 = y; x = vcombine_s16(vget_low_s16(x0), vget_low_s16(y0)); y = vcombine_s16(vget_high_s16(x0), vget_high_s16(y0)); }
- // pass 1
- dct_trn16(row0, row1); // a0b0a2b2a4b4a6b6
- dct_trn16(row2, row3);
- dct_trn16(row4, row5);
- dct_trn16(row6, row7);
+ // pass 1
+ dct_trn16(row0, row1); // a0b0a2b2a4b4a6b6
+ dct_trn16(row2, row3);
+ dct_trn16(row4, row5);
+ dct_trn16(row6, row7);
- // pass 2
- dct_trn32(row0, row2); // a0b0c0d0a4b4c4d4
- dct_trn32(row1, row3);
- dct_trn32(row4, row6);
- dct_trn32(row5, row7);
+ // pass 2
+ dct_trn32(row0, row2); // a0b0c0d0a4b4c4d4
+ dct_trn32(row1, row3);
+ dct_trn32(row4, row6);
+ dct_trn32(row5, row7);
- // pass 3
- dct_trn64(row0, row4); // a0b0c0d0e0f0g0h0
- dct_trn64(row1, row5);
- dct_trn64(row2, row6);
- dct_trn64(row3, row7);
+ // pass 3
+ dct_trn64(row0, row4); // a0b0c0d0e0f0g0h0
+ dct_trn64(row1, row5);
+ dct_trn64(row2, row6);
+ dct_trn64(row3, row7);
-#undef dct_trn16
-#undef dct_trn32
-#undef dct_trn64
- }
+ #undef dct_trn16
+ #undef dct_trn32
+ #undef dct_trn64
+ }
- // row pass
- // vrshrn_n_s32 only supports shifts up to 16, we need
- // 17. so do a non-rounding shift of 16 first then follow
- // up with a rounding shift by 1.
- dct_pass(vshrn_n_s32, 16);
+ // row pass
+ // vrshrn_n_s32 only supports shifts up to 16, we need
+ // 17. so do a non-rounding shift of 16 first then follow
+ // up with a rounding shift by 1.
+ dct_pass(vshrn_n_s32, 16);
- {
- // pack and round
- uint8x8_t p0 = vqrshrun_n_s16(row0, 1);
- uint8x8_t p1 = vqrshrun_n_s16(row1, 1);
- uint8x8_t p2 = vqrshrun_n_s16(row2, 1);
- uint8x8_t p3 = vqrshrun_n_s16(row3, 1);
- uint8x8_t p4 = vqrshrun_n_s16(row4, 1);
- uint8x8_t p5 = vqrshrun_n_s16(row5, 1);
- uint8x8_t p6 = vqrshrun_n_s16(row6, 1);
- uint8x8_t p7 = vqrshrun_n_s16(row7, 1);
+ {
+ // pack and round
+ uint8x8_t p0 = vqrshrun_n_s16(row0, 1);
+ uint8x8_t p1 = vqrshrun_n_s16(row1, 1);
+ uint8x8_t p2 = vqrshrun_n_s16(row2, 1);
+ uint8x8_t p3 = vqrshrun_n_s16(row3, 1);
+ uint8x8_t p4 = vqrshrun_n_s16(row4, 1);
+ uint8x8_t p5 = vqrshrun_n_s16(row5, 1);
+ uint8x8_t p6 = vqrshrun_n_s16(row6, 1);
+ uint8x8_t p7 = vqrshrun_n_s16(row7, 1);
- // again, these can translate into one instruction, but often don't.
-#define dct_trn8_8(x, y) { uint8x8x2_t t = vtrn_u8(x, y); x = t.val[0]; y = t.val[1]; }
-#define dct_trn8_16(x, y) { uint16x4x2_t t = vtrn_u16(vreinterpret_u16_u8(x), vreinterpret_u16_u8(y)); x = vreinterpret_u8_u16(t.val[0]); y = vreinterpret_u8_u16(t.val[1]); }
-#define dct_trn8_32(x, y) { uint32x2x2_t t = vtrn_u32(vreinterpret_u32_u8(x), vreinterpret_u32_u8(y)); x = vreinterpret_u8_u32(t.val[0]); y = vreinterpret_u8_u32(t.val[1]); }
+ // again, these can translate into one instruction, but often don't.
+ #define dct_trn8_8(x, y) { uint8x8x2_t t = vtrn_u8(x, y); x = t.val[0]; y = t.val[1]; }
+ #define dct_trn8_16(x, y) { uint16x4x2_t t = vtrn_u16(vreinterpret_u16_u8(x), vreinterpret_u16_u8(y)); x = vreinterpret_u8_u16(t.val[0]); y = vreinterpret_u8_u16(t.val[1]); }
+ #define dct_trn8_32(x, y) { uint32x2x2_t t = vtrn_u32(vreinterpret_u32_u8(x), vreinterpret_u32_u8(y)); x = vreinterpret_u8_u32(t.val[0]); y = vreinterpret_u8_u32(t.val[1]); }
- // sadly can't use interleaved stores here since we only write
- // 8 bytes to each scan line!
+ // sadly can't use interleaved stores here since we only write
+ // 8 bytes to each scan line!
- // 8x8 8-bit transpose pass 1
- dct_trn8_8(p0, p1);
- dct_trn8_8(p2, p3);
- dct_trn8_8(p4, p5);
- dct_trn8_8(p6, p7);
+ // 8x8 8-bit transpose pass 1
+ dct_trn8_8(p0, p1);
+ dct_trn8_8(p2, p3);
+ dct_trn8_8(p4, p5);
+ dct_trn8_8(p6, p7);
- // pass 2
- dct_trn8_16(p0, p2);
- dct_trn8_16(p1, p3);
- dct_trn8_16(p4, p6);
- dct_trn8_16(p5, p7);
+ // pass 2
+ dct_trn8_16(p0, p2);
+ dct_trn8_16(p1, p3);
+ dct_trn8_16(p4, p6);
+ dct_trn8_16(p5, p7);
- // pass 3
- dct_trn8_32(p0, p4);
- dct_trn8_32(p1, p5);
- dct_trn8_32(p2, p6);
- dct_trn8_32(p3, p7);
+ // pass 3
+ dct_trn8_32(p0, p4);
+ dct_trn8_32(p1, p5);
+ dct_trn8_32(p2, p6);
+ dct_trn8_32(p3, p7);
- // store
- vst1_u8(out, p0); out += out_stride;
- vst1_u8(out, p1); out += out_stride;
- vst1_u8(out, p2); out += out_stride;
- vst1_u8(out, p3); out += out_stride;
- vst1_u8(out, p4); out += out_stride;
- vst1_u8(out, p5); out += out_stride;
- vst1_u8(out, p6); out += out_stride;
- vst1_u8(out, p7);
+ // store
+ vst1_u8(out, p0);
+ out += out_stride;
+ vst1_u8(out, p1);
+ out += out_stride;
+ vst1_u8(out, p2);
+ out += out_stride;
+ vst1_u8(out, p3);
+ out += out_stride;
+ vst1_u8(out, p4);
+ out += out_stride;
+ vst1_u8(out, p5);
+ out += out_stride;
+ vst1_u8(out, p6);
+ out += out_stride;
+ vst1_u8(out, p7);
-#undef dct_trn8_8
-#undef dct_trn8_16
-#undef dct_trn8_32
- }
+ #undef dct_trn8_8
+ #undef dct_trn8_16
+ #undef dct_trn8_32
+ }
-#undef dct_long_mul
-#undef dct_long_mac
-#undef dct_widen
-#undef dct_wadd
-#undef dct_wsub
-#undef dct_bfly32o
-#undef dct_pass
+ #undef dct_long_mul
+ #undef dct_long_mac
+ #undef dct_widen
+ #undef dct_wadd
+ #undef dct_wsub
+ #undef dct_bfly32o
+ #undef dct_pass
}
#endif // STBI_NEON
@@ -2655,13 +2922,18 @@ static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64])
// marker, return 0xff, which is never a valid marker value
static stbi_uc stbi__get_marker(stbi__jpeg *j)
{
- stbi_uc x;
- if (j->marker != STBI__MARKER_none) { x = j->marker; j->marker = STBI__MARKER_none; return x; }
- x = stbi__get8(j->s);
- if (x != 0xff) return STBI__MARKER_none;
- while (x == 0xff)
- x = stbi__get8(j->s); // consume repeated 0xff fill bytes
- return x;
+ stbi_uc x;
+ if (j->marker != STBI__MARKER_none)
+ {
+ x = j->marker;
+ j->marker = STBI__MARKER_none;
+ return x;
+ }
+ x = stbi__get8(j->s);
+ if (x != 0xff) return STBI__MARKER_none;
+ while (x == 0xff)
+ x = stbi__get8(j->s); // consume repeated 0xff fill bytes
+ return x;
}
// in each scan, we'll have scan_n components, and the order
@@ -2672,412 +2944,481 @@ static stbi_uc stbi__get_marker(stbi__jpeg *j)
// the dc prediction
static void stbi__jpeg_reset(stbi__jpeg *j)
{
- j->code_bits = 0;
- j->code_buffer = 0;
- j->nomore = 0;
- j->img_comp[0].dc_pred = j->img_comp[1].dc_pred = j->img_comp[2].dc_pred = j->img_comp[3].dc_pred = 0;
- j->marker = STBI__MARKER_none;
- j->todo = j->restart_interval ? j->restart_interval : 0x7fffffff;
- j->eob_run = 0;
- // no more than 1<<31 MCUs if no restart_interal? that's plenty safe,
- // since we don't even allow 1<<30 pixels
+ j->code_bits = 0;
+ j->code_buffer = 0;
+ j->nomore = 0;
+ j->img_comp[0].dc_pred = j->img_comp[1].dc_pred = j->img_comp[2].dc_pred = j->img_comp[3].dc_pred = 0;
+ j->marker = STBI__MARKER_none;
+ j->todo = j->restart_interval ? j->restart_interval : 0x7fffffff;
+ j->eob_run = 0;
+ // no more than 1<<31 MCUs if no restart_interal? that's plenty safe,
+ // since we don't even allow 1<<30 pixels
}
static int stbi__parse_entropy_coded_data(stbi__jpeg *z)
{
- stbi__jpeg_reset(z);
- if (!z->progressive) {
- if (z->scan_n == 1) {
- int i,j;
- STBI_SIMD_ALIGN(short, data[64]);
- int n = z->order[0];
- // non-interleaved data, we just need to process one block at a time,
- // in trivial scanline order
- // number of blocks to do just depends on how many actual "pixels" this
- // component has, independent of interleaved MCU blocking and such
- int w = (z->img_comp[n].x+7) >> 3;
- int h = (z->img_comp[n].y+7) >> 3;
- for (j=0; j < h; ++j) {
- for (i=0; i < w; ++i) {
- int ha = z->img_comp[n].ha;
- if (!stbi__jpeg_decode_block(z, data, z->huff_dc+z->img_comp[n].hd, z->huff_ac+ha, z->fast_ac[ha], n, z->dequant[z->img_comp[n].tq])) return 0;
- z->idct_block_kernel(z->img_comp[n].data+z->img_comp[n].w2*j*8+i*8, z->img_comp[n].w2, data);
- // every data block is an MCU, so countdown the restart interval
- if (--z->todo <= 0) {
- if (z->code_bits < 24) stbi__grow_buffer_unsafe(z);
- // if it's NOT a restart, then just bail, so we get corrupt data
- // rather than no data
- if (!STBI__RESTART(z->marker)) return 1;
- stbi__jpeg_reset(z);
- }
+ stbi__jpeg_reset(z);
+ if (!z->progressive)
+ {
+ if (z->scan_n == 1)
+ {
+ int i, j;
+ STBI_SIMD_ALIGN(short, data[64]);
+ int n = z->order[0];
+ // non-interleaved data, we just need to process one block at a time,
+ // in trivial scanline order
+ // number of blocks to do just depends on how many actual "pixels" this
+ // component has, independent of interleaved MCU blocking and such
+ int w = (z->img_comp[n].x + 7) >> 3;
+ int h = (z->img_comp[n].y + 7) >> 3;
+ for (j = 0; j < h; ++j)
+ {
+ for (i = 0; i < w; ++i)
+ {
+ int ha = z->img_comp[n].ha;
+ if (!stbi__jpeg_decode_block(z, data, z->huff_dc + z->img_comp[n].hd, z->huff_ac + ha, z->fast_ac[ha], n, z->dequant[z->img_comp[n].tq])) return 0;
+ z->idct_block_kernel(z->img_comp[n].data + z->img_comp[n].w2 * j * 8 + i * 8, z->img_comp[n].w2, data);
+ // every data block is an MCU, so countdown the restart interval
+ if (--z->todo <= 0)
+ {
+ if (z->code_bits < 24) stbi__grow_buffer_unsafe(z);
+ // if it's NOT a restart, then just bail, so we get corrupt data
+ // rather than no data
+ if (!STBI__RESTART(z->marker)) return 1;
+ stbi__jpeg_reset(z);
+ }
+ }
}
- }
- return 1;
- } else { // interleaved
- int i,j,k,x,y;
- STBI_SIMD_ALIGN(short, data[64]);
- for (j=0; j < z->img_mcu_y; ++j) {
- for (i=0; i < z->img_mcu_x; ++i) {
- // scan an interleaved mcu... process scan_n components in order
- for (k=0; k < z->scan_n; ++k) {
- int n = z->order[k];
- // scan out an mcu's worth of this component; that's just determined
- // by the basic H and V specified for the component
- for (y=0; y < z->img_comp[n].v; ++y) {
- for (x=0; x < z->img_comp[n].h; ++x) {
- int x2 = (i*z->img_comp[n].h + x)*8;
- int y2 = (j*z->img_comp[n].v + y)*8;
- int ha = z->img_comp[n].ha;
- if (!stbi__jpeg_decode_block(z, data, z->huff_dc+z->img_comp[n].hd, z->huff_ac+ha, z->fast_ac[ha], n, z->dequant[z->img_comp[n].tq])) return 0;
- z->idct_block_kernel(z->img_comp[n].data+z->img_comp[n].w2*y2+x2, z->img_comp[n].w2, data);
- }
- }
- }
- // after all interleaved components, that's an interleaved MCU,
- // so now count down the restart interval
- if (--z->todo <= 0) {
- if (z->code_bits < 24) stbi__grow_buffer_unsafe(z);
- if (!STBI__RESTART(z->marker)) return 1;
- stbi__jpeg_reset(z);
- }
+ return 1;
+ }
+ else
+ { // interleaved
+ int i, j, k, x, y;
+ STBI_SIMD_ALIGN(short, data[64]);
+ for (j = 0; j < z->img_mcu_y; ++j)
+ {
+ for (i = 0; i < z->img_mcu_x; ++i)
+ {
+ // scan an interleaved mcu... process scan_n components in order
+ for (k = 0; k < z->scan_n; ++k)
+ {
+ int n = z->order[k];
+ // scan out an mcu's worth of this component; that's just determined
+ // by the basic H and V specified for the component
+ for (y = 0; y < z->img_comp[n].v; ++y)
+ {
+ for (x = 0; x < z->img_comp[n].h; ++x)
+ {
+ int x2 = (i * z->img_comp[n].h + x) * 8;
+ int y2 = (j * z->img_comp[n].v + y) * 8;
+ int ha = z->img_comp[n].ha;
+ if (!stbi__jpeg_decode_block(z, data, z->huff_dc + z->img_comp[n].hd, z->huff_ac + ha, z->fast_ac[ha], n, z->dequant[z->img_comp[n].tq])) return 0;
+ z->idct_block_kernel(z->img_comp[n].data + z->img_comp[n].w2 * y2 + x2, z->img_comp[n].w2, data);
+ }
+ }
+ }
+ // after all interleaved components, that's an interleaved MCU,
+ // so now count down the restart interval
+ if (--z->todo <= 0)
+ {
+ if (z->code_bits < 24) stbi__grow_buffer_unsafe(z);
+ if (!STBI__RESTART(z->marker)) return 1;
+ stbi__jpeg_reset(z);
+ }
+ }
}
- }
- return 1;
- }
- } else {
- if (z->scan_n == 1) {
- int i,j;
- int n = z->order[0];
- // non-interleaved data, we just need to process one block at a time,
- // in trivial scanline order
- // number of blocks to do just depends on how many actual "pixels" this
- // component has, independent of interleaved MCU blocking and such
- int w = (z->img_comp[n].x+7) >> 3;
- int h = (z->img_comp[n].y+7) >> 3;
- for (j=0; j < h; ++j) {
- for (i=0; i < w; ++i) {
- short *data = z->img_comp[n].coeff + 64 * (i + j * z->img_comp[n].coeff_w);
- if (z->spec_start == 0) {
- if (!stbi__jpeg_decode_block_prog_dc(z, data, &z->huff_dc[z->img_comp[n].hd], n))
- return 0;
- } else {
- int ha = z->img_comp[n].ha;
- if (!stbi__jpeg_decode_block_prog_ac(z, data, &z->huff_ac[ha], z->fast_ac[ha]))
- return 0;
- }
- // every data block is an MCU, so countdown the restart interval
- if (--z->todo <= 0) {
- if (z->code_bits < 24) stbi__grow_buffer_unsafe(z);
- if (!STBI__RESTART(z->marker)) return 1;
- stbi__jpeg_reset(z);
- }
- }
- }
- return 1;
- } else { // interleaved
- int i,j,k,x,y;
- for (j=0; j < z->img_mcu_y; ++j) {
- for (i=0; i < z->img_mcu_x; ++i) {
- // scan an interleaved mcu... process scan_n components in order
- for (k=0; k < z->scan_n; ++k) {
- int n = z->order[k];
- // scan out an mcu's worth of this component; that's just determined
- // by the basic H and V specified for the component
- for (y=0; y < z->img_comp[n].v; ++y) {
- for (x=0; x < z->img_comp[n].h; ++x) {
- int x2 = (i*z->img_comp[n].h + x);
- int y2 = (j*z->img_comp[n].v + y);
- short *data = z->img_comp[n].coeff + 64 * (x2 + y2 * z->img_comp[n].coeff_w);
+ return 1;
+ }
+ }
+ else
+ {
+ if (z->scan_n == 1)
+ {
+ int i, j;
+ int n = z->order[0];
+ // non-interleaved data, we just need to process one block at a time,
+ // in trivial scanline order
+ // number of blocks to do just depends on how many actual "pixels" this
+ // component has, independent of interleaved MCU blocking and such
+ int w = (z->img_comp[n].x + 7) >> 3;
+ int h = (z->img_comp[n].y + 7) >> 3;
+ for (j = 0; j < h; ++j)
+ {
+ for (i = 0; i < w; ++i)
+ {
+ short *data = z->img_comp[n].coeff + 64 * (i + j * z->img_comp[n].coeff_w);
+ if (z->spec_start == 0)
+ {
if (!stbi__jpeg_decode_block_prog_dc(z, data, &z->huff_dc[z->img_comp[n].hd], n))
- return 0;
- }
- }
- }
- // after all interleaved components, that's an interleaved MCU,
- // so now count down the restart interval
- if (--z->todo <= 0) {
- if (z->code_bits < 24) stbi__grow_buffer_unsafe(z);
- if (!STBI__RESTART(z->marker)) return 1;
- stbi__jpeg_reset(z);
- }
+ return 0;
+ }
+ else
+ {
+ int ha = z->img_comp[n].ha;
+ if (!stbi__jpeg_decode_block_prog_ac(z, data, &z->huff_ac[ha], z->fast_ac[ha]))
+ return 0;
+ }
+ // every data block is an MCU, so countdown the restart interval
+ if (--z->todo <= 0)
+ {
+ if (z->code_bits < 24) stbi__grow_buffer_unsafe(z);
+ if (!STBI__RESTART(z->marker)) return 1;
+ stbi__jpeg_reset(z);
+ }
+ }
}
- }
- return 1;
- }
- }
+ return 1;
+ }
+ else
+ { // interleaved
+ int i, j, k, x, y;
+ for (j = 0; j < z->img_mcu_y; ++j)
+ {
+ for (i = 0; i < z->img_mcu_x; ++i)
+ {
+ // scan an interleaved mcu... process scan_n components in order
+ for (k = 0; k < z->scan_n; ++k)
+ {
+ int n = z->order[k];
+ // scan out an mcu's worth of this component; that's just determined
+ // by the basic H and V specified for the component
+ for (y = 0; y < z->img_comp[n].v; ++y)
+ {
+ for (x = 0; x < z->img_comp[n].h; ++x)
+ {
+ int x2 = i * z->img_comp[n].h + x;
+ int y2 = j * z->img_comp[n].v + y;
+ short *data = z->img_comp[n].coeff + 64 * (x2 + y2 * z->img_comp[n].coeff_w);
+ if (!stbi__jpeg_decode_block_prog_dc(z, data, &z->huff_dc[z->img_comp[n].hd], n))
+ return 0;
+ }
+ }
+ }
+ // after all interleaved components, that's an interleaved MCU,
+ // so now count down the restart interval
+ if (--z->todo <= 0)
+ {
+ if (z->code_bits < 24) stbi__grow_buffer_unsafe(z);
+ if (!STBI__RESTART(z->marker)) return 1;
+ stbi__jpeg_reset(z);
+ }
+ }
+ }
+ return 1;
+ }
+ }
}
static void stbi__jpeg_dequantize(short *data, stbi__uint16 *dequant)
{
- int i;
- for (i=0; i < 64; ++i)
- data[i] *= dequant[i];
+ int i;
+ for (i = 0; i < 64; ++i)
+ data[i] *= dequant[i];
}
static void stbi__jpeg_finish(stbi__jpeg *z)
{
- if (z->progressive) {
- // dequantize and idct the data
- int i,j,n;
- for (n=0; n < z->s->img_n; ++n) {
- int w = (z->img_comp[n].x+7) >> 3;
- int h = (z->img_comp[n].y+7) >> 3;
- for (j=0; j < h; ++j) {
- for (i=0; i < w; ++i) {
- short *data = z->img_comp[n].coeff + 64 * (i + j * z->img_comp[n].coeff_w);
- stbi__jpeg_dequantize(data, z->dequant[z->img_comp[n].tq]);
- z->idct_block_kernel(z->img_comp[n].data+z->img_comp[n].w2*j*8+i*8, z->img_comp[n].w2, data);
+ if (z->progressive)
+ {
+ // dequantize and idct the data
+ int i, j, n;
+ for (n = 0; n < z->s->img_n; ++n)
+ {
+ int w = (z->img_comp[n].x + 7) >> 3;
+ int h = (z->img_comp[n].y + 7) >> 3;
+ for (j = 0; j < h; ++j)
+ {
+ for (i = 0; i < w; ++i)
+ {
+ short *data = z->img_comp[n].coeff + 64 * (i + j * z->img_comp[n].coeff_w);
+ stbi__jpeg_dequantize(data, z->dequant[z->img_comp[n].tq]);
+ z->idct_block_kernel(z->img_comp[n].data + z->img_comp[n].w2 * j * 8 + i * 8, z->img_comp[n].w2, data);
+ }
}
- }
- }
- }
+ }
+ }
}
static int stbi__process_marker(stbi__jpeg *z, int m)
{
- int L;
- switch (m) {
- case STBI__MARKER_none: // no marker found
- return stbi__err("expected marker","Corrupt JPEG");
+ int L;
+ switch (m)
+ {
+ case STBI__MARKER_none: // no marker found
+ return stbi__err("expected marker", "Corrupt JPEG");
- case 0xDD: // DRI - specify restart interval
- if (stbi__get16be(z->s) != 4) return stbi__err("bad DRI len","Corrupt JPEG");
- z->restart_interval = stbi__get16be(z->s);
- return 1;
+ case 0xDD: // DRI - specify restart interval
+ if (stbi__get16be(z->s) != 4) return stbi__err("bad DRI len", "Corrupt JPEG");
+ z->restart_interval = stbi__get16be(z->s);
+ return 1;
- case 0xDB: // DQT - define quantization table
- L = stbi__get16be(z->s)-2;
- while (L > 0) {
- int q = stbi__get8(z->s);
- int p = q >> 4, sixteen = (p != 0);
- int t = q & 15,i;
- if (p != 0 && p != 1) return stbi__err("bad DQT type","Corrupt JPEG");
- if (t > 3) return stbi__err("bad DQT table","Corrupt JPEG");
+ case 0xDB: // DQT - define quantization table
+ L = stbi__get16be(z->s) - 2;
+ while (L > 0)
+ {
+ int q = stbi__get8(z->s);
+ int p = q >> 4, sixteen = p != 0;
+ int t = q & 15, i;
+ if (p != 0 && p != 1) return stbi__err("bad DQT type", "Corrupt JPEG");
+ if (t > 3) return stbi__err("bad DQT table", "Corrupt JPEG");
- for (i=0; i < 64; ++i)
- z->dequant[t][stbi__jpeg_dezigzag[i]] = (stbi__uint16)(sixteen ? stbi__get16be(z->s) : stbi__get8(z->s));
- L -= (sixteen ? 129 : 65);
- }
- return L==0;
-
- case 0xC4: // DHT - define huffman table
- L = stbi__get16be(z->s)-2;
- while (L > 0) {
- stbi_uc *v;
- int sizes[16],i,n=0;
- int q = stbi__get8(z->s);
- int tc = q >> 4;
- int th = q & 15;
- if (tc > 1 || th > 3) return stbi__err("bad DHT header","Corrupt JPEG");
- for (i=0; i < 16; ++i) {
- sizes[i] = stbi__get8(z->s);
- n += sizes[i];
+ for (i = 0; i < 64; ++i)
+ z->dequant[t][stbi__jpeg_dezigzag[i]] = (stbi__uint16)(sixteen ? stbi__get16be(z->s) : stbi__get8(z->s));
+ L -= sixteen ? 129 : 65;
}
- L -= 17;
- if (tc == 0) {
- if (!stbi__build_huffman(z->huff_dc+th, sizes)) return 0;
- v = z->huff_dc[th].values;
- } else {
- if (!stbi__build_huffman(z->huff_ac+th, sizes)) return 0;
- v = z->huff_ac[th].values;
+ return L == 0;
+
+ case 0xC4: // DHT - define huffman table
+ L = stbi__get16be(z->s) - 2;
+ while (L > 0)
+ {
+ stbi_uc *v;
+ int sizes[16], i, n = 0;
+ int q = stbi__get8(z->s);
+ int tc = q >> 4;
+ int th = q & 15;
+ if (tc > 1 || th > 3) return stbi__err("bad DHT header", "Corrupt JPEG");
+ for (i = 0; i < 16; ++i)
+ {
+ sizes[i] = stbi__get8(z->s);
+ n += sizes[i];
+ }
+ L -= 17;
+ if (tc == 0)
+ {
+ if (!stbi__build_huffman(z->huff_dc + th, sizes)) return 0;
+ v = z->huff_dc[th].values;
+ }
+ else
+ {
+ if (!stbi__build_huffman(z->huff_ac + th, sizes)) return 0;
+ v = z->huff_ac[th].values;
+ }
+ for (i = 0; i < n; ++i)
+ v[i] = stbi__get8(z->s);
+ if (tc != 0)
+ stbi__build_fast_ac(z->fast_ac[th], z->huff_ac + th);
+ L -= n;
}
- for (i=0; i < n; ++i)
- v[i] = stbi__get8(z->s);
- if (tc != 0)
- stbi__build_fast_ac(z->fast_ac[th], z->huff_ac + th);
- L -= n;
- }
- return L==0;
- }
+ return L == 0;
+ }
- // check for comment block or APP blocks
- if ((m >= 0xE0 && m <= 0xEF) || m == 0xFE) {
- L = stbi__get16be(z->s);
- if (L < 2) {
- if (m == 0xFE)
- return stbi__err("bad COM len","Corrupt JPEG");
- else
- return stbi__err("bad APP len","Corrupt JPEG");
- }
- L -= 2;
+ // check for comment block or APP blocks
+ if ((m >= 0xE0 && m <= 0xEF) || m == 0xFE)
+ {
+ L = stbi__get16be(z->s);
+ if (L < 2)
+ {
+ if (m == 0xFE)
+ return stbi__err("bad COM len", "Corrupt JPEG");
+ else
+ return stbi__err("bad APP len", "Corrupt JPEG");
+ }
+ L -= 2;
- if (m == 0xE0 && L >= 5) { // JFIF APP0 segment
- static const unsigned char tag[5] = {'J','F','I','F','\0'};
- int ok = 1;
- int i;
- for (i=0; i < 5; ++i)
- if (stbi__get8(z->s) != tag[i])
- ok = 0;
- L -= 5;
- if (ok)
- z->jfif = 1;
- } else if (m == 0xEE && L >= 12) { // Adobe APP14 segment
- static const unsigned char tag[6] = {'A','d','o','b','e','\0'};
- int ok = 1;
- int i;
- for (i=0; i < 6; ++i)
- if (stbi__get8(z->s) != tag[i])
- ok = 0;
- L -= 6;
- if (ok) {
- stbi__get8(z->s); // version
- stbi__get16be(z->s); // flags0
- stbi__get16be(z->s); // flags1
- z->app14_color_transform = stbi__get8(z->s); // color transform
+ if (m == 0xE0 && L >= 5)
+ { // JFIF APP0 segment
+ static const unsigned char tag[5] = {'J', 'F', 'I', 'F', '\0'};
+ int ok = 1;
+ int i;
+ for (i = 0; i < 5; ++i)
+ if (stbi__get8(z->s) != tag[i])
+ ok = 0;
+ L -= 5;
+ if (ok)
+ z->jfif = 1;
+ }
+ else if (m == 0xEE && L >= 12)
+ { // Adobe APP14 segment
+ static const unsigned char tag[6] = {'A', 'd', 'o', 'b', 'e', '\0'};
+ int ok = 1;
+ int i;
+ for (i = 0; i < 6; ++i)
+ if (stbi__get8(z->s) != tag[i])
+ ok = 0;
L -= 6;
- }
- }
+ if (ok)
+ {
+ stbi__get8(z->s); // version
+ stbi__get16be(z->s); // flags0
+ stbi__get16be(z->s); // flags1
+ z->app14_color_transform = stbi__get8(z->s); // color transform
+ L -= 6;
+ }
+ }
- stbi__skip(z->s, L);
- return 1;
- }
+ stbi__skip(z->s, L);
+ return 1;
+ }
- return stbi__err("unknown marker","Corrupt JPEG");
+ return stbi__err("unknown marker", "Corrupt JPEG");
}
// after we see SOS
static int stbi__process_scan_header(stbi__jpeg *z)
{
- int i;
- int Ls = stbi__get16be(z->s);
- z->scan_n = stbi__get8(z->s);
- if (z->scan_n < 1 || z->scan_n > 4 || z->scan_n > (int) z->s->img_n) return stbi__err("bad SOS component count","Corrupt JPEG");
- if (Ls != 6+2*z->scan_n) return stbi__err("bad SOS len","Corrupt JPEG");
- for (i=0; i < z->scan_n; ++i) {
- int id = stbi__get8(z->s), which;
- int q = stbi__get8(z->s);
- for (which = 0; which < z->s->img_n; ++which)
- if (z->img_comp[which].id == id)
- break;
- if (which == z->s->img_n) return 0; // no match
- z->img_comp[which].hd = q >> 4; if (z->img_comp[which].hd > 3) return stbi__err("bad DC huff","Corrupt JPEG");
- z->img_comp[which].ha = q & 15; if (z->img_comp[which].ha > 3) return stbi__err("bad AC huff","Corrupt JPEG");
- z->order[i] = which;
- }
+ int i;
+ int Ls = stbi__get16be(z->s);
+ z->scan_n = stbi__get8(z->s);
+ if (z->scan_n < 1 || z->scan_n > 4 || z->scan_n > z->s->img_n) return stbi__err("bad SOS component count", "Corrupt JPEG");
+ if (Ls != 6 + 2 * z->scan_n) return stbi__err("bad SOS len", "Corrupt JPEG");
+ for (i = 0; i < z->scan_n; ++i)
+ {
+ int id = stbi__get8(z->s), which;
+ int q = stbi__get8(z->s);
+ for (which = 0; which < z->s->img_n; ++which)
+ if (z->img_comp[which].id == id)
+ break;
+ if (which == z->s->img_n) return 0; // no match
+ z->img_comp[which].hd = q >> 4;
+ if (z->img_comp[which].hd > 3) return stbi__err("bad DC huff", "Corrupt JPEG");
+ z->img_comp[which].ha = q & 15;
+ if (z->img_comp[which].ha > 3) return stbi__err("bad AC huff", "Corrupt JPEG");
+ z->order[i] = which;
+ }
- {
- int aa;
- z->spec_start = stbi__get8(z->s);
- z->spec_end = stbi__get8(z->s); // should be 63, but might be 0
- aa = stbi__get8(z->s);
- z->succ_high = (aa >> 4);
- z->succ_low = (aa & 15);
- if (z->progressive) {
- if (z->spec_start > 63 || z->spec_end > 63 || z->spec_start > z->spec_end || z->succ_high > 13 || z->succ_low > 13)
- return stbi__err("bad SOS", "Corrupt JPEG");
- } else {
- if (z->spec_start != 0) return stbi__err("bad SOS","Corrupt JPEG");
- if (z->succ_high != 0 || z->succ_low != 0) return stbi__err("bad SOS","Corrupt JPEG");
- z->spec_end = 63;
- }
- }
+ {
+ int aa;
+ z->spec_start = stbi__get8(z->s);
+ z->spec_end = stbi__get8(z->s); // should be 63, but might be 0
+ aa = stbi__get8(z->s);
+ z->succ_high = aa >> 4;
+ z->succ_low = aa & 15;
+ if (z->progressive)
+ {
+ if (z->spec_start > 63 || z->spec_end > 63 || z->spec_start > z->spec_end || z->succ_high > 13 || z->succ_low > 13)
+ return stbi__err("bad SOS", "Corrupt JPEG");
+ }
+ else
+ {
+ if (z->spec_start != 0) return stbi__err("bad SOS", "Corrupt JPEG");
+ if (z->succ_high != 0 || z->succ_low != 0) return stbi__err("bad SOS", "Corrupt JPEG");
+ z->spec_end = 63;
+ }
+ }
- return 1;
+ return 1;
}
static int stbi__free_jpeg_components(stbi__jpeg *z, int ncomp, int why)
{
- int i;
- for (i=0; i < ncomp; ++i) {
- if (z->img_comp[i].raw_data) {
- STBI_FREE(z->img_comp[i].raw_data);
- z->img_comp[i].raw_data = NULL;
- z->img_comp[i].data = NULL;
- }
- if (z->img_comp[i].raw_coeff) {
- STBI_FREE(z->img_comp[i].raw_coeff);
- z->img_comp[i].raw_coeff = 0;
- z->img_comp[i].coeff = 0;
- }
- if (z->img_comp[i].linebuf) {
- STBI_FREE(z->img_comp[i].linebuf);
- z->img_comp[i].linebuf = NULL;
- }
- }
- return why;
+ int i;
+ for (i = 0; i < ncomp; ++i)
+ {
+ if (z->img_comp[i].raw_data)
+ {
+ STBI_FREE(z->img_comp[i].raw_data);
+ z->img_comp[i].raw_data = NULL;
+ z->img_comp[i].data = NULL;
+ }
+ if (z->img_comp[i].raw_coeff)
+ {
+ STBI_FREE(z->img_comp[i].raw_coeff);
+ z->img_comp[i].raw_coeff = 0;
+ z->img_comp[i].coeff = 0;
+ }
+ if (z->img_comp[i].linebuf)
+ {
+ STBI_FREE(z->img_comp[i].linebuf);
+ z->img_comp[i].linebuf = NULL;
+ }
+ }
+ return why;
}
static int stbi__process_frame_header(stbi__jpeg *z, int scan)
{
- stbi__context *s = z->s;
- int Lf,p,i,q, h_max=1,v_max=1,c;
- Lf = stbi__get16be(s); if (Lf < 11) return stbi__err("bad SOF len","Corrupt JPEG"); // JPEG
- p = stbi__get8(s); if (p != 8) return stbi__err("only 8-bit","JPEG format not supported: 8-bit only"); // JPEG baseline
- s->img_y = stbi__get16be(s); if (s->img_y == 0) return stbi__err("no header height", "JPEG format not supported: delayed height"); // Legal, but we don't handle it--but neither does IJG
- s->img_x = stbi__get16be(s); if (s->img_x == 0) return stbi__err("0 width","Corrupt JPEG"); // JPEG requires
- c = stbi__get8(s);
- if (c != 3 && c != 1 && c != 4) return stbi__err("bad component count","Corrupt JPEG");
- s->img_n = c;
- for (i=0; i < c; ++i) {
- z->img_comp[i].data = NULL;
- z->img_comp[i].linebuf = NULL;
- }
+ stbi__context *s = z->s;
+ int Lf, p, i, q, h_max = 1, v_max = 1, c;
+ Lf = stbi__get16be(s);
+ if (Lf < 11) return stbi__err("bad SOF len", "Corrupt JPEG"); // JPEG
+ p = stbi__get8(s);
+ if (p != 8) return stbi__err("only 8-bit", "JPEG format not supported: 8-bit only"); // JPEG baseline
+ s->img_y = stbi__get16be(s);
+ if (s->img_y == 0) return stbi__err("no header height", "JPEG format not supported: delayed height"); // Legal, but we don't handle it--but neither does IJG
+ s->img_x = stbi__get16be(s);
+ if (s->img_x == 0) return stbi__err("0 width", "Corrupt JPEG"); // JPEG requires
+ c = stbi__get8(s);
+ if (c != 3 && c != 1 && c != 4) return stbi__err("bad component count", "Corrupt JPEG");
+ s->img_n = c;
+ for (i = 0; i < c; ++i)
+ {
+ z->img_comp[i].data = NULL;
+ z->img_comp[i].linebuf = NULL;
+ }
- if (Lf != 8+3*s->img_n) return stbi__err("bad SOF len","Corrupt JPEG");
+ if (Lf != 8 + 3 * s->img_n) return stbi__err("bad SOF len", "Corrupt JPEG");
- z->rgb = 0;
- for (i=0; i < s->img_n; ++i) {
- static const unsigned char rgb[3] = { 'R', 'G', 'B' };
- z->img_comp[i].id = stbi__get8(s);
- if (s->img_n == 3 && z->img_comp[i].id == rgb[i])
- ++z->rgb;
- q = stbi__get8(s);
- z->img_comp[i].h = (q >> 4); if (!z->img_comp[i].h || z->img_comp[i].h > 4) return stbi__err("bad H","Corrupt JPEG");
- z->img_comp[i].v = q & 15; if (!z->img_comp[i].v || z->img_comp[i].v > 4) return stbi__err("bad V","Corrupt JPEG");
- z->img_comp[i].tq = stbi__get8(s); if (z->img_comp[i].tq > 3) return stbi__err("bad TQ","Corrupt JPEG");
- }
+ z->rgb = 0;
+ for (i = 0; i < s->img_n; ++i)
+ {
+ static const unsigned char rgb[3] = {'R', 'G', 'B'};
+ z->img_comp[i].id = stbi__get8(s);
+ if (s->img_n == 3 && z->img_comp[i].id == rgb[i])
+ ++z->rgb;
+ q = stbi__get8(s);
+ z->img_comp[i].h = q >> 4;
+ if (!z->img_comp[i].h || z->img_comp[i].h > 4) return stbi__err("bad H", "Corrupt JPEG");
+ z->img_comp[i].v = q & 15;
+ if (!z->img_comp[i].v || z->img_comp[i].v > 4) return stbi__err("bad V", "Corrupt JPEG");
+ z->img_comp[i].tq = stbi__get8(s);
+ if (z->img_comp[i].tq > 3) return stbi__err("bad TQ", "Corrupt JPEG");
+ }
- if (scan != STBI__SCAN_load) return 1;
+ if (scan != STBI__SCAN_load) return 1;
- if (!stbi__mad3sizes_valid(s->img_x, s->img_y, s->img_n, 0)) return stbi__err("too large", "Image too large to decode");
+ if (!stbi__mad3sizes_valid(s->img_x, s->img_y, s->img_n, 0)) return stbi__err("too large", "Image too large to decode");
- for (i=0; i < s->img_n; ++i) {
- if (z->img_comp[i].h > h_max) h_max = z->img_comp[i].h;
- if (z->img_comp[i].v > v_max) v_max = z->img_comp[i].v;
- }
+ for (i = 0; i < s->img_n; ++i)
+ {
+ if (z->img_comp[i].h > h_max) h_max = z->img_comp[i].h;
+ if (z->img_comp[i].v > v_max) v_max = z->img_comp[i].v;
+ }
- // compute interleaved mcu info
- z->img_h_max = h_max;
- z->img_v_max = v_max;
- z->img_mcu_w = h_max * 8;
- z->img_mcu_h = v_max * 8;
- // these sizes can't be more than 17 bits
- z->img_mcu_x = (s->img_x + z->img_mcu_w-1) / z->img_mcu_w;
- z->img_mcu_y = (s->img_y + z->img_mcu_h-1) / z->img_mcu_h;
+ // compute interleaved mcu info
+ z->img_h_max = h_max;
+ z->img_v_max = v_max;
+ z->img_mcu_w = h_max * 8;
+ z->img_mcu_h = v_max * 8;
+ // these sizes can't be more than 17 bits
+ z->img_mcu_x = (s->img_x + z->img_mcu_w - 1) / z->img_mcu_w;
+ z->img_mcu_y = (s->img_y + z->img_mcu_h - 1) / z->img_mcu_h;
- for (i=0; i < s->img_n; ++i) {
- // number of effective pixels (e.g. for non-interleaved MCU)
- z->img_comp[i].x = (s->img_x * z->img_comp[i].h + h_max-1) / h_max;
- z->img_comp[i].y = (s->img_y * z->img_comp[i].v + v_max-1) / v_max;
- // to simplify generation, we'll allocate enough memory to decode
- // the bogus oversized data from using interleaved MCUs and their
- // big blocks (e.g. a 16x16 iMCU on an image of width 33); we won't
- // discard the extra data until colorspace conversion
- //
- // img_mcu_x, img_mcu_y: <=17 bits; comp[i].h and .v are <=4 (checked earlier)
- // so these muls can't overflow with 32-bit ints (which we require)
- z->img_comp[i].w2 = z->img_mcu_x * z->img_comp[i].h * 8;
- z->img_comp[i].h2 = z->img_mcu_y * z->img_comp[i].v * 8;
- z->img_comp[i].coeff = 0;
- z->img_comp[i].raw_coeff = 0;
- z->img_comp[i].linebuf = NULL;
- z->img_comp[i].raw_data = stbi__malloc_mad2(z->img_comp[i].w2, z->img_comp[i].h2, 15);
- if (z->img_comp[i].raw_data == NULL)
- return stbi__free_jpeg_components(z, i+1, stbi__err("outofmem", "Out of memory"));
- // align blocks for idct using mmx/sse
- z->img_comp[i].data = (stbi_uc*) (((size_t) z->img_comp[i].raw_data + 15) & ~15);
- if (z->progressive) {
- // w2, h2 are multiples of 8 (see above)
- z->img_comp[i].coeff_w = z->img_comp[i].w2 / 8;
- z->img_comp[i].coeff_h = z->img_comp[i].h2 / 8;
- z->img_comp[i].raw_coeff = stbi__malloc_mad3(z->img_comp[i].w2, z->img_comp[i].h2, sizeof(short), 15);
- if (z->img_comp[i].raw_coeff == NULL)
- return stbi__free_jpeg_components(z, i+1, stbi__err("outofmem", "Out of memory"));
- z->img_comp[i].coeff = (short*) (((size_t) z->img_comp[i].raw_coeff + 15) & ~15);
- }
- }
+ for (i = 0; i < s->img_n; ++i)
+ {
+ // number of effective pixels (e.g. for non-interleaved MCU)
+ z->img_comp[i].x = (s->img_x * z->img_comp[i].h + h_max - 1) / h_max;
+ z->img_comp[i].y = (s->img_y * z->img_comp[i].v + v_max - 1) / v_max;
+ // to simplify generation, we'll allocate enough memory to decode
+ // the bogus oversized data from using interleaved MCUs and their
+ // big blocks (e.g. a 16x16 iMCU on an image of width 33); we won't
+ // discard the extra data until colorspace conversion
+ //
+ // img_mcu_x, img_mcu_y: <=17 bits; comp[i].h and .v are <=4 (checked earlier)
+ // so these muls can't overflow with 32-bit ints (which we require)
+ z->img_comp[i].w2 = z->img_mcu_x * z->img_comp[i].h * 8;
+ z->img_comp[i].h2 = z->img_mcu_y * z->img_comp[i].v * 8;
+ z->img_comp[i].coeff = 0;
+ z->img_comp[i].raw_coeff = 0;
+ z->img_comp[i].linebuf = NULL;
+ z->img_comp[i].raw_data = stbi__malloc_mad2(z->img_comp[i].w2, z->img_comp[i].h2, 15);
+ if (z->img_comp[i].raw_data == NULL)
+ return stbi__free_jpeg_components(z, i + 1, stbi__err("outofmem", "Out of memory"));
+ // align blocks for idct using mmx/sse
+ z->img_comp[i].data = (stbi_uc *)((size_t)z->img_comp[i].raw_data + 15 & ~15);
+ if (z->progressive)
+ {
+ // w2, h2 are multiples of 8 (see above)
+ z->img_comp[i].coeff_w = z->img_comp[i].w2 / 8;
+ z->img_comp[i].coeff_h = z->img_comp[i].h2 / 8;
+ z->img_comp[i].raw_coeff = stbi__malloc_mad3(z->img_comp[i].w2, z->img_comp[i].h2, sizeof(short), 15);
+ if (z->img_comp[i].raw_coeff == NULL)
+ return stbi__free_jpeg_components(z, i + 1, stbi__err("outofmem", "Out of memory"));
+ z->img_comp[i].coeff = (short *)((size_t)z->img_comp[i].raw_coeff + 15 & ~15);
+ }
+ }
- return 1;
+ return 1;
}
// use comparisons since in some cases we handle more than one case (e.g. SOF)
@@ -3091,688 +3432,787 @@ static int stbi__process_frame_header(stbi__jpeg *z, int scan)
static int stbi__decode_jpeg_header(stbi__jpeg *z, int scan)
{
- int m;
- z->jfif = 0;
- z->app14_color_transform = -1; // valid values are 0,1,2
- z->marker = STBI__MARKER_none; // initialize cached marker to empty
- m = stbi__get_marker(z);
- if (!stbi__SOI(m)) return stbi__err("no SOI","Corrupt JPEG");
- if (scan == STBI__SCAN_type) return 1;
- m = stbi__get_marker(z);
- while (!stbi__SOF(m)) {
- if (!stbi__process_marker(z,m)) return 0;
- m = stbi__get_marker(z);
- while (m == STBI__MARKER_none) {
- // some files have extra padding after their blocks, so ok, we'll scan
- if (stbi__at_eof(z->s)) return stbi__err("no SOF", "Corrupt JPEG");
- m = stbi__get_marker(z);
- }
- }
- z->progressive = stbi__SOF_progressive(m);
- if (!stbi__process_frame_header(z, scan)) return 0;
- return 1;
+ int m;
+ z->jfif = 0;
+ z->app14_color_transform = -1; // valid values are 0,1,2
+ z->marker = STBI__MARKER_none; // initialize cached marker to empty
+ m = stbi__get_marker(z);
+ if (!stbi__SOI(m)) return stbi__err("no SOI", "Corrupt JPEG");
+ if (scan == STBI__SCAN_type) return 1;
+ m = stbi__get_marker(z);
+ while (!stbi__SOF(m))
+ {
+ if (!stbi__process_marker(z, m)) return 0;
+ m = stbi__get_marker(z);
+ while (m == STBI__MARKER_none)
+ {
+ // some files have extra padding after their blocks, so ok, we'll scan
+ if (stbi__at_eof(z->s)) return stbi__err("no SOF", "Corrupt JPEG");
+ m = stbi__get_marker(z);
+ }
+ }
+ z->progressive = stbi__SOF_progressive(m);
+ if (!stbi__process_frame_header(z, scan)) return 0;
+ return 1;
}
// decode image to YCbCr format
static int stbi__decode_jpeg_image(stbi__jpeg *j)
{
- int m;
- for (m = 0; m < 4; m++) {
- j->img_comp[m].raw_data = NULL;
- j->img_comp[m].raw_coeff = NULL;
- }
- j->restart_interval = 0;
- if (!stbi__decode_jpeg_header(j, STBI__SCAN_load)) return 0;
- m = stbi__get_marker(j);
- while (!stbi__EOI(m)) {
- if (stbi__SOS(m)) {
- if (!stbi__process_scan_header(j)) return 0;
- if (!stbi__parse_entropy_coded_data(j)) return 0;
- if (j->marker == STBI__MARKER_none ) {
- // handle 0s at the end of image data from IP Kamera 9060
- while (!stbi__at_eof(j->s)) {
- int x = stbi__get8(j->s);
- if (x == 255) {
- j->marker = stbi__get8(j->s);
- break;
- }
+ int m;
+ for (m = 0; m < 4; m++)
+ {
+ j->img_comp[m].raw_data = NULL;
+ j->img_comp[m].raw_coeff = NULL;
+ }
+ j->restart_interval = 0;
+ if (!stbi__decode_jpeg_header(j, STBI__SCAN_load)) return 0;
+ m = stbi__get_marker(j);
+ while (!stbi__EOI(m))
+ {
+ if (stbi__SOS(m))
+ {
+ if (!stbi__process_scan_header(j)) return 0;
+ if (!stbi__parse_entropy_coded_data(j)) return 0;
+ if (j->marker == STBI__MARKER_none)
+ {
+ // handle 0s at the end of image data from IP Kamera 9060
+ while (!stbi__at_eof(j->s))
+ {
+ int x = stbi__get8(j->s);
+ if (x == 255)
+ {
+ j->marker = stbi__get8(j->s);
+ break;
+ }
+ }
+ // if we reach eof without hitting a marker, stbi__get_marker() below will fail and we'll eventually return 0
}
- // if we reach eof without hitting a marker, stbi__get_marker() below will fail and we'll eventually return 0
- }
- } else if (stbi__DNL(m)) {
- int Ld = stbi__get16be(j->s);
- stbi__uint32 NL = stbi__get16be(j->s);
- if (Ld != 4) return stbi__err("bad DNL len", "Corrupt JPEG");
- if (NL != j->s->img_y) return stbi__err("bad DNL height", "Corrupt JPEG");
- } else {
- if (!stbi__process_marker(j, m)) return 0;
- }
- m = stbi__get_marker(j);
- }
- if (j->progressive)
- stbi__jpeg_finish(j);
- return 1;
+ }
+ else if (stbi__DNL(m))
+ {
+ int Ld = stbi__get16be(j->s);
+ stbi__uint32 NL = stbi__get16be(j->s);
+ if (Ld != 4) return stbi__err("bad DNL len", "Corrupt JPEG");
+ if (NL != j->s->img_y) return stbi__err("bad DNL height", "Corrupt JPEG");
+ }
+ else
+ {
+ if (!stbi__process_marker(j, m)) return 0;
+ }
+ m = stbi__get_marker(j);
+ }
+ if (j->progressive)
+ stbi__jpeg_finish(j);
+ return 1;
}
// static jfif-centered resampling (across block boundaries)
-typedef stbi_uc *(*resample_row_func)(stbi_uc *out, stbi_uc *in0, stbi_uc *in1,
- int w, int hs);
+typedef stbi_uc *(*resample_row_func)(
+ stbi_uc *out, stbi_uc *in0, stbi_uc *in1,
+ int w, int hs);
#define stbi__div4(x) ((stbi_uc) ((x) >> 2))
static stbi_uc *resample_row_1(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs)
{
- STBI_NOTUSED(out);
- STBI_NOTUSED(in_far);
- STBI_NOTUSED(w);
- STBI_NOTUSED(hs);
- return in_near;
+ STBI_NOTUSED(out);
+ STBI_NOTUSED(in_far);
+ STBI_NOTUSED(w);
+ STBI_NOTUSED(hs);
+ return in_near;
}
-static stbi_uc* stbi__resample_row_v_2(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs)
+static stbi_uc *stbi__resample_row_v_2(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs)
{
- // need to generate two samples vertically for every one in input
- int i;
- STBI_NOTUSED(hs);
- for (i=0; i < w; ++i)
- out[i] = stbi__div4(3*in_near[i] + in_far[i] + 2);
- return out;
+ // need to generate two samples vertically for every one in input
+ int i;
+ STBI_NOTUSED(hs);
+ for (i = 0; i < w; ++i)
+ out[i] = stbi__div4(3 * in_near[i] + in_far[i] + 2);
+ return out;
}
-static stbi_uc* stbi__resample_row_h_2(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs)
+static stbi_uc *stbi__resample_row_h_2(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs)
{
- // need to generate two samples horizontally for every one in input
- int i;
- stbi_uc *input = in_near;
+ // need to generate two samples horizontally for every one in input
+ int i;
+ stbi_uc *input = in_near;
- if (w == 1) {
- // if only one sample, can't do any interpolation
- out[0] = out[1] = input[0];
- return out;
- }
+ if (w == 1)
+ {
+ // if only one sample, can't do any interpolation
+ out[0] = out[1] = input[0];
+ return out;
+ }
- out[0] = input[0];
- out[1] = stbi__div4(input[0]*3 + input[1] + 2);
- for (i=1; i < w-1; ++i) {
- int n = 3*input[i]+2;
- out[i*2+0] = stbi__div4(n+input[i-1]);
- out[i*2+1] = stbi__div4(n+input[i+1]);
- }
- out[i*2+0] = stbi__div4(input[w-2]*3 + input[w-1] + 2);
- out[i*2+1] = input[w-1];
+ out[0] = input[0];
+ out[1] = stbi__div4(input[0] * 3 + input[1] + 2);
+ for (i = 1; i < w - 1; ++i)
+ {
+ int n = 3 * input[i] + 2;
+ out[i * 2 + 0] = stbi__div4(n + input[i - 1]);
+ out[i * 2 + 1] = stbi__div4(n + input[i + 1]);
+ }
+ out[i * 2 + 0] = stbi__div4(input[w - 2] * 3 + input[w - 1] + 2);
+ out[i * 2 + 1] = input[w - 1];
- STBI_NOTUSED(in_far);
- STBI_NOTUSED(hs);
+ STBI_NOTUSED(in_far);
+ STBI_NOTUSED(hs);
- return out;
+ return out;
}
#define stbi__div16(x) ((stbi_uc) ((x) >> 4))
static stbi_uc *stbi__resample_row_hv_2(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs)
{
- // need to generate 2x2 samples for every one in input
- int i,t0,t1;
- if (w == 1) {
- out[0] = out[1] = stbi__div4(3*in_near[0] + in_far[0] + 2);
- return out;
- }
+ // need to generate 2x2 samples for every one in input
+ int i, t0, t1;
+ if (w == 1)
+ {
+ out[0] = out[1] = stbi__div4(3 * in_near[0] + in_far[0] + 2);
+ return out;
+ }
- t1 = 3*in_near[0] + in_far[0];
- out[0] = stbi__div4(t1+2);
- for (i=1; i < w; ++i) {
- t0 = t1;
- t1 = 3*in_near[i]+in_far[i];
- out[i*2-1] = stbi__div16(3*t0 + t1 + 8);
- out[i*2 ] = stbi__div16(3*t1 + t0 + 8);
- }
- out[w*2-1] = stbi__div4(t1+2);
+ t1 = 3 * in_near[0] + in_far[0];
+ out[0] = stbi__div4(t1 + 2);
+ for (i = 1; i < w; ++i)
+ {
+ t0 = t1;
+ t1 = 3 * in_near[i] + in_far[i];
+ out[i * 2 - 1] = stbi__div16(3 * t0 + t1 + 8);
+ out[i * 2] = stbi__div16(3 * t1 + t0 + 8);
+ }
+ out[w * 2 - 1] = stbi__div4(t1 + 2);
- STBI_NOTUSED(hs);
+ STBI_NOTUSED(hs);
- return out;
+ return out;
}
#if defined(STBI_SSE2) || defined(STBI_NEON)
static stbi_uc *stbi__resample_row_hv_2_simd(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs)
{
- // need to generate 2x2 samples for every one in input
- int i=0,t0,t1;
+ // need to generate 2x2 samples for every one in input
+ int i = 0, t0, t1;
- if (w == 1) {
- out[0] = out[1] = stbi__div4(3*in_near[0] + in_far[0] + 2);
- return out;
- }
+ if (w == 1)
+ {
+ out[0] = out[1] = stbi__div4(3 * in_near[0] + in_far[0] + 2);
+ return out;
+ }
- t1 = 3*in_near[0] + in_far[0];
- // process groups of 8 pixels for as long as we can.
- // note we can't handle the last pixel in a row in this loop
- // because we need to handle the filter boundary conditions.
- for (; i < ((w-1) & ~7); i += 8) {
-#if defined(STBI_SSE2)
- // load and perform the vertical filtering pass
- // this uses 3*x + y = 4*x + (y - x)
- __m128i zero = _mm_setzero_si128();
- __m128i farb = _mm_loadl_epi64((__m128i *) (in_far + i));
- __m128i nearb = _mm_loadl_epi64((__m128i *) (in_near + i));
- __m128i farw = _mm_unpacklo_epi8(farb, zero);
- __m128i nearw = _mm_unpacklo_epi8(nearb, zero);
- __m128i diff = _mm_sub_epi16(farw, nearw);
- __m128i nears = _mm_slli_epi16(nearw, 2);
- __m128i curr = _mm_add_epi16(nears, diff); // current row
+ t1 = 3 * in_near[0] + in_far[0];
+ // process groups of 8 pixels for as long as we can.
+ // note we can't handle the last pixel in a row in this loop
+ // because we need to handle the filter boundary conditions.
+ for (; i < (w - 1 & ~7); i += 8)
+ {
+ #if defined(STBI_SSE2)
+ // load and perform the vertical filtering pass
+ // this uses 3*x + y = 4*x + (y - x)
+ __m128i zero = _mm_setzero_si128();
+ __m128i farb = _mm_loadl_epi64((__m128i *)(in_far + i));
+ __m128i nearb = _mm_loadl_epi64((__m128i *)(in_near + i));
+ __m128i farw = _mm_unpacklo_epi8(farb, zero);
+ __m128i nearw = _mm_unpacklo_epi8(nearb, zero);
+ __m128i diff = _mm_sub_epi16(farw, nearw);
+ __m128i nears = _mm_slli_epi16(nearw, 2);
+ __m128i curr = _mm_add_epi16(nears, diff); // current row
- // horizontal filter works the same based on shifted vers of current
- // row. "prev" is current row shifted right by 1 pixel; we need to
- // insert the previous pixel value (from t1).
- // "next" is current row shifted left by 1 pixel, with first pixel
- // of next block of 8 pixels added in.
- __m128i prv0 = _mm_slli_si128(curr, 2);
- __m128i nxt0 = _mm_srli_si128(curr, 2);
- __m128i prev = _mm_insert_epi16(prv0, t1, 0);
- __m128i next = _mm_insert_epi16(nxt0, 3*in_near[i+8] + in_far[i+8], 7);
+ // horizontal filter works the same based on shifted vers of current
+ // row. "prev" is current row shifted right by 1 pixel; we need to
+ // insert the previous pixel value (from t1).
+ // "next" is current row shifted left by 1 pixel, with first pixel
+ // of next block of 8 pixels added in.
+ __m128i prv0 = _mm_slli_si128(curr, 2);
+ __m128i nxt0 = _mm_srli_si128(curr, 2);
+ __m128i prev = _mm_insert_epi16(prv0, t1, 0);
+ __m128i next = _mm_insert_epi16(nxt0, 3 * in_near[i + 8] + in_far[i + 8], 7);
- // horizontal filter, polyphase implementation since it's convenient:
- // even pixels = 3*cur + prev = cur*4 + (prev - cur)
- // odd pixels = 3*cur + next = cur*4 + (next - cur)
- // note the shared term.
- __m128i bias = _mm_set1_epi16(8);
- __m128i curs = _mm_slli_epi16(curr, 2);
- __m128i prvd = _mm_sub_epi16(prev, curr);
- __m128i nxtd = _mm_sub_epi16(next, curr);
- __m128i curb = _mm_add_epi16(curs, bias);
- __m128i even = _mm_add_epi16(prvd, curb);
- __m128i odd = _mm_add_epi16(nxtd, curb);
+ // horizontal filter, polyphase implementation since it's convenient:
+ // even pixels = 3*cur + prev = cur*4 + (prev - cur)
+ // odd pixels = 3*cur + next = cur*4 + (next - cur)
+ // note the shared term.
+ __m128i bias = _mm_set1_epi16(8);
+ __m128i curs = _mm_slli_epi16(curr, 2);
+ __m128i prvd = _mm_sub_epi16(prev, curr);
+ __m128i nxtd = _mm_sub_epi16(next, curr);
+ __m128i curb = _mm_add_epi16(curs, bias);
+ __m128i even = _mm_add_epi16(prvd, curb);
+ __m128i odd = _mm_add_epi16(nxtd, curb);
- // interleave even and odd pixels, then undo scaling.
- __m128i int0 = _mm_unpacklo_epi16(even, odd);
- __m128i int1 = _mm_unpackhi_epi16(even, odd);
- __m128i de0 = _mm_srli_epi16(int0, 4);
- __m128i de1 = _mm_srli_epi16(int1, 4);
+ // interleave even and odd pixels, then undo scaling.
+ __m128i int0 = _mm_unpacklo_epi16(even, odd);
+ __m128i int1 = _mm_unpackhi_epi16(even, odd);
+ __m128i de0 = _mm_srli_epi16(int0, 4);
+ __m128i de1 = _mm_srli_epi16(int1, 4);
- // pack and write output
- __m128i outv = _mm_packus_epi16(de0, de1);
- _mm_storeu_si128((__m128i *) (out + i*2), outv);
-#elif defined(STBI_NEON)
- // load and perform the vertical filtering pass
- // this uses 3*x + y = 4*x + (y - x)
- uint8x8_t farb = vld1_u8(in_far + i);
- uint8x8_t nearb = vld1_u8(in_near + i);
- int16x8_t diff = vreinterpretq_s16_u16(vsubl_u8(farb, nearb));
- int16x8_t nears = vreinterpretq_s16_u16(vshll_n_u8(nearb, 2));
- int16x8_t curr = vaddq_s16(nears, diff); // current row
+ // pack and write output
+ __m128i outv = _mm_packus_epi16(de0, de1);
+ _mm_storeu_si128((__m128i *)(out + i * 2), outv);
+ #elif defined(STBI_NEON)
+ // load and perform the vertical filtering pass
+ // this uses 3*x + y = 4*x + (y - x)
+ uint8x8_t farb = vld1_u8(in_far + i);
+ uint8x8_t nearb = vld1_u8(in_near + i);
+ int16x8_t diff = vreinterpretq_s16_u16(vsubl_u8(farb, nearb));
+ int16x8_t nears = vreinterpretq_s16_u16(vshll_n_u8(nearb, 2));
+ int16x8_t curr = vaddq_s16(nears, diff); // current row
- // horizontal filter works the same based on shifted vers of current
- // row. "prev" is current row shifted right by 1 pixel; we need to
- // insert the previous pixel value (from t1).
- // "next" is current row shifted left by 1 pixel, with first pixel
- // of next block of 8 pixels added in.
- int16x8_t prv0 = vextq_s16(curr, curr, 7);
- int16x8_t nxt0 = vextq_s16(curr, curr, 1);
- int16x8_t prev = vsetq_lane_s16(t1, prv0, 0);
- int16x8_t next = vsetq_lane_s16(3*in_near[i+8] + in_far[i+8], nxt0, 7);
+ // horizontal filter works the same based on shifted vers of current
+ // row. "prev" is current row shifted right by 1 pixel; we need to
+ // insert the previous pixel value (from t1).
+ // "next" is current row shifted left by 1 pixel, with first pixel
+ // of next block of 8 pixels added in.
+ int16x8_t prv0 = vextq_s16(curr, curr, 7);
+ int16x8_t nxt0 = vextq_s16(curr, curr, 1);
+ int16x8_t prev = vsetq_lane_s16(t1, prv0, 0);
+ int16x8_t next = vsetq_lane_s16(3 * in_near[i + 8] + in_far[i + 8], nxt0, 7);
- // horizontal filter, polyphase implementation since it's convenient:
- // even pixels = 3*cur + prev = cur*4 + (prev - cur)
- // odd pixels = 3*cur + next = cur*4 + (next - cur)
- // note the shared term.
- int16x8_t curs = vshlq_n_s16(curr, 2);
- int16x8_t prvd = vsubq_s16(prev, curr);
- int16x8_t nxtd = vsubq_s16(next, curr);
- int16x8_t even = vaddq_s16(curs, prvd);
- int16x8_t odd = vaddq_s16(curs, nxtd);
+ // horizontal filter, polyphase implementation since it's convenient:
+ // even pixels = 3*cur + prev = cur*4 + (prev - cur)
+ // odd pixels = 3*cur + next = cur*4 + (next - cur)
+ // note the shared term.
+ int16x8_t curs = vshlq_n_s16(curr, 2);
+ int16x8_t prvd = vsubq_s16(prev, curr);
+ int16x8_t nxtd = vsubq_s16(next, curr);
+ int16x8_t even = vaddq_s16(curs, prvd);
+ int16x8_t odd = vaddq_s16(curs, nxtd);
- // undo scaling and round, then store with even/odd phases interleaved
- uint8x8x2_t o;
- o.val[0] = vqrshrun_n_s16(even, 4);
- o.val[1] = vqrshrun_n_s16(odd, 4);
- vst2_u8(out + i*2, o);
-#endif
+ // undo scaling and round, then store with even/odd phases interleaved
+ uint8x8x2_t o;
+ o.val[0] = vqrshrun_n_s16(even, 4);
+ o.val[1] = vqrshrun_n_s16(odd, 4);
+ vst2_u8(out + i * 2, o);
+ #endif
- // "previous" value for next iter
- t1 = 3*in_near[i+7] + in_far[i+7];
- }
+ // "previous" value for next iter
+ t1 = 3 * in_near[i + 7] + in_far[i + 7];
+ }
- t0 = t1;
- t1 = 3*in_near[i] + in_far[i];
- out[i*2] = stbi__div16(3*t1 + t0 + 8);
+ t0 = t1;
+ t1 = 3 * in_near[i] + in_far[i];
+ out[i * 2] = stbi__div16(3*t1+ t0+ 8);
- for (++i; i < w; ++i) {
- t0 = t1;
- t1 = 3*in_near[i]+in_far[i];
- out[i*2-1] = stbi__div16(3*t0 + t1 + 8);
- out[i*2 ] = stbi__div16(3*t1 + t0 + 8);
- }
- out[w*2-1] = stbi__div4(t1+2);
+ for (++i; i < w; ++i)
+ {
+ t0 = t1;
+ t1 = 3 * in_near[i] + in_far[i];
+ out[i * 2 - 1] = stbi__div16(3*t0 + t1 + 8);
+ out[i * 2] = stbi__div16(3*t1 + t0 + 8);
+ }
+ out[w * 2 - 1] = stbi__div4(t1+2);
- STBI_NOTUSED(hs);
+ STBI_NOTUSED(hs);
- return out;
+ return out;
}
#endif
static stbi_uc *stbi__resample_row_generic(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs)
{
- // resample with nearest-neighbor
- int i,j;
- STBI_NOTUSED(in_far);
- for (i=0; i < w; ++i)
- for (j=0; j < hs; ++j)
- out[i*hs+j] = in_near[i];
- return out;
+ // resample with nearest-neighbor
+ int i, j;
+ STBI_NOTUSED(in_far);
+ for (i = 0; i < w; ++i)
+ for (j = 0; j < hs; ++j)
+ out[i * hs + j] = in_near[i];
+ return out;
}
// this is a reduced-precision calculation of YCbCr-to-RGB introduced
// to make sure the code produces the same results in both SIMD and scalar
#define stbi__float2fixed(x) (((int) ((x) * 4096.0f + 0.5f)) << 8)
+
static void stbi__YCbCr_to_RGB_row(stbi_uc *out, const stbi_uc *y, const stbi_uc *pcb, const stbi_uc *pcr, int count, int step)
{
- int i;
- for (i=0; i < count; ++i) {
- int y_fixed = (y[i] << 20) + (1<<19); // rounding
- int r,g,b;
- int cr = pcr[i] - 128;
- int cb = pcb[i] - 128;
- r = y_fixed + cr* stbi__float2fixed(1.40200f);
- g = y_fixed + (cr*-stbi__float2fixed(0.71414f)) + ((cb*-stbi__float2fixed(0.34414f)) & 0xffff0000);
- b = y_fixed + cb* stbi__float2fixed(1.77200f);
- r >>= 20;
- g >>= 20;
- b >>= 20;
- if ((unsigned) r > 255) { if (r < 0) r = 0; else r = 255; }
- if ((unsigned) g > 255) { if (g < 0) g = 0; else g = 255; }
- if ((unsigned) b > 255) { if (b < 0) b = 0; else b = 255; }
- out[0] = (stbi_uc)r;
- out[1] = (stbi_uc)g;
- out[2] = (stbi_uc)b;
- out[3] = 255;
- out += step;
- }
+ int i;
+ for (i = 0; i < count; ++i)
+ {
+ int y_fixed = (y[i] << 20) + (1 << 19); // rounding
+ int r, g, b;
+ int cr = pcr[i] - 128;
+ int cb = pcb[i] - 128;
+ r = y_fixed + cr * stbi__float2fixed(1.40200f);
+ g = y_fixed + cr * -stbi__float2fixed(0.71414f) + (cb * -stbi__float2fixed(0.34414f) & 0xffff0000);
+ b = y_fixed + cb * stbi__float2fixed(1.77200f);
+ r >>= 20;
+ g >>= 20;
+ b >>= 20;
+ if ((unsigned)r > 255)
+ {
+ if (r < 0) r = 0;
+ else r = 255;
+ }
+ if ((unsigned)g > 255)
+ {
+ if (g < 0) g = 0;
+ else g = 255;
+ }
+ if ((unsigned)b > 255)
+ {
+ if (b < 0) b = 0;
+ else b = 255;
+ }
+ out[0] = (stbi_uc)r;
+ out[1] = (stbi_uc)g;
+ out[2] = (stbi_uc)b;
+ out[3] = 255;
+ out += step;
+ }
}
#if defined(STBI_SSE2) || defined(STBI_NEON)
static void stbi__YCbCr_to_RGB_simd(stbi_uc *out, stbi_uc const *y, stbi_uc const *pcb, stbi_uc const *pcr, int count, int step)
{
- int i = 0;
+ int i = 0;
-#ifdef STBI_SSE2
- // step == 3 is pretty ugly on the final interleave, and i'm not convinced
- // it's useful in practice (you wouldn't use it for textures, for example).
- // so just accelerate step == 4 case.
- if (step == 4) {
- // this is a fairly straightforward implementation and not super-optimized.
- __m128i signflip = _mm_set1_epi8(-0x80);
- __m128i cr_const0 = _mm_set1_epi16( (short) ( 1.40200f*4096.0f+0.5f));
- __m128i cr_const1 = _mm_set1_epi16( - (short) ( 0.71414f*4096.0f+0.5f));
- __m128i cb_const0 = _mm_set1_epi16( - (short) ( 0.34414f*4096.0f+0.5f));
- __m128i cb_const1 = _mm_set1_epi16( (short) ( 1.77200f*4096.0f+0.5f));
- __m128i y_bias = _mm_set1_epi8((char) (unsigned char) 128);
- __m128i xw = _mm_set1_epi16(255); // alpha channel
+ #ifdef STBI_SSE2
+ // step == 3 is pretty ugly on the final interleave, and i'm not convinced
+ // it's useful in practice (you wouldn't use it for textures, for example).
+ // so just accelerate step == 4 case.
+ if (step == 4)
+ {
+ // this is a fairly straightforward implementation and not super-optimized.
+ __m128i signflip = _mm_set1_epi8(-0x80);
+ __m128i cr_const0 = _mm_set1_epi16((short)(1.40200f * 4096.0f + 0.5f));
+ __m128i cr_const1 = _mm_set1_epi16(-(short)(0.71414f * 4096.0f + 0.5f));
+ __m128i cb_const0 = _mm_set1_epi16(-(short)(0.34414f * 4096.0f + 0.5f));
+ __m128i cb_const1 = _mm_set1_epi16((short)(1.77200f * 4096.0f + 0.5f));
+ __m128i y_bias = _mm_set1_epi8((char)(unsigned char)128);
+ __m128i xw = _mm_set1_epi16(255); // alpha channel
- for (; i+7 < count; i += 8) {
- // load
- __m128i y_bytes = _mm_loadl_epi64((__m128i *) (y+i));
- __m128i cr_bytes = _mm_loadl_epi64((__m128i *) (pcr+i));
- __m128i cb_bytes = _mm_loadl_epi64((__m128i *) (pcb+i));
- __m128i cr_biased = _mm_xor_si128(cr_bytes, signflip); // -128
- __m128i cb_biased = _mm_xor_si128(cb_bytes, signflip); // -128
+ for (; i + 7 < count; i += 8)
+ {
+ // load
+ __m128i y_bytes = _mm_loadl_epi64((__m128i *)(y + i));
+ __m128i cr_bytes = _mm_loadl_epi64((__m128i *)(pcr + i));
+ __m128i cb_bytes = _mm_loadl_epi64((__m128i *)(pcb + i));
+ __m128i cr_biased = _mm_xor_si128(cr_bytes, signflip); // -128
+ __m128i cb_biased = _mm_xor_si128(cb_bytes, signflip); // -128
- // unpack to short (and left-shift cr, cb by 8)
- __m128i yw = _mm_unpacklo_epi8(y_bias, y_bytes);
- __m128i crw = _mm_unpacklo_epi8(_mm_setzero_si128(), cr_biased);
- __m128i cbw = _mm_unpacklo_epi8(_mm_setzero_si128(), cb_biased);
+ // unpack to short (and left-shift cr, cb by 8)
+ __m128i yw = _mm_unpacklo_epi8(y_bias, y_bytes);
+ __m128i crw = _mm_unpacklo_epi8(_mm_setzero_si128(), cr_biased);
+ __m128i cbw = _mm_unpacklo_epi8(_mm_setzero_si128(), cb_biased);
- // color transform
- __m128i yws = _mm_srli_epi16(yw, 4);
- __m128i cr0 = _mm_mulhi_epi16(cr_const0, crw);
- __m128i cb0 = _mm_mulhi_epi16(cb_const0, cbw);
- __m128i cb1 = _mm_mulhi_epi16(cbw, cb_const1);
- __m128i cr1 = _mm_mulhi_epi16(crw, cr_const1);
- __m128i rws = _mm_add_epi16(cr0, yws);
- __m128i gwt = _mm_add_epi16(cb0, yws);
- __m128i bws = _mm_add_epi16(yws, cb1);
- __m128i gws = _mm_add_epi16(gwt, cr1);
+ // color transform
+ __m128i yws = _mm_srli_epi16(yw, 4);
+ __m128i cr0 = _mm_mulhi_epi16(cr_const0, crw);
+ __m128i cb0 = _mm_mulhi_epi16(cb_const0, cbw);
+ __m128i cb1 = _mm_mulhi_epi16(cbw, cb_const1);
+ __m128i cr1 = _mm_mulhi_epi16(crw, cr_const1);
+ __m128i rws = _mm_add_epi16(cr0, yws);
+ __m128i gwt = _mm_add_epi16(cb0, yws);
+ __m128i bws = _mm_add_epi16(yws, cb1);
+ __m128i gws = _mm_add_epi16(gwt, cr1);
- // descale
- __m128i rw = _mm_srai_epi16(rws, 4);
- __m128i bw = _mm_srai_epi16(bws, 4);
- __m128i gw = _mm_srai_epi16(gws, 4);
+ // descale
+ __m128i rw = _mm_srai_epi16(rws, 4);
+ __m128i bw = _mm_srai_epi16(bws, 4);
+ __m128i gw = _mm_srai_epi16(gws, 4);
- // back to byte, set up for transpose
- __m128i brb = _mm_packus_epi16(rw, bw);
- __m128i gxb = _mm_packus_epi16(gw, xw);
+ // back to byte, set up for transpose
+ __m128i brb = _mm_packus_epi16(rw, bw);
+ __m128i gxb = _mm_packus_epi16(gw, xw);
- // transpose to interleave channels
- __m128i t0 = _mm_unpacklo_epi8(brb, gxb);
- __m128i t1 = _mm_unpackhi_epi8(brb, gxb);
- __m128i o0 = _mm_unpacklo_epi16(t0, t1);
- __m128i o1 = _mm_unpackhi_epi16(t0, t1);
+ // transpose to interleave channels
+ __m128i t0 = _mm_unpacklo_epi8(brb, gxb);
+ __m128i t1 = _mm_unpackhi_epi8(brb, gxb);
+ __m128i o0 = _mm_unpacklo_epi16(t0, t1);
+ __m128i o1 = _mm_unpackhi_epi16(t0, t1);
- // store
- _mm_storeu_si128((__m128i *) (out + 0), o0);
- _mm_storeu_si128((__m128i *) (out + 16), o1);
- out += 32;
- }
- }
-#endif
+ // store
+ _mm_storeu_si128((__m128i *)(out + 0), o0);
+ _mm_storeu_si128((__m128i *)(out + 16), o1);
+ out += 32;
+ }
+ }
+ #endif
-#ifdef STBI_NEON
- // in this version, step=3 support would be easy to add. but is there demand?
- if (step == 4) {
- // this is a fairly straightforward implementation and not super-optimized.
- uint8x8_t signflip = vdup_n_u8(0x80);
- int16x8_t cr_const0 = vdupq_n_s16( (short) ( 1.40200f*4096.0f+0.5f));
- int16x8_t cr_const1 = vdupq_n_s16( - (short) ( 0.71414f*4096.0f+0.5f));
- int16x8_t cb_const0 = vdupq_n_s16( - (short) ( 0.34414f*4096.0f+0.5f));
- int16x8_t cb_const1 = vdupq_n_s16( (short) ( 1.77200f*4096.0f+0.5f));
+ #ifdef STBI_NEON
+ // in this version, step=3 support would be easy to add. but is there demand?
+ if (step == 4)
+ {
+ // this is a fairly straightforward implementation and not super-optimized.
+ uint8x8_t signflip = vdup_n_u8(0x80);
+ int16x8_t cr_const0 = vdupq_n_s16((short)(1.40200f * 4096.0f + 0.5f));
+ int16x8_t cr_const1 = vdupq_n_s16(-(short)(0.71414f * 4096.0f + 0.5f));
+ int16x8_t cb_const0 = vdupq_n_s16(-(short)(0.34414f * 4096.0f + 0.5f));
+ int16x8_t cb_const1 = vdupq_n_s16((short)(1.77200f * 4096.0f + 0.5f));
- for (; i+7 < count; i += 8) {
- // load
- uint8x8_t y_bytes = vld1_u8(y + i);
- uint8x8_t cr_bytes = vld1_u8(pcr + i);
- uint8x8_t cb_bytes = vld1_u8(pcb + i);
- int8x8_t cr_biased = vreinterpret_s8_u8(vsub_u8(cr_bytes, signflip));
- int8x8_t cb_biased = vreinterpret_s8_u8(vsub_u8(cb_bytes, signflip));
+ for (; i + 7 < count; i += 8)
+ {
+ // load
+ uint8x8_t y_bytes = vld1_u8(y + i);
+ uint8x8_t cr_bytes = vld1_u8(pcr + i);
+ uint8x8_t cb_bytes = vld1_u8(pcb + i);
+ int8x8_t cr_biased = vreinterpret_s8_u8(vsub_u8(cr_bytes, signflip));
+ int8x8_t cb_biased = vreinterpret_s8_u8(vsub_u8(cb_bytes, signflip));
- // expand to s16
- int16x8_t yws = vreinterpretq_s16_u16(vshll_n_u8(y_bytes, 4));
- int16x8_t crw = vshll_n_s8(cr_biased, 7);
- int16x8_t cbw = vshll_n_s8(cb_biased, 7);
+ // expand to s16
+ int16x8_t yws = vreinterpretq_s16_u16(vshll_n_u8(y_bytes, 4));
+ int16x8_t crw = vshll_n_s8(cr_biased, 7);
+ int16x8_t cbw = vshll_n_s8(cb_biased, 7);
- // color transform
- int16x8_t cr0 = vqdmulhq_s16(crw, cr_const0);
- int16x8_t cb0 = vqdmulhq_s16(cbw, cb_const0);
- int16x8_t cr1 = vqdmulhq_s16(crw, cr_const1);
- int16x8_t cb1 = vqdmulhq_s16(cbw, cb_const1);
- int16x8_t rws = vaddq_s16(yws, cr0);
- int16x8_t gws = vaddq_s16(vaddq_s16(yws, cb0), cr1);
- int16x8_t bws = vaddq_s16(yws, cb1);
+ // color transform
+ int16x8_t cr0 = vqdmulhq_s16(crw, cr_const0);
+ int16x8_t cb0 = vqdmulhq_s16(cbw, cb_const0);
+ int16x8_t cr1 = vqdmulhq_s16(crw, cr_const1);
+ int16x8_t cb1 = vqdmulhq_s16(cbw, cb_const1);
+ int16x8_t rws = vaddq_s16(yws, cr0);
+ int16x8_t gws = vaddq_s16(vaddq_s16(yws, cb0), cr1);
+ int16x8_t bws = vaddq_s16(yws, cb1);
- // undo scaling, round, convert to byte
- uint8x8x4_t o;
- o.val[0] = vqrshrun_n_s16(rws, 4);
- o.val[1] = vqrshrun_n_s16(gws, 4);
- o.val[2] = vqrshrun_n_s16(bws, 4);
- o.val[3] = vdup_n_u8(255);
+ // undo scaling, round, convert to byte
+ uint8x8x4_t o;
+ o.val[0] = vqrshrun_n_s16(rws, 4);
+ o.val[1] = vqrshrun_n_s16(gws, 4);
+ o.val[2] = vqrshrun_n_s16(bws, 4);
+ o.val[3] = vdup_n_u8(255);
- // store, interleaving r/g/b/a
- vst4_u8(out, o);
- out += 8*4;
- }
- }
-#endif
+ // store, interleaving r/g/b/a
+ vst4_u8(out, o);
+ out += 8 * 4;
+ }
+ }
+ #endif
- for (; i < count; ++i) {
- int y_fixed = (y[i] << 20) + (1<<19); // rounding
- int r,g,b;
- int cr = pcr[i] - 128;
- int cb = pcb[i] - 128;
- r = y_fixed + cr* stbi__float2fixed(1.40200f);
- g = y_fixed + cr*-stbi__float2fixed(0.71414f) + ((cb*-stbi__float2fixed(0.34414f)) & 0xffff0000);
- b = y_fixed + cb* stbi__float2fixed(1.77200f);
- r >>= 20;
- g >>= 20;
- b >>= 20;
- if ((unsigned) r > 255) { if (r < 0) r = 0; else r = 255; }
- if ((unsigned) g > 255) { if (g < 0) g = 0; else g = 255; }
- if ((unsigned) b > 255) { if (b < 0) b = 0; else b = 255; }
- out[0] = (stbi_uc)r;
- out[1] = (stbi_uc)g;
- out[2] = (stbi_uc)b;
- out[3] = 255;
- out += step;
- }
+ for (; i < count; ++i)
+ {
+ int y_fixed = (y[i] << 20) + (1 << 19); // rounding
+ int r, g, b;
+ int cr = pcr[i] - 128;
+ int cb = pcb[i] - 128;
+ r = y_fixed + cr * stbi__float2fixed(1.40200f);
+ g = y_fixed + cr * -stbi__float2fixed(0.71414f) + (cb * -stbi__float2fixed(0.34414f) & 0xffff0000);
+ b = y_fixed + cb * stbi__float2fixed(1.77200f);
+ r >>= 20;
+ g >>= 20;
+ b >>= 20;
+ if ((unsigned)r > 255)
+ {
+ if (r < 0) r = 0;
+ else r = 255;
+ }
+ if ((unsigned)g > 255)
+ {
+ if (g < 0) g = 0;
+ else g = 255;
+ }
+ if ((unsigned)b > 255)
+ {
+ if (b < 0) b = 0;
+ else b = 255;
+ }
+ out[0] = (stbi_uc)r;
+ out[1] = (stbi_uc)g;
+ out[2] = (stbi_uc)b;
+ out[3] = 255;
+ out += step;
+ }
}
#endif
// set up the kernels
static void stbi__setup_jpeg(stbi__jpeg *j)
{
- j->idct_block_kernel = stbi__idct_block;
- j->YCbCr_to_RGB_kernel = stbi__YCbCr_to_RGB_row;
- j->resample_row_hv_2_kernel = stbi__resample_row_hv_2;
+ j->idct_block_kernel = stbi__idct_block;
+ j->YCbCr_to_RGB_kernel = stbi__YCbCr_to_RGB_row;
+ j->resample_row_hv_2_kernel = stbi__resample_row_hv_2;
-#ifdef STBI_SSE2
- if (stbi__sse2_available()) {
- j->idct_block_kernel = stbi__idct_simd;
- j->YCbCr_to_RGB_kernel = stbi__YCbCr_to_RGB_simd;
- j->resample_row_hv_2_kernel = stbi__resample_row_hv_2_simd;
- }
-#endif
+ #ifdef STBI_SSE2
+ if (stbi__sse2_available())
+ {
+ j->idct_block_kernel = stbi__idct_simd;
+ j->YCbCr_to_RGB_kernel = stbi__YCbCr_to_RGB_simd;
+ j->resample_row_hv_2_kernel = stbi__resample_row_hv_2_simd;
+ }
+ #endif
-#ifdef STBI_NEON
- j->idct_block_kernel = stbi__idct_simd;
- j->YCbCr_to_RGB_kernel = stbi__YCbCr_to_RGB_simd;
- j->resample_row_hv_2_kernel = stbi__resample_row_hv_2_simd;
-#endif
+ #ifdef STBI_NEON
+ j->idct_block_kernel = stbi__idct_simd;
+ j->YCbCr_to_RGB_kernel = stbi__YCbCr_to_RGB_simd;
+ j->resample_row_hv_2_kernel = stbi__resample_row_hv_2_simd;
+ #endif
}
// clean up the temporary component buffers
static void stbi__cleanup_jpeg(stbi__jpeg *j)
{
- stbi__free_jpeg_components(j, j->s->img_n, 0);
+ stbi__free_jpeg_components(j, j->s->img_n, 0);
}
typedef struct
{
- resample_row_func resample;
- stbi_uc *line0,*line1;
- int hs,vs; // expansion factor in each axis
- int w_lores; // horizontal pixels pre-expansion
- int ystep; // how far through vertical expansion we are
- int ypos; // which pre-expansion row we're on
+ resample_row_func resample;
+ stbi_uc *line0, *line1;
+ int hs, vs; // expansion factor in each axis
+ int w_lores; // horizontal pixels pre-expansion
+ int ystep; // how far through vertical expansion we are
+ int ypos; // which pre-expansion row we're on
} stbi__resample;
// fast 0..255 * 0..255 => 0..255 rounded multiplication
static stbi_uc stbi__blinn_8x8(stbi_uc x, stbi_uc y)
{
- unsigned int t = x*y + 128;
- return (stbi_uc) ((t + (t >>8)) >> 8);
+ unsigned int t = x * y + 128;
+ return (stbi_uc)((t + (t >> 8)) >> 8);
}
static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp, int req_comp)
{
- int n, decode_n, is_rgb;
- z->s->img_n = 0; // make stbi__cleanup_jpeg safe
+ int n, decode_n, is_rgb;
+ z->s->img_n = 0; // make stbi__cleanup_jpeg safe
- // validate req_comp
- if (req_comp < 0 || req_comp > 4) return stbi__errpuc("bad req_comp", "Internal error");
+ // validate req_comp
+ if (req_comp < 0 || req_comp > 4) return stbi__errpuc("bad req_comp", "Internal error");
- // load a jpeg image from whichever source, but leave in YCbCr format
- if (!stbi__decode_jpeg_image(z)) { stbi__cleanup_jpeg(z); return NULL; }
+ // load a jpeg image from whichever source, but leave in YCbCr format
+ if (!stbi__decode_jpeg_image(z))
+ {
+ stbi__cleanup_jpeg(z);
+ return NULL;
+ }
- // determine actual number of components to generate
- n = req_comp ? req_comp : z->s->img_n >= 3 ? 3 : 1;
+ // determine actual number of components to generate
+ n = req_comp ? req_comp : z->s->img_n >= 3 ? 3 : 1;
- is_rgb = z->s->img_n == 3 && (z->rgb == 3 || (z->app14_color_transform == 0 && !z->jfif));
+ is_rgb = z->s->img_n == 3 && (z->rgb == 3 || (z->app14_color_transform == 0 && !z->jfif));
- if (z->s->img_n == 3 && n < 3 && !is_rgb)
- decode_n = 1;
- else
- decode_n = z->s->img_n;
+ if (z->s->img_n == 3 && n < 3 && !is_rgb)
+ decode_n = 1;
+ else
+ decode_n = z->s->img_n;
- // resample and color-convert
- {
- int k;
- unsigned int i,j;
- stbi_uc *output;
- stbi_uc *coutput[4];
+ // resample and color-convert
+ {
+ int k;
+ unsigned int i, j;
+ stbi_uc *output;
+ stbi_uc *coutput[4];
- stbi__resample res_comp[4];
+ stbi__resample res_comp[4];
- for (k=0; k < decode_n; ++k) {
- stbi__resample *r = &res_comp[k];
-
- // allocate line buffer big enough for upsampling off the edges
- // with upsample factor of 4
- z->img_comp[k].linebuf = (stbi_uc *) stbi__malloc(z->s->img_x + 3);
- if (!z->img_comp[k].linebuf) { stbi__cleanup_jpeg(z); return stbi__errpuc("outofmem", "Out of memory"); }
-
- r->hs = z->img_h_max / z->img_comp[k].h;
- r->vs = z->img_v_max / z->img_comp[k].v;
- r->ystep = r->vs >> 1;
- r->w_lores = (z->s->img_x + r->hs-1) / r->hs;
- r->ypos = 0;
- r->line0 = r->line1 = z->img_comp[k].data;
-
- if (r->hs == 1 && r->vs == 1) r->resample = resample_row_1;
- else if (r->hs == 1 && r->vs == 2) r->resample = stbi__resample_row_v_2;
- else if (r->hs == 2 && r->vs == 1) r->resample = stbi__resample_row_h_2;
- else if (r->hs == 2 && r->vs == 2) r->resample = z->resample_row_hv_2_kernel;
- else r->resample = stbi__resample_row_generic;
- }
-
- // can't error after this so, this is safe
- output = (stbi_uc *) stbi__malloc_mad3(n, z->s->img_x, z->s->img_y, 1);
- if (!output) { stbi__cleanup_jpeg(z); return stbi__errpuc("outofmem", "Out of memory"); }
-
- // now go ahead and resample
- for (j=0; j < z->s->img_y; ++j) {
- stbi_uc *out = output + n * z->s->img_x * j;
- for (k=0; k < decode_n; ++k) {
+ for (k = 0; k < decode_n; ++k)
+ {
stbi__resample *r = &res_comp[k];
- int y_bot = r->ystep >= (r->vs >> 1);
- coutput[k] = r->resample(z->img_comp[k].linebuf,
- y_bot ? r->line1 : r->line0,
- y_bot ? r->line0 : r->line1,
- r->w_lores, r->hs);
- if (++r->ystep >= r->vs) {
- r->ystep = 0;
- r->line0 = r->line1;
- if (++r->ypos < z->img_comp[k].y)
- r->line1 += z->img_comp[k].w2;
+
+ // allocate line buffer big enough for upsampling off the edges
+ // with upsample factor of 4
+ z->img_comp[k].linebuf = (stbi_uc *)stbi__malloc(z->s->img_x + 3);
+ if (!z->img_comp[k].linebuf)
+ {
+ stbi__cleanup_jpeg(z);
+ return stbi__errpuc("outofmem", "Out of memory");
}
- }
- if (n >= 3) {
- stbi_uc *y = coutput[0];
- if (z->s->img_n == 3) {
- if (is_rgb) {
- for (i=0; i < z->s->img_x; ++i) {
- out[0] = y[i];
- out[1] = coutput[1][i];
- out[2] = coutput[2][i];
- out[3] = 255;
- out += n;
- }
- } else {
- z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n);
- }
- } else if (z->s->img_n == 4) {
- if (z->app14_color_transform == 0) { // CMYK
- for (i=0; i < z->s->img_x; ++i) {
- stbi_uc m = coutput[3][i];
- out[0] = stbi__blinn_8x8(coutput[0][i], m);
- out[1] = stbi__blinn_8x8(coutput[1][i], m);
- out[2] = stbi__blinn_8x8(coutput[2][i], m);
- out[3] = 255;
- out += n;
- }
- } else if (z->app14_color_transform == 2) { // YCCK
- z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n);
- for (i=0; i < z->s->img_x; ++i) {
- stbi_uc m = coutput[3][i];
- out[0] = stbi__blinn_8x8(255 - out[0], m);
- out[1] = stbi__blinn_8x8(255 - out[1], m);
- out[2] = stbi__blinn_8x8(255 - out[2], m);
- out += n;
- }
- } else { // YCbCr + alpha? Ignore the fourth channel for now
- z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n);
- }
- } else
- for (i=0; i < z->s->img_x; ++i) {
- out[0] = out[1] = out[2] = y[i];
- out[3] = 255; // not used if n==3
- out += n;
- }
- } else {
- if (is_rgb) {
- if (n == 1)
- for (i=0; i < z->s->img_x; ++i)
- *out++ = stbi__compute_y(coutput[0][i], coutput[1][i], coutput[2][i]);
- else {
- for (i=0; i < z->s->img_x; ++i, out += 2) {
- out[0] = stbi__compute_y(coutput[0][i], coutput[1][i], coutput[2][i]);
- out[1] = 255;
- }
- }
- } else if (z->s->img_n == 4 && z->app14_color_transform == 0) {
- for (i=0; i < z->s->img_x; ++i) {
- stbi_uc m = coutput[3][i];
- stbi_uc r = stbi__blinn_8x8(coutput[0][i], m);
- stbi_uc g = stbi__blinn_8x8(coutput[1][i], m);
- stbi_uc b = stbi__blinn_8x8(coutput[2][i], m);
- out[0] = stbi__compute_y(r, g, b);
- out[1] = 255;
- out += n;
- }
- } else if (z->s->img_n == 4 && z->app14_color_transform == 2) {
- for (i=0; i < z->s->img_x; ++i) {
- out[0] = stbi__blinn_8x8(255 - coutput[0][i], coutput[3][i]);
- out[1] = 255;
- out += n;
- }
- } else {
- stbi_uc *y = coutput[0];
- if (n == 1)
- for (i=0; i < z->s->img_x; ++i) out[i] = y[i];
- else
- for (i=0; i < z->s->img_x; ++i) *out++ = y[i], *out++ = 255;
+
+ r->hs = z->img_h_max / z->img_comp[k].h;
+ r->vs = z->img_v_max / z->img_comp[k].v;
+ r->ystep = r->vs >> 1;
+ r->w_lores = (z->s->img_x + r->hs - 1) / r->hs;
+ r->ypos = 0;
+ r->line0 = r->line1 = z->img_comp[k].data;
+
+ if (r->hs == 1 && r->vs == 1) r->resample = resample_row_1;
+ else if (r->hs == 1 && r->vs == 2) r->resample = stbi__resample_row_v_2;
+ else if (r->hs == 2 && r->vs == 1) r->resample = stbi__resample_row_h_2;
+ else if (r->hs == 2 && r->vs == 2) r->resample = z->resample_row_hv_2_kernel;
+ else r->resample = stbi__resample_row_generic;
+ }
+
+ // can't error after this so, this is safe
+ output = (stbi_uc *)stbi__malloc_mad3(n, z->s->img_x, z->s->img_y, 1);
+ if (!output)
+ {
+ stbi__cleanup_jpeg(z);
+ return stbi__errpuc("outofmem", "Out of memory");
+ }
+
+ // now go ahead and resample
+ for (j = 0; j < z->s->img_y; ++j)
+ {
+ stbi_uc *out = output + n * z->s->img_x * j;
+ for (k = 0; k < decode_n; ++k)
+ {
+ stbi__resample *r = &res_comp[k];
+ int y_bot = r->ystep >= r->vs >> 1;
+ coutput[k] = r->resample(z->img_comp[k].linebuf,
+ y_bot ? r->line1 : r->line0,
+ y_bot ? r->line0 : r->line1,
+ r->w_lores, r->hs);
+ if (++r->ystep >= r->vs)
+ {
+ r->ystep = 0;
+ r->line0 = r->line1;
+ if (++r->ypos < z->img_comp[k].y)
+ r->line1 += z->img_comp[k].w2;
+ }
}
- }
- }
- stbi__cleanup_jpeg(z);
- *out_x = z->s->img_x;
- *out_y = z->s->img_y;
- if (comp) *comp = z->s->img_n >= 3 ? 3 : 1; // report original components, not output
- return output;
- }
+ if (n >= 3)
+ {
+ stbi_uc *y = coutput[0];
+ if (z->s->img_n == 3)
+ {
+ if (is_rgb)
+ {
+ for (i = 0; i < z->s->img_x; ++i)
+ {
+ out[0] = y[i];
+ out[1] = coutput[1][i];
+ out[2] = coutput[2][i];
+ out[3] = 255;
+ out += n;
+ }
+ }
+ else
+ {
+ z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n);
+ }
+ }
+ else if (z->s->img_n == 4)
+ {
+ if (z->app14_color_transform == 0)
+ { // CMYK
+ for (i = 0; i < z->s->img_x; ++i)
+ {
+ stbi_uc m = coutput[3][i];
+ out[0] = stbi__blinn_8x8(coutput[0][i], m);
+ out[1] = stbi__blinn_8x8(coutput[1][i], m);
+ out[2] = stbi__blinn_8x8(coutput[2][i], m);
+ out[3] = 255;
+ out += n;
+ }
+ }
+ else if (z->app14_color_transform == 2)
+ { // YCCK
+ z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n);
+ for (i = 0; i < z->s->img_x; ++i)
+ {
+ stbi_uc m = coutput[3][i];
+ out[0] = stbi__blinn_8x8(255 - out[0], m);
+ out[1] = stbi__blinn_8x8(255 - out[1], m);
+ out[2] = stbi__blinn_8x8(255 - out[2], m);
+ out += n;
+ }
+ }
+ else
+ { // YCbCr + alpha? Ignore the fourth channel for now
+ z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n);
+ }
+ }
+ else
+ for (i = 0; i < z->s->img_x; ++i)
+ {
+ out[0] = out[1] = out[2] = y[i];
+ out[3] = 255; // not used if n==3
+ out += n;
+ }
+ }
+ else
+ {
+ if (is_rgb)
+ {
+ if (n == 1)
+ for (i = 0; i < z->s->img_x; ++i)
+ *out++ = stbi__compute_y(coutput[0][i], coutput[1][i], coutput[2][i]);
+ else
+ {
+ for (i = 0; i < z->s->img_x; ++i, out += 2)
+ {
+ out[0] = stbi__compute_y(coutput[0][i], coutput[1][i], coutput[2][i]);
+ out[1] = 255;
+ }
+ }
+ }
+ else if (z->s->img_n == 4 && z->app14_color_transform == 0)
+ {
+ for (i = 0; i < z->s->img_x; ++i)
+ {
+ stbi_uc m = coutput[3][i];
+ stbi_uc r = stbi__blinn_8x8(coutput[0][i], m);
+ stbi_uc g = stbi__blinn_8x8(coutput[1][i], m);
+ stbi_uc b = stbi__blinn_8x8(coutput[2][i], m);
+ out[0] = stbi__compute_y(r, g, b);
+ out[1] = 255;
+ out += n;
+ }
+ }
+ else if (z->s->img_n == 4 && z->app14_color_transform == 2)
+ {
+ for (i = 0; i < z->s->img_x; ++i)
+ {
+ out[0] = stbi__blinn_8x8(255 - coutput[0][i], coutput[3][i]);
+ out[1] = 255;
+ out += n;
+ }
+ }
+ else
+ {
+ stbi_uc *y = coutput[0];
+ if (n == 1)
+ for (i = 0; i < z->s->img_x; ++i) out[i] = y[i];
+ else
+ for (i = 0; i < z->s->img_x; ++i) *out++ = y[i], *out++ = 255;
+ }
+ }
+ }
+ stbi__cleanup_jpeg(z);
+ *out_x = z->s->img_x;
+ *out_y = z->s->img_y;
+ if (comp) *comp = z->s->img_n >= 3 ? 3 : 1; // report original components, not output
+ return output;
+ }
}
static void *stbi__jpeg_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri)
{
- unsigned char* result;
- stbi__jpeg* j = (stbi__jpeg*) stbi__malloc(sizeof(stbi__jpeg));
- STBI_NOTUSED(ri);
- j->s = s;
- stbi__setup_jpeg(j);
- result = load_jpeg_image(j, x,y,comp,req_comp);
- STBI_FREE(j);
- return result;
+ unsigned char *result;
+ stbi__jpeg *j = stbi__malloc(sizeof(stbi__jpeg));
+ STBI_NOTUSED(ri);
+ j->s = s;
+ stbi__setup_jpeg(j);
+ result = load_jpeg_image(j, x, y, comp, req_comp);
+ STBI_FREE(j);
+ return result;
}
static int stbi__jpeg_test(stbi__context *s)
{
- int r;
- stbi__jpeg* j = (stbi__jpeg*)stbi__malloc(sizeof(stbi__jpeg));
- j->s = s;
- stbi__setup_jpeg(j);
- r = stbi__decode_jpeg_header(j, STBI__SCAN_type);
- stbi__rewind(s);
- STBI_FREE(j);
- return r;
+ int r;
+ stbi__jpeg *j = stbi__malloc(sizeof(stbi__jpeg));
+ j->s = s;
+ stbi__setup_jpeg(j);
+ r = stbi__decode_jpeg_header(j, STBI__SCAN_type);
+ stbi__rewind(s);
+ STBI_FREE(j);
+ return r;
}
static int stbi__jpeg_info_raw(stbi__jpeg *j, int *x, int *y, int *comp)
{
- if (!stbi__decode_jpeg_header(j, STBI__SCAN_header)) {
- stbi__rewind( j->s );
- return 0;
- }
- if (x) *x = j->s->img_x;
- if (y) *y = j->s->img_y;
- if (comp) *comp = j->s->img_n >= 3 ? 3 : 1;
- return 1;
+ if (!stbi__decode_jpeg_header(j, STBI__SCAN_header))
+ {
+ stbi__rewind(j->s);
+ return 0;
+ }
+ if (x) *x = j->s->img_x;
+ if (y) *y = j->s->img_y;
+ if (comp) *comp = j->s->img_n >= 3 ? 3 : 1;
+ return 1;
}
static int stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp)
{
- int result;
- stbi__jpeg* j = (stbi__jpeg*) (stbi__malloc(sizeof(stbi__jpeg)));
- j->s = s;
- result = stbi__jpeg_info_raw(j, x, y, comp);
- STBI_FREE(j);
- return result;
+ int result;
+ stbi__jpeg *j = stbi__malloc(sizeof(stbi__jpeg));
+ j->s = s;
+ result = stbi__jpeg_info_raw(j, x, y, comp);
+ STBI_FREE(j);
+ return result;
}
#endif
@@ -3793,76 +4233,81 @@ static int stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp)
// (jpegs packs from left, zlib from right, so can't share code)
typedef struct
{
- stbi__uint16 fast[1 << STBI__ZFAST_BITS];
- stbi__uint16 firstcode[16];
- int maxcode[17];
- stbi__uint16 firstsymbol[16];
- stbi_uc size[288];
- stbi__uint16 value[288];
+ stbi__uint16 fast[1 << STBI__ZFAST_BITS];
+ stbi__uint16 firstcode[16];
+ int maxcode[17];
+ stbi__uint16 firstsymbol[16];
+ stbi_uc size[288];
+ stbi__uint16 value[288];
} stbi__zhuffman;
stbi_inline static int stbi__bitreverse16(int n)
{
- n = ((n & 0xAAAA) >> 1) | ((n & 0x5555) << 1);
- n = ((n & 0xCCCC) >> 2) | ((n & 0x3333) << 2);
- n = ((n & 0xF0F0) >> 4) | ((n & 0x0F0F) << 4);
- n = ((n & 0xFF00) >> 8) | ((n & 0x00FF) << 8);
- return n;
+ n = (n & 0xAAAA) >> 1 | (n & 0x5555) << 1;
+ n = (n & 0xCCCC) >> 2 | (n & 0x3333) << 2;
+ n = (n & 0xF0F0) >> 4 | (n & 0x0F0F) << 4;
+ n = (n & 0xFF00) >> 8 | (n & 0x00FF) << 8;
+ return n;
}
stbi_inline static int stbi__bit_reverse(int v, int bits)
{
- STBI_ASSERT(bits <= 16);
- // to bit reverse n bits, reverse 16 and shift
- // e.g. 11 bits, bit reverse and shift away 5
- return stbi__bitreverse16(v) >> (16-bits);
+ STBI_ASSERT(bits <= 16);
+ // to bit reverse n bits, reverse 16 and shift
+ // e.g. 11 bits, bit reverse and shift away 5
+ return stbi__bitreverse16(v) >> (16 - bits);
}
static int stbi__zbuild_huffman(stbi__zhuffman *z, const stbi_uc *sizelist, int num)
{
- int i,k=0;
- int code, next_code[16], sizes[17];
+ int i, k = 0;
+ int code, next_code[16], sizes[17];
- // DEFLATE spec for generating codes
- memset(sizes, 0, sizeof(sizes));
- memset(z->fast, 0, sizeof(z->fast));
- for (i=0; i < num; ++i)
- ++sizes[sizelist[i]];
- sizes[0] = 0;
- for (i=1; i < 16; ++i)
- if (sizes[i] > (1 << i))
- return stbi__err("bad sizes", "Corrupt PNG");
- code = 0;
- for (i=1; i < 16; ++i) {
- next_code[i] = code;
- z->firstcode[i] = (stbi__uint16) code;
- z->firstsymbol[i] = (stbi__uint16) k;
- code = (code + sizes[i]);
- if (sizes[i])
- if (code-1 >= (1 << i)) return stbi__err("bad codelengths","Corrupt PNG");
- z->maxcode[i] = code << (16-i); // preshift for inner loop
- code <<= 1;
- k += sizes[i];
- }
- z->maxcode[16] = 0x10000; // sentinel
- for (i=0; i < num; ++i) {
- int s = sizelist[i];
- if (s) {
- int c = next_code[s] - z->firstcode[s] + z->firstsymbol[s];
- stbi__uint16 fastv = (stbi__uint16) ((s << 9) | i);
- z->size [c] = (stbi_uc ) s;
- z->value[c] = (stbi__uint16) i;
- if (s <= STBI__ZFAST_BITS) {
- int j = stbi__bit_reverse(next_code[s],s);
- while (j < (1 << STBI__ZFAST_BITS)) {
- z->fast[j] = fastv;
- j += (1 << s);
+ // DEFLATE spec for generating codes
+ memset(sizes, 0, sizeof(sizes));
+ memset(z->fast, 0, sizeof(z->fast));
+ for (i = 0; i < num; ++i)
+ ++sizes[sizelist[i]];
+ sizes[0] = 0;
+ for (i = 1; i < 16; ++i)
+ if (sizes[i] > 1 << i)
+ return stbi__err("bad sizes", "Corrupt PNG");
+ code = 0;
+ for (i = 1; i < 16; ++i)
+ {
+ next_code[i] = code;
+ z->firstcode[i] = (stbi__uint16)code;
+ z->firstsymbol[i] = (stbi__uint16)k;
+ code = code + sizes[i];
+ if (sizes[i])
+ if (code - 1 >= 1 << i) return stbi__err("bad codelengths", "Corrupt PNG");
+ z->maxcode[i] = code << (16 - i); // preshift for inner loop
+ code <<= 1;
+ k += sizes[i];
+ }
+ z->maxcode[16] = 0x10000; // sentinel
+ for (i = 0; i < num; ++i)
+ {
+ int s = sizelist[i];
+ if (s)
+ {
+ int c = next_code[s] - z->firstcode[s] + z->firstsymbol[s];
+ stbi__uint16 fastv = (stbi__uint16)(s << 9 | i);
+ z->size[c] = (stbi_uc)s;
+ z->value[c] = (stbi__uint16)i;
+ if (s <= STBI__ZFAST_BITS)
+ {
+ int j = stbi__bit_reverse(next_code[s], s);
+ while (j < 1 << STBI__ZFAST_BITS)
+ {
+ z->fast[j] = fastv;
+ j += 1 << s;
+ }
}
- }
- ++next_code[s];
- }
- }
- return 1;
+ ++next_code[s];
+ }
+ }
+ return 1;
}
// zlib-from-memory implementation for PNG reading
@@ -3873,256 +4318,279 @@ static int stbi__zbuild_huffman(stbi__zhuffman *z, const stbi_uc *sizelist, int
typedef struct
{
- stbi_uc *zbuffer, *zbuffer_end;
- int num_bits;
- stbi__uint32 code_buffer;
+ stbi_uc *zbuffer, *zbuffer_end;
+ int num_bits;
+ stbi__uint32 code_buffer;
- char *zout;
- char *zout_start;
- char *zout_end;
- int z_expandable;
+ char *zout;
+ char *zout_start;
+ char *zout_end;
+ int z_expandable;
- stbi__zhuffman z_length, z_distance;
+ stbi__zhuffman z_length, z_distance;
} stbi__zbuf;
stbi_inline static stbi_uc stbi__zget8(stbi__zbuf *z)
{
- if (z->zbuffer >= z->zbuffer_end) return 0;
- return *z->zbuffer++;
+ if (z->zbuffer >= z->zbuffer_end) return 0;
+ return *z->zbuffer++;
}
static void stbi__fill_bits(stbi__zbuf *z)
{
- do {
- STBI_ASSERT(z->code_buffer < (1U << z->num_bits));
- z->code_buffer |= (unsigned int) stbi__zget8(z) << z->num_bits;
- z->num_bits += 8;
- } while (z->num_bits <= 24);
+ do
+ {
+ STBI_ASSERT(z->code_buffer < (1U << z->num_bits));
+ z->code_buffer |= (unsigned int)stbi__zget8(z) << z->num_bits;
+ z->num_bits += 8;
+ }
+ while (z->num_bits <= 24);
}
stbi_inline static unsigned int stbi__zreceive(stbi__zbuf *z, int n)
{
- unsigned int k;
- if (z->num_bits < n) stbi__fill_bits(z);
- k = z->code_buffer & ((1 << n) - 1);
- z->code_buffer >>= n;
- z->num_bits -= n;
- return k;
+ unsigned int k;
+ if (z->num_bits < n) stbi__fill_bits(z);
+ k = z->code_buffer & (1 << n) - 1;
+ z->code_buffer >>= n;
+ z->num_bits -= n;
+ return k;
}
static int stbi__zhuffman_decode_slowpath(stbi__zbuf *a, stbi__zhuffman *z)
{
- int b,s,k;
- // not resolved by fast table, so compute it the slow way
- // use jpeg approach, which requires MSbits at top
- k = stbi__bit_reverse(a->code_buffer, 16);
- for (s=STBI__ZFAST_BITS+1; ; ++s)
- if (k < z->maxcode[s])
- break;
- if (s == 16) return -1; // invalid code!
- // code size is s, so:
- b = (k >> (16-s)) - z->firstcode[s] + z->firstsymbol[s];
- STBI_ASSERT(z->size[b] == s);
- a->code_buffer >>= s;
- a->num_bits -= s;
- return z->value[b];
+ int b, s, k;
+ // not resolved by fast table, so compute it the slow way
+ // use jpeg approach, which requires MSbits at top
+ k = stbi__bit_reverse(a->code_buffer, 16);
+ for (s = STBI__ZFAST_BITS + 1; ; ++s)
+ if (k < z->maxcode[s])
+ break;
+ if (s == 16) return -1; // invalid code!
+ // code size is s, so:
+ b = (k >> (16 - s)) - z->firstcode[s] + z->firstsymbol[s];
+ STBI_ASSERT(z->size[b] == s);
+ a->code_buffer >>= s;
+ a->num_bits -= s;
+ return z->value[b];
}
stbi_inline static int stbi__zhuffman_decode(stbi__zbuf *a, stbi__zhuffman *z)
{
- int b,s;
- if (a->num_bits < 16) stbi__fill_bits(a);
- b = z->fast[a->code_buffer & STBI__ZFAST_MASK];
- if (b) {
- s = b >> 9;
- a->code_buffer >>= s;
- a->num_bits -= s;
- return b & 511;
- }
- return stbi__zhuffman_decode_slowpath(a, z);
+ int b, s;
+ if (a->num_bits < 16) stbi__fill_bits(a);
+ b = z->fast[a->code_buffer & STBI__ZFAST_MASK];
+ if (b)
+ {
+ s = b >> 9;
+ a->code_buffer >>= s;
+ a->num_bits -= s;
+ return b & 511;
+ }
+ return stbi__zhuffman_decode_slowpath(a, z);
}
-static int stbi__zexpand(stbi__zbuf *z, char *zout, int n) // need to make room for n bytes
+static int stbi__zexpand(stbi__zbuf *z, char *zout, int n) // need to make room for n bytes
{
- char *q;
- int cur, limit, old_limit;
- z->zout = zout;
- if (!z->z_expandable) return stbi__err("output buffer limit","Corrupt PNG");
- cur = (int) (z->zout - z->zout_start);
- limit = old_limit = (int) (z->zout_end - z->zout_start);
- while (cur + n > limit)
- limit *= 2;
- q = (char *) STBI_REALLOC_SIZED(z->zout_start, old_limit, limit);
- STBI_NOTUSED(old_limit);
- if (q == NULL) return stbi__err("outofmem", "Out of memory");
- z->zout_start = q;
- z->zout = q + cur;
- z->zout_end = q + limit;
- return 1;
+ char *q;
+ int cur, limit, old_limit;
+ z->zout = zout;
+ if (!z->z_expandable) return stbi__err("output buffer limit", "Corrupt PNG");
+ cur = (int)(z->zout - z->zout_start);
+ limit = old_limit = (int)(z->zout_end - z->zout_start);
+ while (cur + n > limit)
+ limit *= 2;
+ q = (char *)STBI_REALLOC_SIZED(z->zout_start, old_limit, limit);
+ STBI_NOTUSED(old_limit);
+ if (q == NULL) return stbi__err("outofmem", "Out of memory");
+ z->zout_start = q;
+ z->zout = q + cur;
+ z->zout_end = q + limit;
+ return 1;
}
static const int stbi__zlength_base[31] = {
- 3,4,5,6,7,8,9,10,11,13,
- 15,17,19,23,27,31,35,43,51,59,
- 67,83,99,115,131,163,195,227,258,0,0 };
+ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13,
+ 15, 17, 19, 23, 27, 31, 35, 43, 51, 59,
+ 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
+};
-static const int stbi__zlength_extra[31]=
-{ 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0 };
+static const int stbi__zlength_extra[31] =
+ {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0};
-static const int stbi__zdist_base[32] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,
-257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0};
+static const int stbi__zdist_base[32] = {
+ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
+ 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0
+};
static const int stbi__zdist_extra[32] =
-{ 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
+ {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13};
static int stbi__parse_huffman_block(stbi__zbuf *a)
{
- char *zout = a->zout;
- for(;;) {
- int z = stbi__zhuffman_decode(a, &a->z_length);
- if (z < 256) {
- if (z < 0) return stbi__err("bad huffman code","Corrupt PNG"); // error in huffman codes
- if (zout >= a->zout_end) {
- if (!stbi__zexpand(a, zout, 1)) return 0;
- zout = a->zout;
- }
- *zout++ = (char) z;
- } else {
- stbi_uc *p;
- int len,dist;
- if (z == 256) {
- a->zout = zout;
- return 1;
- }
- z -= 257;
- len = stbi__zlength_base[z];
- if (stbi__zlength_extra[z]) len += stbi__zreceive(a, stbi__zlength_extra[z]);
- z = stbi__zhuffman_decode(a, &a->z_distance);
- if (z < 0) return stbi__err("bad huffman code","Corrupt PNG");
- dist = stbi__zdist_base[z];
- if (stbi__zdist_extra[z]) dist += stbi__zreceive(a, stbi__zdist_extra[z]);
- if (zout - a->zout_start < dist) return stbi__err("bad dist","Corrupt PNG");
- if (zout + len > a->zout_end) {
- if (!stbi__zexpand(a, zout, len)) return 0;
- zout = a->zout;
- }
- p = (stbi_uc *) (zout - dist);
- if (dist == 1) { // run of one byte; common in images.
- stbi_uc v = *p;
- if (len) { do *zout++ = v; while (--len); }
- } else {
- if (len) { do *zout++ = *p++; while (--len); }
- }
- }
- }
+ char *zout = a->zout;
+ for (;;)
+ {
+ int z = stbi__zhuffman_decode(a, &a->z_length);
+ if (z < 256)
+ {
+ if (z < 0) return stbi__err("bad huffman code", "Corrupt PNG"); // error in huffman codes
+ if (zout >= a->zout_end)
+ {
+ if (!stbi__zexpand(a, zout, 1)) return 0;
+ zout = a->zout;
+ }
+ *zout++ = (char)z;
+ }
+ else
+ {
+ stbi_uc *p;
+ int len, dist;
+ if (z == 256)
+ {
+ a->zout = zout;
+ return 1;
+ }
+ z -= 257;
+ len = stbi__zlength_base[z];
+ if (stbi__zlength_extra[z]) len += stbi__zreceive(a, stbi__zlength_extra[z]);
+ z = stbi__zhuffman_decode(a, &a->z_distance);
+ if (z < 0) return stbi__err("bad huffman code", "Corrupt PNG");
+ dist = stbi__zdist_base[z];
+ if (stbi__zdist_extra[z]) dist += stbi__zreceive(a, stbi__zdist_extra[z]);
+ if (zout - a->zout_start < dist) return stbi__err("bad dist", "Corrupt PNG");
+ if (zout + len > a->zout_end)
+ {
+ if (!stbi__zexpand(a, zout, len)) return 0;
+ zout = a->zout;
+ }
+ p = (stbi_uc *)(zout - dist);
+ if (dist == 1)
+ { // run of one byte; common in images.
+ stbi_uc v = *p;
+ if (len) { do *zout++ = v; while (--len); }
+ }
+ else
+ {
+ if (len) { do *zout++ = *p++; while (--len); }
+ }
+ }
+ }
}
static int stbi__compute_huffman_codes(stbi__zbuf *a)
{
- static const stbi_uc length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 };
- stbi__zhuffman z_codelength;
- stbi_uc lencodes[286+32+137];//padding for maximum single op
- stbi_uc codelength_sizes[19];
- int i,n;
+ static const stbi_uc length_dezigzag[19] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
+ stbi__zhuffman z_codelength;
+ stbi_uc lencodes[286 + 32 + 137]; //padding for maximum single op
+ stbi_uc codelength_sizes[19];
+ int i, n;
- int hlit = stbi__zreceive(a,5) + 257;
- int hdist = stbi__zreceive(a,5) + 1;
- int hclen = stbi__zreceive(a,4) + 4;
- int ntot = hlit + hdist;
+ int hlit = stbi__zreceive(a, 5) + 257;
+ int hdist = stbi__zreceive(a, 5) + 1;
+ int hclen = stbi__zreceive(a, 4) + 4;
+ int ntot = hlit + hdist;
- memset(codelength_sizes, 0, sizeof(codelength_sizes));
- for (i=0; i < hclen; ++i) {
- int s = stbi__zreceive(a,3);
- codelength_sizes[length_dezigzag[i]] = (stbi_uc) s;
- }
- if (!stbi__zbuild_huffman(&z_codelength, codelength_sizes, 19)) return 0;
+ memset(codelength_sizes, 0, sizeof(codelength_sizes));
+ for (i = 0; i < hclen; ++i)
+ {
+ int s = stbi__zreceive(a, 3);
+ codelength_sizes[length_dezigzag[i]] = (stbi_uc)s;
+ }
+ if (!stbi__zbuild_huffman(&z_codelength, codelength_sizes, 19)) return 0;
- n = 0;
- while (n < ntot) {
- int c = stbi__zhuffman_decode(a, &z_codelength);
- if (c < 0 || c >= 19) return stbi__err("bad codelengths", "Corrupt PNG");
- if (c < 16)
- lencodes[n++] = (stbi_uc) c;
- else {
- stbi_uc fill = 0;
- if (c == 16) {
- c = stbi__zreceive(a,2)+3;
- if (n == 0) return stbi__err("bad codelengths", "Corrupt PNG");
- fill = lencodes[n-1];
- } else if (c == 17)
- c = stbi__zreceive(a,3)+3;
- else {
- STBI_ASSERT(c == 18);
- c = stbi__zreceive(a,7)+11;
- }
- if (ntot - n < c) return stbi__err("bad codelengths", "Corrupt PNG");
- memset(lencodes+n, fill, c);
- n += c;
- }
- }
- if (n != ntot) return stbi__err("bad codelengths","Corrupt PNG");
- if (!stbi__zbuild_huffman(&a->z_length, lencodes, hlit)) return 0;
- if (!stbi__zbuild_huffman(&a->z_distance, lencodes+hlit, hdist)) return 0;
- return 1;
+ n = 0;
+ while (n < ntot)
+ {
+ int c = stbi__zhuffman_decode(a, &z_codelength);
+ if (c < 0 || c >= 19) return stbi__err("bad codelengths", "Corrupt PNG");
+ if (c < 16)
+ lencodes[n++] = (stbi_uc)c;
+ else
+ {
+ stbi_uc fill = 0;
+ if (c == 16)
+ {
+ c = stbi__zreceive(a, 2) + 3;
+ if (n == 0) return stbi__err("bad codelengths", "Corrupt PNG");
+ fill = lencodes[n - 1];
+ }
+ else if (c == 17)
+ c = stbi__zreceive(a, 3) + 3;
+ else
+ {
+ STBI_ASSERT(c == 18);
+ c = stbi__zreceive(a, 7) + 11;
+ }
+ if (ntot - n < c) return stbi__err("bad codelengths", "Corrupt PNG");
+ memset(lencodes + n, fill, c);
+ n += c;
+ }
+ }
+ if (n != ntot) return stbi__err("bad codelengths", "Corrupt PNG");
+ if (!stbi__zbuild_huffman(&a->z_length, lencodes, hlit)) return 0;
+ if (!stbi__zbuild_huffman(&a->z_distance, lencodes + hlit, hdist)) return 0;
+ return 1;
}
static int stbi__parse_uncompressed_block(stbi__zbuf *a)
{
- stbi_uc header[4];
- int len,nlen,k;
- if (a->num_bits & 7)
- stbi__zreceive(a, a->num_bits & 7); // discard
- // drain the bit-packed data into header
- k = 0;
- while (a->num_bits > 0) {
- header[k++] = (stbi_uc) (a->code_buffer & 255); // suppress MSVC run-time check
- a->code_buffer >>= 8;
- a->num_bits -= 8;
- }
- STBI_ASSERT(a->num_bits == 0);
- // now fill header the normal way
- while (k < 4)
- header[k++] = stbi__zget8(a);
- len = header[1] * 256 + header[0];
- nlen = header[3] * 256 + header[2];
- if (nlen != (len ^ 0xffff)) return stbi__err("zlib corrupt","Corrupt PNG");
- if (a->zbuffer + len > a->zbuffer_end) return stbi__err("read past buffer","Corrupt PNG");
- if (a->zout + len > a->zout_end)
- if (!stbi__zexpand(a, a->zout, len)) return 0;
- memcpy(a->zout, a->zbuffer, len);
- a->zbuffer += len;
- a->zout += len;
- return 1;
+ stbi_uc header[4];
+ int len, nlen, k;
+ if (a->num_bits & 7)
+ stbi__zreceive(a, a->num_bits & 7); // discard
+ // drain the bit-packed data into header
+ k = 0;
+ while (a->num_bits > 0)
+ {
+ header[k++] = (stbi_uc)(a->code_buffer & 255); // suppress MSVC run-time check
+ a->code_buffer >>= 8;
+ a->num_bits -= 8;
+ }
+ STBI_ASSERT(a->num_bits == 0);
+ // now fill header the normal way
+ while (k < 4)
+ header[k++] = stbi__zget8(a);
+ len = header[1] * 256 + header[0];
+ nlen = header[3] * 256 + header[2];
+ if (nlen != (len ^ 0xffff)) return stbi__err("zlib corrupt", "Corrupt PNG");
+ if (a->zbuffer + len > a->zbuffer_end) return stbi__err("read past buffer", "Corrupt PNG");
+ if (a->zout + len > a->zout_end)
+ if (!stbi__zexpand(a, a->zout, len)) return 0;
+ memcpy(a->zout, a->zbuffer, len);
+ a->zbuffer += len;
+ a->zout += len;
+ return 1;
}
static int stbi__parse_zlib_header(stbi__zbuf *a)
{
- int cmf = stbi__zget8(a);
- int cm = cmf & 15;
- /* int cinfo = cmf >> 4; */
- int flg = stbi__zget8(a);
- if ((cmf*256+flg) % 31 != 0) return stbi__err("bad zlib header","Corrupt PNG"); // zlib spec
- if (flg & 32) return stbi__err("no preset dict","Corrupt PNG"); // preset dictionary not allowed in png
- if (cm != 8) return stbi__err("bad compression","Corrupt PNG"); // DEFLATE required for png
- // window = 1 << (8 + cinfo)... but who cares, we fully buffer output
- return 1;
+ int cmf = stbi__zget8(a);
+ int cm = cmf & 15;
+ /* int cinfo = cmf >> 4; */
+ int flg = stbi__zget8(a);
+ if ((cmf * 256 + flg) % 31 != 0) return stbi__err("bad zlib header", "Corrupt PNG"); // zlib spec
+ if (flg & 32) return stbi__err("no preset dict", "Corrupt PNG"); // preset dictionary not allowed in png
+ if (cm != 8) return stbi__err("bad compression", "Corrupt PNG"); // DEFLATE required for png
+ // window = 1 << (8 + cinfo)... but who cares, we fully buffer output
+ return 1;
}
static const stbi_uc stbi__zdefault_length[288] =
{
- 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
- 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
- 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
- 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
- 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
- 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
- 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
- 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8
};
static const stbi_uc stbi__zdefault_distance[32] =
{
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
};
/*
Init algorithm:
@@ -4139,115 +4607,134 @@ Init algorithm:
static int stbi__parse_zlib(stbi__zbuf *a, int parse_header)
{
- int final, type;
- if (parse_header)
- if (!stbi__parse_zlib_header(a)) return 0;
- a->num_bits = 0;
- a->code_buffer = 0;
- do {
- final = stbi__zreceive(a,1);
- type = stbi__zreceive(a,2);
- if (type == 0) {
- if (!stbi__parse_uncompressed_block(a)) return 0;
- } else if (type == 3) {
- return 0;
- } else {
- if (type == 1) {
- // use fixed code lengths
- if (!stbi__zbuild_huffman(&a->z_length , stbi__zdefault_length , 288)) return 0;
- if (!stbi__zbuild_huffman(&a->z_distance, stbi__zdefault_distance, 32)) return 0;
- } else {
- if (!stbi__compute_huffman_codes(a)) return 0;
- }
- if (!stbi__parse_huffman_block(a)) return 0;
- }
- } while (!final);
- return 1;
+ int final, type;
+ if (parse_header)
+ if (!stbi__parse_zlib_header(a)) return 0;
+ a->num_bits = 0;
+ a->code_buffer = 0;
+ do
+ {
+ final = stbi__zreceive(a, 1);
+ type = stbi__zreceive(a, 2);
+ if (type == 0)
+ {
+ if (!stbi__parse_uncompressed_block(a)) return 0;
+ }
+ else if (type == 3)
+ {
+ return 0;
+ }
+ else
+ {
+ if (type == 1)
+ {
+ // use fixed code lengths
+ if (!stbi__zbuild_huffman(&a->z_length, stbi__zdefault_length, 288)) return 0;
+ if (!stbi__zbuild_huffman(&a->z_distance, stbi__zdefault_distance, 32)) return 0;
+ }
+ else
+ {
+ if (!stbi__compute_huffman_codes(a)) return 0;
+ }
+ if (!stbi__parse_huffman_block(a)) return 0;
+ }
+ }
+ while (!final);
+ return 1;
}
static int stbi__do_zlib(stbi__zbuf *a, char *obuf, int olen, int exp, int parse_header)
{
- a->zout_start = obuf;
- a->zout = obuf;
- a->zout_end = obuf + olen;
- a->z_expandable = exp;
+ a->zout_start = obuf;
+ a->zout = obuf;
+ a->zout_end = obuf + olen;
+ a->z_expandable = exp;
- return stbi__parse_zlib(a, parse_header);
+ return stbi__parse_zlib(a, parse_header);
}
STBIDEF char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen)
{
- stbi__zbuf a;
- char *p = (char *) stbi__malloc(initial_size);
- if (p == NULL) return NULL;
- a.zbuffer = (stbi_uc *) buffer;
- a.zbuffer_end = (stbi_uc *) buffer + len;
- if (stbi__do_zlib(&a, p, initial_size, 1, 1)) {
- if (outlen) *outlen = (int) (a.zout - a.zout_start);
- return a.zout_start;
- } else {
- STBI_FREE(a.zout_start);
- return NULL;
- }
+ stbi__zbuf a;
+ char *p = stbi__malloc(initial_size);
+ if (p == NULL) return NULL;
+ a.zbuffer = (stbi_uc *)buffer;
+ a.zbuffer_end = (stbi_uc *)buffer + len;
+ if (stbi__do_zlib(&a, p, initial_size, 1, 1))
+ {
+ if (outlen) *outlen = (int)(a.zout - a.zout_start);
+ return a.zout_start;
+ }
+ else
+ {
+ STBI_FREE(a.zout_start);
+ return NULL;
+ }
}
STBIDEF char *stbi_zlib_decode_malloc(char const *buffer, int len, int *outlen)
{
- return stbi_zlib_decode_malloc_guesssize(buffer, len, 16384, outlen);
+ return stbi_zlib_decode_malloc_guesssize(buffer, len, 16384, outlen);
}
STBIDEF char *stbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, int len, int initial_size, int *outlen, int parse_header)
{
- stbi__zbuf a;
- char *p = (char *) stbi__malloc(initial_size);
- if (p == NULL) return NULL;
- a.zbuffer = (stbi_uc *) buffer;
- a.zbuffer_end = (stbi_uc *) buffer + len;
- if (stbi__do_zlib(&a, p, initial_size, 1, parse_header)) {
- if (outlen) *outlen = (int) (a.zout - a.zout_start);
- return a.zout_start;
- } else {
- STBI_FREE(a.zout_start);
- return NULL;
- }
+ stbi__zbuf a;
+ char *p = stbi__malloc(initial_size);
+ if (p == NULL) return NULL;
+ a.zbuffer = (stbi_uc *)buffer;
+ a.zbuffer_end = (stbi_uc *)buffer + len;
+ if (stbi__do_zlib(&a, p, initial_size, 1, parse_header))
+ {
+ if (outlen) *outlen = (int)(a.zout - a.zout_start);
+ return a.zout_start;
+ }
+ else
+ {
+ STBI_FREE(a.zout_start);
+ return NULL;
+ }
}
STBIDEF int stbi_zlib_decode_buffer(char *obuffer, int olen, char const *ibuffer, int ilen)
{
- stbi__zbuf a;
- a.zbuffer = (stbi_uc *) ibuffer;
- a.zbuffer_end = (stbi_uc *) ibuffer + ilen;
- if (stbi__do_zlib(&a, obuffer, olen, 0, 1))
- return (int) (a.zout - a.zout_start);
- else
- return -1;
+ stbi__zbuf a;
+ a.zbuffer = (stbi_uc *)ibuffer;
+ a.zbuffer_end = (stbi_uc *)ibuffer + ilen;
+ if (stbi__do_zlib(&a, obuffer, olen, 0, 1))
+ return (int)(a.zout - a.zout_start);
+ else
+ return -1;
}
STBIDEF char *stbi_zlib_decode_noheader_malloc(char const *buffer, int len, int *outlen)
{
- stbi__zbuf a;
- char *p = (char *) stbi__malloc(16384);
- if (p == NULL) return NULL;
- a.zbuffer = (stbi_uc *) buffer;
- a.zbuffer_end = (stbi_uc *) buffer+len;
- if (stbi__do_zlib(&a, p, 16384, 1, 0)) {
- if (outlen) *outlen = (int) (a.zout - a.zout_start);
- return a.zout_start;
- } else {
- STBI_FREE(a.zout_start);
- return NULL;
- }
+ stbi__zbuf a;
+ char *p = stbi__malloc(16384);
+ if (p == NULL) return NULL;
+ a.zbuffer = (stbi_uc *)buffer;
+ a.zbuffer_end = (stbi_uc *)buffer + len;
+ if (stbi__do_zlib(&a, p, 16384, 1, 0))
+ {
+ if (outlen) *outlen = (int)(a.zout - a.zout_start);
+ return a.zout_start;
+ }
+ else
+ {
+ STBI_FREE(a.zout_start);
+ return NULL;
+ }
}
STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen)
{
- stbi__zbuf a;
- a.zbuffer = (stbi_uc *) ibuffer;
- a.zbuffer_end = (stbi_uc *) ibuffer + ilen;
- if (stbi__do_zlib(&a, obuffer, olen, 0, 0))
- return (int) (a.zout - a.zout_start);
- else
- return -1;
+ stbi__zbuf a;
+ a.zbuffer = (stbi_uc *)ibuffer;
+ a.zbuffer_end = (stbi_uc *)ibuffer + ilen;
+ if (stbi__do_zlib(&a, obuffer, olen, 0, 0))
+ return (int)(a.zout - a.zout_start);
+ else
+ return -1;
}
#endif
@@ -4264,410 +4751,535 @@ STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char
#ifndef STBI_NO_PNG
typedef struct
{
- stbi__uint32 length;
- stbi__uint32 type;
+ stbi__uint32 length;
+ stbi__uint32 type;
} stbi__pngchunk;
static stbi__pngchunk stbi__get_chunk_header(stbi__context *s)
{
- stbi__pngchunk c;
- c.length = stbi__get32be(s);
- c.type = stbi__get32be(s);
- return c;
+ stbi__pngchunk c;
+ c.length = stbi__get32be(s);
+ c.type = stbi__get32be(s);
+ return c;
}
static int stbi__check_png_header(stbi__context *s)
{
- static const stbi_uc png_sig[8] = { 137,80,78,71,13,10,26,10 };
- int i;
- for (i=0; i < 8; ++i)
- if (stbi__get8(s) != png_sig[i]) return stbi__err("bad png sig","Not a PNG");
- return 1;
+ static const stbi_uc png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
+ int i;
+ for (i = 0; i < 8; ++i)
+ if (stbi__get8(s) != png_sig[i]) return stbi__err("bad png sig", "Not a PNG");
+ return 1;
}
typedef struct
{
- stbi__context *s;
- stbi_uc *idata, *expanded, *out;
- int depth;
+ stbi__context *s;
+ stbi_uc *idata, *expanded, *out;
+ int depth;
} stbi__png;
-enum {
- STBI__F_none=0,
- STBI__F_sub=1,
- STBI__F_up=2,
- STBI__F_avg=3,
- STBI__F_paeth=4,
- // synthetic filters used for first scanline to avoid needing a dummy row of 0s
- STBI__F_avg_first,
- STBI__F_paeth_first
+enum
+{
+ STBI__F_none = 0,
+ STBI__F_sub = 1,
+ STBI__F_up = 2,
+ STBI__F_avg = 3,
+ STBI__F_paeth = 4,
+ // synthetic filters used for first scanline to avoid needing a dummy row of 0s
+ STBI__F_avg_first,
+ STBI__F_paeth_first
};
static stbi_uc first_row_filter[5] =
{
- STBI__F_none,
- STBI__F_sub,
- STBI__F_none,
- STBI__F_avg_first,
- STBI__F_paeth_first
+ STBI__F_none,
+ STBI__F_sub,
+ STBI__F_none,
+ STBI__F_avg_first,
+ STBI__F_paeth_first
};
static int stbi__paeth(int a, int b, int c)
{
- int p = a + b - c;
- int pa = abs(p-a);
- int pb = abs(p-b);
- int pc = abs(p-c);
- if (pa <= pb && pa <= pc) return a;
- if (pb <= pc) return b;
- return c;
+ int p = a + b - c;
+ int pa = abs(p - a);
+ int pb = abs(p - b);
+ int pc = abs(p - c);
+ if (pa <= pb && pa <= pc) return a;
+ if (pb <= pc) return b;
+ return c;
}
-static const stbi_uc stbi__depth_scale_table[9] = { 0, 0xff, 0x55, 0, 0x11, 0,0,0, 0x01 };
+static const stbi_uc stbi__depth_scale_table[9] = {0, 0xff, 0x55, 0, 0x11, 0, 0, 0, 0x01};
// create the png data from post-deflated data
static int stbi__create_png_image_raw(stbi__png *a, stbi_uc *raw, stbi__uint32 raw_len, int out_n, stbi__uint32 x, stbi__uint32 y, int depth, int color)
{
- int bytes = (depth == 16? 2 : 1);
- stbi__context *s = a->s;
- stbi__uint32 i,j,stride = x*out_n*bytes;
- stbi__uint32 img_len, img_width_bytes;
- int k;
- int img_n = s->img_n; // copy it into a local for later
+ int bytes = depth == 16 ? 2 : 1;
+ stbi__context *s = a->s;
+ stbi__uint32 i, j, stride = x * out_n * bytes;
+ stbi__uint32 img_len, img_width_bytes;
+ int k;
+ int img_n = s->img_n; // copy it into a local for later
- int output_bytes = out_n*bytes;
- int filter_bytes = img_n*bytes;
- int width = x;
+ int output_bytes = out_n * bytes;
+ int filter_bytes = img_n * bytes;
+ int width = x;
- STBI_ASSERT(out_n == s->img_n || out_n == s->img_n+1);
- a->out = (stbi_uc *) stbi__malloc_mad3(x, y, output_bytes, 0); // extra bytes to write off the end into
- if (!a->out) return stbi__err("outofmem", "Out of memory");
+ STBI_ASSERT(out_n == s->img_n || out_n == s->img_n + 1);
+ a->out = (stbi_uc *)stbi__malloc_mad3(x, y, output_bytes, 0); // extra bytes to write off the end into
+ if (!a->out) return stbi__err("outofmem", "Out of memory");
- if (!stbi__mad3sizes_valid(img_n, x, depth, 7)) return stbi__err("too large", "Corrupt PNG");
- img_width_bytes = (((img_n * x * depth) + 7) >> 3);
- img_len = (img_width_bytes + 1) * y;
+ if (!stbi__mad3sizes_valid(img_n, x, depth, 7)) return stbi__err("too large", "Corrupt PNG");
+ img_width_bytes = (img_n * x * depth + 7) >> 3;
+ img_len = (img_width_bytes + 1) * y;
- // we used to check for exact match between raw_len and img_len on non-interlaced PNGs,
- // but issue #276 reported a PNG in the wild that had extra data at the end (all zeros),
- // so just check for raw_len < img_len always.
- if (raw_len < img_len) return stbi__err("not enough pixels","Corrupt PNG");
+ // we used to check for exact match between raw_len and img_len on non-interlaced PNGs,
+ // but issue #276 reported a PNG in the wild that had extra data at the end (all zeros),
+ // so just check for raw_len < img_len always.
+ if (raw_len < img_len) return stbi__err("not enough pixels", "Corrupt PNG");
- for (j=0; j < y; ++j) {
- stbi_uc *cur = a->out + stride*j;
- stbi_uc *prior;
- int filter = *raw++;
+ for (j = 0; j < y; ++j)
+ {
+ stbi_uc *cur = a->out + stride * j;
+ stbi_uc *prior;
+ int filter = *raw++;
- if (filter > 4)
- return stbi__err("invalid filter","Corrupt PNG");
+ if (filter > 4)
+ return stbi__err("invalid filter", "Corrupt PNG");
- if (depth < 8) {
- STBI_ASSERT(img_width_bytes <= x);
- cur += x*out_n - img_width_bytes; // store output to the rightmost img_len bytes, so we can decode in place
- filter_bytes = 1;
- width = img_width_bytes;
- }
- prior = cur - stride; // bugfix: need to compute this after 'cur +=' computation above
+ if (depth < 8)
+ {
+ STBI_ASSERT(img_width_bytes <= x);
+ cur += x * out_n - img_width_bytes; // store output to the rightmost img_len bytes, so we can decode in place
+ filter_bytes = 1;
+ width = img_width_bytes;
+ }
+ prior = cur - stride; // bugfix: need to compute this after 'cur +=' computation above
- // if first row, use special filter that doesn't sample previous row
- if (j == 0) filter = first_row_filter[filter];
+ // if first row, use special filter that doesn't sample previous row
+ if (j == 0) filter = first_row_filter[filter];
- // handle first byte explicitly
- for (k=0; k < filter_bytes; ++k) {
- switch (filter) {
- case STBI__F_none : cur[k] = raw[k]; break;
- case STBI__F_sub : cur[k] = raw[k]; break;
- case STBI__F_up : cur[k] = STBI__BYTECAST(raw[k] + prior[k]); break;
- case STBI__F_avg : cur[k] = STBI__BYTECAST(raw[k] + (prior[k]>>1)); break;
- case STBI__F_paeth : cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(0,prior[k],0)); break;
- case STBI__F_avg_first : cur[k] = raw[k]; break;
- case STBI__F_paeth_first: cur[k] = raw[k]; break;
- }
- }
+ // handle first byte explicitly
+ for (k = 0; k < filter_bytes; ++k)
+ {
+ switch (filter)
+ {
+ case STBI__F_none:
+ cur[k] = raw[k];
+ break;
+ case STBI__F_sub:
+ cur[k] = raw[k];
+ break;
+ case STBI__F_up:
+ cur[k] = STBI__BYTECAST(raw[k] + prior[k]);
+ break;
+ case STBI__F_avg:
+ cur[k] = STBI__BYTECAST(raw[k] + (prior[k] >> 1));
+ break;
+ case STBI__F_paeth:
+ cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(0, prior[k], 0));
+ break;
+ case STBI__F_avg_first:
+ cur[k] = raw[k];
+ break;
+ case STBI__F_paeth_first:
+ cur[k] = raw[k];
+ break;
+ }
+ }
- if (depth == 8) {
- if (img_n != out_n)
- cur[img_n] = 255; // first pixel
- raw += img_n;
- cur += out_n;
- prior += out_n;
- } else if (depth == 16) {
- if (img_n != out_n) {
- cur[filter_bytes] = 255; // first pixel top byte
- cur[filter_bytes+1] = 255; // first pixel bottom byte
- }
- raw += filter_bytes;
- cur += output_bytes;
- prior += output_bytes;
- } else {
- raw += 1;
- cur += 1;
- prior += 1;
- }
+ if (depth == 8)
+ {
+ if (img_n != out_n)
+ cur[img_n] = 255; // first pixel
+ raw += img_n;
+ cur += out_n;
+ prior += out_n;
+ }
+ else if (depth == 16)
+ {
+ if (img_n != out_n)
+ {
+ cur[filter_bytes] = 255; // first pixel top byte
+ cur[filter_bytes + 1] = 255; // first pixel bottom byte
+ }
+ raw += filter_bytes;
+ cur += output_bytes;
+ prior += output_bytes;
+ }
+ else
+ {
+ raw += 1;
+ cur += 1;
+ prior += 1;
+ }
- // this is a little gross, so that we don't switch per-pixel or per-component
- if (depth < 8 || img_n == out_n) {
- int nk = (width - 1)*filter_bytes;
- #define STBI__CASE(f) \
+ // this is a little gross, so that we don't switch per-pixel or per-component
+ if (depth < 8 || img_n == out_n)
+ {
+ int nk = (width - 1) * filter_bytes;
+ #define STBI__CASE(f) \
case f: \
for (k=0; k < nk; ++k)
- switch (filter) {
- // "none" filter turns into a memcpy here; make that explicit.
- case STBI__F_none: memcpy(cur, raw, nk); break;
- STBI__CASE(STBI__F_sub) { cur[k] = STBI__BYTECAST(raw[k] + cur[k-filter_bytes]); } break;
- STBI__CASE(STBI__F_up) { cur[k] = STBI__BYTECAST(raw[k] + prior[k]); } break;
- STBI__CASE(STBI__F_avg) { cur[k] = STBI__BYTECAST(raw[k] + ((prior[k] + cur[k-filter_bytes])>>1)); } break;
- STBI__CASE(STBI__F_paeth) { cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k-filter_bytes],prior[k],prior[k-filter_bytes])); } break;
- STBI__CASE(STBI__F_avg_first) { cur[k] = STBI__BYTECAST(raw[k] + (cur[k-filter_bytes] >> 1)); } break;
- STBI__CASE(STBI__F_paeth_first) { cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k-filter_bytes],0,0)); } break;
- }
- #undef STBI__CASE
- raw += nk;
- } else {
- STBI_ASSERT(img_n+1 == out_n);
- #define STBI__CASE(f) \
+ switch (filter)
+ {
+ // "none" filter turns into a memcpy here; make that explicit.
+ case STBI__F_none:
+ memcpy(cur, raw, nk);
+ break;
+ STBI__CASE(STBI__F_sub)
+ {
+ cur[k] = STBI__BYTECAST(raw[k] + cur[k - filter_bytes]);
+ }
+ break;
+ STBI__CASE(STBI__F_up)
+ {
+ cur[k] = STBI__BYTECAST(raw[k] + prior[k]);
+ }
+ break;
+ STBI__CASE(STBI__F_avg)
+ {
+ cur[k] = STBI__BYTECAST(raw[k] + ((prior[k] + cur[k - filter_bytes]) >> 1));
+ }
+ break;
+ STBI__CASE(STBI__F_paeth)
+ {
+ cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k - filter_bytes], prior[k], prior[k - filter_bytes]));
+ }
+ break;
+ STBI__CASE(STBI__F_avg_first)
+ {
+ cur[k] = STBI__BYTECAST(raw[k] + (cur[k - filter_bytes] >> 1));
+ }
+ break;
+ STBI__CASE(STBI__F_paeth_first)
+ {
+ cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k - filter_bytes], 0, 0));
+ }
+ break;
+ }
+ #undef STBI__CASE
+ raw += nk;
+ }
+ else
+ {
+ STBI_ASSERT(img_n + 1 == out_n);
+ #define STBI__CASE(f) \
case f: \
for (i=x-1; i >= 1; --i, cur[filter_bytes]=255,raw+=filter_bytes,cur+=output_bytes,prior+=output_bytes) \
for (k=0; k < filter_bytes; ++k)
- switch (filter) {
- STBI__CASE(STBI__F_none) { cur[k] = raw[k]; } break;
- STBI__CASE(STBI__F_sub) { cur[k] = STBI__BYTECAST(raw[k] + cur[k- output_bytes]); } break;
- STBI__CASE(STBI__F_up) { cur[k] = STBI__BYTECAST(raw[k] + prior[k]); } break;
- STBI__CASE(STBI__F_avg) { cur[k] = STBI__BYTECAST(raw[k] + ((prior[k] + cur[k- output_bytes])>>1)); } break;
- STBI__CASE(STBI__F_paeth) { cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k- output_bytes],prior[k],prior[k- output_bytes])); } break;
- STBI__CASE(STBI__F_avg_first) { cur[k] = STBI__BYTECAST(raw[k] + (cur[k- output_bytes] >> 1)); } break;
- STBI__CASE(STBI__F_paeth_first) { cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k- output_bytes],0,0)); } break;
- }
- #undef STBI__CASE
-
- // the loop above sets the high byte of the pixels' alpha, but for
- // 16 bit png files we also need the low byte set. we'll do that here.
- if (depth == 16) {
- cur = a->out + stride*j; // start at the beginning of the row again
- for (i=0; i < x; ++i,cur+=output_bytes) {
- cur[filter_bytes+1] = 255;
+ switch (filter)
+ {
+ STBI__CASE(STBI__F_none)
+ {
+ cur[k] = raw[k];
+ }
+ break;
+ STBI__CASE(STBI__F_sub)
+ {
+ cur[k] = STBI__BYTECAST(raw[k] + cur[k - output_bytes]);
+ }
+ break;
+ STBI__CASE(STBI__F_up)
+ {
+ cur[k] = STBI__BYTECAST(raw[k] + prior[k]);
+ }
+ break;
+ STBI__CASE(STBI__F_avg)
+ {
+ cur[k] = STBI__BYTECAST(raw[k] + ((prior[k] + cur[k - output_bytes]) >> 1));
+ }
+ break;
+ STBI__CASE(STBI__F_paeth)
+ {
+ cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k - output_bytes], prior[k], prior[k - output_bytes]));
+ }
+ break;
+ STBI__CASE(STBI__F_avg_first)
+ {
+ cur[k] = STBI__BYTECAST(raw[k] + (cur[k - output_bytes] >> 1));
+ }
+ break;
+ STBI__CASE(STBI__F_paeth_first)
+ {
+ cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k - output_bytes], 0, 0));
+ }
+ break;
}
- }
- }
- }
+ #undef STBI__CASE
- // we make a separate pass to expand bits to pixels; for performance,
- // this could run two scanlines behind the above code, so it won't
- // intefere with filtering but will still be in the cache.
- if (depth < 8) {
- for (j=0; j < y; ++j) {
- stbi_uc *cur = a->out + stride*j;
- stbi_uc *in = a->out + stride*j + x*out_n - img_width_bytes;
- // unpack 1/2/4-bit into a 8-bit buffer. allows us to keep the common 8-bit path optimal at minimal cost for 1/2/4-bit
- // png guarante byte alignment, if width is not multiple of 8/4/2 we'll decode dummy trailing data that will be skipped in the later loop
- stbi_uc scale = (color == 0) ? stbi__depth_scale_table[depth] : 1; // scale grayscale values to 0..255 range
-
- // note that the final byte might overshoot and write more data than desired.
- // we can allocate enough data that this never writes out of memory, but it
- // could also overwrite the next scanline. can it overwrite non-empty data
- // on the next scanline? yes, consider 1-pixel-wide scanlines with 1-bit-per-pixel.
- // so we need to explicitly clamp the final ones
-
- if (depth == 4) {
- for (k=x*img_n; k >= 2; k-=2, ++in) {
- *cur++ = scale * ((*in >> 4) );
- *cur++ = scale * ((*in ) & 0x0f);
+ // the loop above sets the high byte of the pixels' alpha, but for
+ // 16 bit png files we also need the low byte set. we'll do that here.
+ if (depth == 16)
+ {
+ cur = a->out + stride * j; // start at the beginning of the row again
+ for (i = 0; i < x; ++i, cur += output_bytes)
+ {
+ cur[filter_bytes + 1] = 255;
+ }
}
- if (k > 0) *cur++ = scale * ((*in >> 4) );
- } else if (depth == 2) {
- for (k=x*img_n; k >= 4; k-=4, ++in) {
- *cur++ = scale * ((*in >> 6) );
- *cur++ = scale * ((*in >> 4) & 0x03);
- *cur++ = scale * ((*in >> 2) & 0x03);
- *cur++ = scale * ((*in ) & 0x03);
- }
- if (k > 0) *cur++ = scale * ((*in >> 6) );
- if (k > 1) *cur++ = scale * ((*in >> 4) & 0x03);
- if (k > 2) *cur++ = scale * ((*in >> 2) & 0x03);
- } else if (depth == 1) {
- for (k=x*img_n; k >= 8; k-=8, ++in) {
- *cur++ = scale * ((*in >> 7) );
- *cur++ = scale * ((*in >> 6) & 0x01);
- *cur++ = scale * ((*in >> 5) & 0x01);
- *cur++ = scale * ((*in >> 4) & 0x01);
- *cur++ = scale * ((*in >> 3) & 0x01);
- *cur++ = scale * ((*in >> 2) & 0x01);
- *cur++ = scale * ((*in >> 1) & 0x01);
- *cur++ = scale * ((*in ) & 0x01);
- }
- if (k > 0) *cur++ = scale * ((*in >> 7) );
- if (k > 1) *cur++ = scale * ((*in >> 6) & 0x01);
- if (k > 2) *cur++ = scale * ((*in >> 5) & 0x01);
- if (k > 3) *cur++ = scale * ((*in >> 4) & 0x01);
- if (k > 4) *cur++ = scale * ((*in >> 3) & 0x01);
- if (k > 5) *cur++ = scale * ((*in >> 2) & 0x01);
- if (k > 6) *cur++ = scale * ((*in >> 1) & 0x01);
- }
- if (img_n != out_n) {
- int q;
- // insert alpha = 255
- cur = a->out + stride*j;
- if (img_n == 1) {
- for (q=x-1; q >= 0; --q) {
- cur[q*2+1] = 255;
- cur[q*2+0] = cur[q];
- }
- } else {
- STBI_ASSERT(img_n == 3);
- for (q=x-1; q >= 0; --q) {
- cur[q*4+3] = 255;
- cur[q*4+2] = cur[q*3+2];
- cur[q*4+1] = cur[q*3+1];
- cur[q*4+0] = cur[q*3+0];
- }
- }
- }
- }
- } else if (depth == 16) {
- // force the image data from big-endian to platform-native.
- // this is done in a separate pass due to the decoding relying
- // on the data being untouched, but could probably be done
- // per-line during decode if care is taken.
- stbi_uc *cur = a->out;
- stbi__uint16 *cur16 = (stbi__uint16*)cur;
+ }
+ }
- for(i=0; i < x*y*out_n; ++i,cur16++,cur+=2) {
- *cur16 = (cur[0] << 8) | cur[1];
- }
- }
+ // we make a separate pass to expand bits to pixels; for performance,
+ // this could run two scanlines behind the above code, so it won't
+ // intefere with filtering but will still be in the cache.
+ if (depth < 8)
+ {
+ for (j = 0; j < y; ++j)
+ {
+ stbi_uc *cur = a->out + stride * j;
+ stbi_uc *in = a->out + stride * j + x * out_n - img_width_bytes;
+ // unpack 1/2/4-bit into a 8-bit buffer. allows us to keep the common 8-bit path optimal at minimal cost for 1/2/4-bit
+ // png guarante byte alignment, if width is not multiple of 8/4/2 we'll decode dummy trailing data that will be skipped in the later loop
+ stbi_uc scale = color == 0 ? stbi__depth_scale_table[depth] : 1; // scale grayscale values to 0..255 range
- return 1;
+ // note that the final byte might overshoot and write more data than desired.
+ // we can allocate enough data that this never writes out of memory, but it
+ // could also overwrite the next scanline. can it overwrite non-empty data
+ // on the next scanline? yes, consider 1-pixel-wide scanlines with 1-bit-per-pixel.
+ // so we need to explicitly clamp the final ones
+
+ if (depth == 4)
+ {
+ for (k = x * img_n; k >= 2; k -= 2, ++in)
+ {
+ *cur++ = scale * (*in >> 4);
+ *cur++ = scale * (*in & 0x0f);
+ }
+ if (k > 0) *cur++ = scale * (*in >> 4);
+ }
+ else if (depth == 2)
+ {
+ for (k = x * img_n; k >= 4; k -= 4, ++in)
+ {
+ *cur++ = scale * (*in >> 6);
+ *cur++ = scale * (*in >> 4 & 0x03);
+ *cur++ = scale * (*in >> 2 & 0x03);
+ *cur++ = scale * (*in & 0x03);
+ }
+ if (k > 0) *cur++ = scale * (*in >> 6);
+ if (k > 1) *cur++ = scale * (*in >> 4 & 0x03);
+ if (k > 2) *cur++ = scale * (*in >> 2 & 0x03);
+ }
+ else if (depth == 1)
+ {
+ for (k = x * img_n; k >= 8; k -= 8, ++in)
+ {
+ *cur++ = scale * (*in >> 7);
+ *cur++ = scale * (*in >> 6 & 0x01);
+ *cur++ = scale * (*in >> 5 & 0x01);
+ *cur++ = scale * (*in >> 4 & 0x01);
+ *cur++ = scale * (*in >> 3 & 0x01);
+ *cur++ = scale * (*in >> 2 & 0x01);
+ *cur++ = scale * (*in >> 1 & 0x01);
+ *cur++ = scale * (*in & 0x01);
+ }
+ if (k > 0) *cur++ = scale * (*in >> 7);
+ if (k > 1) *cur++ = scale * (*in >> 6 & 0x01);
+ if (k > 2) *cur++ = scale * (*in >> 5 & 0x01);
+ if (k > 3) *cur++ = scale * (*in >> 4 & 0x01);
+ if (k > 4) *cur++ = scale * (*in >> 3 & 0x01);
+ if (k > 5) *cur++ = scale * (*in >> 2 & 0x01);
+ if (k > 6) *cur++ = scale * (*in >> 1 & 0x01);
+ }
+ if (img_n != out_n)
+ {
+ int q;
+ // insert alpha = 255
+ cur = a->out + stride * j;
+ if (img_n == 1)
+ {
+ for (q = x - 1; q >= 0; --q)
+ {
+ cur[q * 2 + 1] = 255;
+ cur[q * 2 + 0] = cur[q];
+ }
+ }
+ else
+ {
+ STBI_ASSERT(img_n == 3);
+ for (q = x - 1; q >= 0; --q)
+ {
+ cur[q * 4 + 3] = 255;
+ cur[q * 4 + 2] = cur[q * 3 + 2];
+ cur[q * 4 + 1] = cur[q * 3 + 1];
+ cur[q * 4 + 0] = cur[q * 3 + 0];
+ }
+ }
+ }
+ }
+ }
+ else if (depth == 16)
+ {
+ // force the image data from big-endian to platform-native.
+ // this is done in a separate pass due to the decoding relying
+ // on the data being untouched, but could probably be done
+ // per-line during decode if care is taken.
+ stbi_uc *cur = a->out;
+ stbi__uint16 *cur16 = (stbi__uint16 *)cur;
+
+ for (i = 0; i < x * y * out_n; ++i, cur16++, cur += 2)
+ {
+ *cur16 = cur[0] << 8 | cur[1];
+ }
+ }
+
+ return 1;
}
static int stbi__create_png_image(stbi__png *a, stbi_uc *image_data, stbi__uint32 image_data_len, int out_n, int depth, int color, int interlaced)
{
- int bytes = (depth == 16 ? 2 : 1);
- int out_bytes = out_n * bytes;
- stbi_uc *final;
- int p;
- if (!interlaced)
- return stbi__create_png_image_raw(a, image_data, image_data_len, out_n, a->s->img_x, a->s->img_y, depth, color);
+ int bytes = depth == 16 ? 2 : 1;
+ int out_bytes = out_n * bytes;
+ stbi_uc *final;
+ int p;
+ if (!interlaced)
+ return stbi__create_png_image_raw(a, image_data, image_data_len, out_n, a->s->img_x, a->s->img_y, depth, color);
- // de-interlacing
- final = (stbi_uc *) stbi__malloc_mad3(a->s->img_x, a->s->img_y, out_bytes, 0);
- for (p=0; p < 7; ++p) {
- int xorig[] = { 0,4,0,2,0,1,0 };
- int yorig[] = { 0,0,4,0,2,0,1 };
- int xspc[] = { 8,8,4,4,2,2,1 };
- int yspc[] = { 8,8,8,4,4,2,2 };
- int i,j,x,y;
- // pass1_x[4] = 0, pass1_x[5] = 1, pass1_x[12] = 1
- x = (a->s->img_x - xorig[p] + xspc[p]-1) / xspc[p];
- y = (a->s->img_y - yorig[p] + yspc[p]-1) / yspc[p];
- if (x && y) {
- stbi__uint32 img_len = ((((a->s->img_n * x * depth) + 7) >> 3) + 1) * y;
- if (!stbi__create_png_image_raw(a, image_data, image_data_len, out_n, x, y, depth, color)) {
- STBI_FREE(final);
- return 0;
- }
- for (j=0; j < y; ++j) {
- for (i=0; i < x; ++i) {
- int out_y = j*yspc[p]+yorig[p];
- int out_x = i*xspc[p]+xorig[p];
- memcpy(final + out_y*a->s->img_x*out_bytes + out_x*out_bytes,
- a->out + (j*x+i)*out_bytes, out_bytes);
+ // de-interlacing
+ final = (stbi_uc *)stbi__malloc_mad3(a->s->img_x, a->s->img_y, out_bytes, 0);
+ for (p = 0; p < 7; ++p)
+ {
+ int xorig[] = {0, 4, 0, 2, 0, 1, 0};
+ int yorig[] = {0, 0, 4, 0, 2, 0, 1};
+ int xspc[] = {8, 8, 4, 4, 2, 2, 1};
+ int yspc[] = {8, 8, 8, 4, 4, 2, 2};
+ int i, j, x, y;
+ // pass1_x[4] = 0, pass1_x[5] = 1, pass1_x[12] = 1
+ x = (a->s->img_x - xorig[p] + xspc[p] - 1) / xspc[p];
+ y = (a->s->img_y - yorig[p] + yspc[p] - 1) / yspc[p];
+ if (x && y)
+ {
+ stbi__uint32 img_len = (((a->s->img_n * x * depth + 7) >> 3) + 1) * y;
+ if (!stbi__create_png_image_raw(a, image_data, image_data_len, out_n, x, y, depth, color))
+ {
+ STBI_FREE(final);
+ return 0;
}
- }
- STBI_FREE(a->out);
- image_data += img_len;
- image_data_len -= img_len;
- }
- }
- a->out = final;
+ for (j = 0; j < y; ++j)
+ {
+ for (i = 0; i < x; ++i)
+ {
+ int out_y = j * yspc[p] + yorig[p];
+ int out_x = i * xspc[p] + xorig[p];
+ memcpy(final + out_y * a->s->img_x * out_bytes + out_x * out_bytes,
+ a->out + (j * x + i) * out_bytes, out_bytes);
+ }
+ }
+ STBI_FREE(a->out);
+ image_data += img_len;
+ image_data_len -= img_len;
+ }
+ }
+ a->out = final;
- return 1;
+ return 1;
}
static int stbi__compute_transparency(stbi__png *z, stbi_uc tc[3], int out_n)
{
- stbi__context *s = z->s;
- stbi__uint32 i, pixel_count = s->img_x * s->img_y;
- stbi_uc *p = z->out;
+ stbi__context *s = z->s;
+ stbi__uint32 i, pixel_count = s->img_x * s->img_y;
+ stbi_uc *p = z->out;
- // compute color-based transparency, assuming we've
- // already got 255 as the alpha value in the output
- STBI_ASSERT(out_n == 2 || out_n == 4);
+ // compute color-based transparency, assuming we've
+ // already got 255 as the alpha value in the output
+ STBI_ASSERT(out_n == 2 || out_n == 4);
- if (out_n == 2) {
- for (i=0; i < pixel_count; ++i) {
- p[1] = (p[0] == tc[0] ? 0 : 255);
- p += 2;
- }
- } else {
- for (i=0; i < pixel_count; ++i) {
- if (p[0] == tc[0] && p[1] == tc[1] && p[2] == tc[2])
- p[3] = 0;
- p += 4;
- }
- }
- return 1;
+ if (out_n == 2)
+ {
+ for (i = 0; i < pixel_count; ++i)
+ {
+ p[1] = p[0] == tc[0] ? 0 : 255;
+ p += 2;
+ }
+ }
+ else
+ {
+ for (i = 0; i < pixel_count; ++i)
+ {
+ if (p[0] == tc[0] && p[1] == tc[1] && p[2] == tc[2])
+ p[3] = 0;
+ p += 4;
+ }
+ }
+ return 1;
}
static int stbi__compute_transparency16(stbi__png *z, stbi__uint16 tc[3], int out_n)
{
- stbi__context *s = z->s;
- stbi__uint32 i, pixel_count = s->img_x * s->img_y;
- stbi__uint16 *p = (stbi__uint16*) z->out;
+ stbi__context *s = z->s;
+ stbi__uint32 i, pixel_count = s->img_x * s->img_y;
+ stbi__uint16 *p = (stbi__uint16 *)z->out;
- // compute color-based transparency, assuming we've
- // already got 65535 as the alpha value in the output
- STBI_ASSERT(out_n == 2 || out_n == 4);
+ // compute color-based transparency, assuming we've
+ // already got 65535 as the alpha value in the output
+ STBI_ASSERT(out_n == 2 || out_n == 4);
- if (out_n == 2) {
- for (i = 0; i < pixel_count; ++i) {
- p[1] = (p[0] == tc[0] ? 0 : 65535);
- p += 2;
- }
- } else {
- for (i = 0; i < pixel_count; ++i) {
- if (p[0] == tc[0] && p[1] == tc[1] && p[2] == tc[2])
- p[3] = 0;
- p += 4;
- }
- }
- return 1;
+ if (out_n == 2)
+ {
+ for (i = 0; i < pixel_count; ++i)
+ {
+ p[1] = p[0] == tc[0] ? 0 : 65535;
+ p += 2;
+ }
+ }
+ else
+ {
+ for (i = 0; i < pixel_count; ++i)
+ {
+ if (p[0] == tc[0] && p[1] == tc[1] && p[2] == tc[2])
+ p[3] = 0;
+ p += 4;
+ }
+ }
+ return 1;
}
static int stbi__expand_png_palette(stbi__png *a, stbi_uc *palette, int len, int pal_img_n)
{
- stbi__uint32 i, pixel_count = a->s->img_x * a->s->img_y;
- stbi_uc *p, *temp_out, *orig = a->out;
+ stbi__uint32 i, pixel_count = a->s->img_x * a->s->img_y;
+ stbi_uc *p, *temp_out, *orig = a->out;
- p = (stbi_uc *) stbi__malloc_mad2(pixel_count, pal_img_n, 0);
- if (p == NULL) return stbi__err("outofmem", "Out of memory");
+ p = (stbi_uc *)stbi__malloc_mad2(pixel_count, pal_img_n, 0);
+ if (p == NULL) return stbi__err("outofmem", "Out of memory");
- // between here and free(out) below, exitting would leak
- temp_out = p;
+ // between here and free(out) below, exitting would leak
+ temp_out = p;
- if (pal_img_n == 3) {
- for (i=0; i < pixel_count; ++i) {
- int n = orig[i]*4;
- p[0] = palette[n ];
- p[1] = palette[n+1];
- p[2] = palette[n+2];
- p += 3;
- }
- } else {
- for (i=0; i < pixel_count; ++i) {
- int n = orig[i]*4;
- p[0] = palette[n ];
- p[1] = palette[n+1];
- p[2] = palette[n+2];
- p[3] = palette[n+3];
- p += 4;
- }
- }
- STBI_FREE(a->out);
- a->out = temp_out;
+ if (pal_img_n == 3)
+ {
+ for (i = 0; i < pixel_count; ++i)
+ {
+ int n = orig[i] * 4;
+ p[0] = palette[n];
+ p[1] = palette[n + 1];
+ p[2] = palette[n + 2];
+ p += 3;
+ }
+ }
+ else
+ {
+ for (i = 0; i < pixel_count; ++i)
+ {
+ int n = orig[i] * 4;
+ p[0] = palette[n];
+ p[1] = palette[n + 1];
+ p[2] = palette[n + 2];
+ p[3] = palette[n + 3];
+ p += 4;
+ }
+ }
+ STBI_FREE(a->out);
+ a->out = temp_out;
- STBI_NOTUSED(len);
+ STBI_NOTUSED(len);
- return 1;
+ return 1;
}
static int stbi__unpremultiply_on_load = 0;
@@ -4675,306 +5287,370 @@ static int stbi__de_iphone_flag = 0;
STBIDEF void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply)
{
- stbi__unpremultiply_on_load = flag_true_if_should_unpremultiply;
+ stbi__unpremultiply_on_load = flag_true_if_should_unpremultiply;
}
STBIDEF void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert)
{
- stbi__de_iphone_flag = flag_true_if_should_convert;
+ stbi__de_iphone_flag = flag_true_if_should_convert;
}
static void stbi__de_iphone(stbi__png *z)
{
- stbi__context *s = z->s;
- stbi__uint32 i, pixel_count = s->img_x * s->img_y;
- stbi_uc *p = z->out;
+ stbi__context *s = z->s;
+ stbi__uint32 i, pixel_count = s->img_x * s->img_y;
+ stbi_uc *p = z->out;
- if (s->img_out_n == 3) { // convert bgr to rgb
- for (i=0; i < pixel_count; ++i) {
- stbi_uc t = p[0];
- p[0] = p[2];
- p[2] = t;
- p += 3;
- }
- } else {
- STBI_ASSERT(s->img_out_n == 4);
- if (stbi__unpremultiply_on_load) {
- // convert bgr to rgb and unpremultiply
- for (i=0; i < pixel_count; ++i) {
- stbi_uc a = p[3];
- stbi_uc t = p[0];
- if (a) {
- stbi_uc half = a / 2;
- p[0] = (p[2] * 255 + half) / a;
- p[1] = (p[1] * 255 + half) / a;
- p[2] = ( t * 255 + half) / a;
- } else {
- p[0] = p[2];
- p[2] = t;
- }
- p += 4;
- }
- } else {
- // convert bgr to rgb
- for (i=0; i < pixel_count; ++i) {
+ if (s->img_out_n == 3)
+ { // convert bgr to rgb
+ for (i = 0; i < pixel_count; ++i)
+ {
stbi_uc t = p[0];
p[0] = p[2];
p[2] = t;
- p += 4;
- }
- }
- }
+ p += 3;
+ }
+ }
+ else
+ {
+ STBI_ASSERT(s->img_out_n == 4);
+ if (stbi__unpremultiply_on_load)
+ {
+ // convert bgr to rgb and unpremultiply
+ for (i = 0; i < pixel_count; ++i)
+ {
+ stbi_uc a = p[3];
+ stbi_uc t = p[0];
+ if (a)
+ {
+ stbi_uc half = a / 2;
+ p[0] = (p[2] * 255 + half) / a;
+ p[1] = (p[1] * 255 + half) / a;
+ p[2] = (t * 255 + half) / a;
+ }
+ else
+ {
+ p[0] = p[2];
+ p[2] = t;
+ }
+ p += 4;
+ }
+ }
+ else
+ {
+ // convert bgr to rgb
+ for (i = 0; i < pixel_count; ++i)
+ {
+ stbi_uc t = p[0];
+ p[0] = p[2];
+ p[2] = t;
+ p += 4;
+ }
+ }
+ }
}
#define STBI__PNG_TYPE(a,b,c,d) (((unsigned) (a) << 24) + ((unsigned) (b) << 16) + ((unsigned) (c) << 8) + (unsigned) (d))
static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp)
{
- stbi_uc palette[1024], pal_img_n=0;
- stbi_uc has_trans=0, tc[3];
- stbi__uint16 tc16[3];
- stbi__uint32 ioff=0, idata_limit=0, i, pal_len=0;
- int first=1,k,interlace=0, color=0, is_iphone=0;
- stbi__context *s = z->s;
+ stbi_uc palette[1024], pal_img_n = 0;
+ stbi_uc has_trans = 0, tc[3];
+ stbi__uint16 tc16[3];
+ stbi__uint32 ioff = 0, idata_limit = 0, i, pal_len = 0;
+ int first = 1, k, interlace = 0, color = 0, is_iphone = 0;
+ stbi__context *s = z->s;
- z->expanded = NULL;
- z->idata = NULL;
- z->out = NULL;
+ z->expanded = NULL;
+ z->idata = NULL;
+ z->out = NULL;
- if (!stbi__check_png_header(s)) return 0;
+ if (!stbi__check_png_header(s)) return 0;
- if (scan == STBI__SCAN_type) return 1;
+ if (scan == STBI__SCAN_type) return 1;
- for (;;) {
- stbi__pngchunk c = stbi__get_chunk_header(s);
- switch (c.type) {
- case STBI__PNG_TYPE('C','g','B','I'):
- is_iphone = 1;
- stbi__skip(s, c.length);
- break;
- case STBI__PNG_TYPE('I','H','D','R'): {
- int comp,filter;
- if (!first) return stbi__err("multiple IHDR","Corrupt PNG");
- first = 0;
- if (c.length != 13) return stbi__err("bad IHDR len","Corrupt PNG");
- s->img_x = stbi__get32be(s); if (s->img_x > (1 << 24)) return stbi__err("too large","Very large image (corrupt?)");
- s->img_y = stbi__get32be(s); if (s->img_y > (1 << 24)) return stbi__err("too large","Very large image (corrupt?)");
- z->depth = stbi__get8(s); if (z->depth != 1 && z->depth != 2 && z->depth != 4 && z->depth != 8 && z->depth != 16) return stbi__err("1/2/4/8/16-bit only","PNG not supported: 1/2/4/8/16-bit only");
- color = stbi__get8(s); if (color > 6) return stbi__err("bad ctype","Corrupt PNG");
- if (color == 3 && z->depth == 16) return stbi__err("bad ctype","Corrupt PNG");
- if (color == 3) pal_img_n = 3; else if (color & 1) return stbi__err("bad ctype","Corrupt PNG");
- comp = stbi__get8(s); if (comp) return stbi__err("bad comp method","Corrupt PNG");
- filter= stbi__get8(s); if (filter) return stbi__err("bad filter method","Corrupt PNG");
- interlace = stbi__get8(s); if (interlace>1) return stbi__err("bad interlace method","Corrupt PNG");
- if (!s->img_x || !s->img_y) return stbi__err("0-pixel image","Corrupt PNG");
- if (!pal_img_n) {
- s->img_n = (color & 2 ? 3 : 1) + (color & 4 ? 1 : 0);
- if ((1 << 30) / s->img_x / s->img_n < s->img_y) return stbi__err("too large", "Image too large to decode");
- if (scan == STBI__SCAN_header) return 1;
- } else {
- // if paletted, then pal_n is our final components, and
- // img_n is # components to decompress/filter.
- s->img_n = 1;
- if ((1 << 30) / s->img_x / 4 < s->img_y) return stbi__err("too large","Corrupt PNG");
- // if SCAN_header, have to scan to see if we have a tRNS
+ for (;;)
+ {
+ stbi__pngchunk c = stbi__get_chunk_header(s);
+ switch (c.type)
+ {
+ case STBI__PNG_TYPE('C', 'g', 'B', 'I'):
+ is_iphone = 1;
+ stbi__skip(s, c.length);
+ break;
+ case STBI__PNG_TYPE('I', 'H', 'D', 'R'):
+ {
+ int comp, filter;
+ if (!first) return stbi__err("multiple IHDR", "Corrupt PNG");
+ first = 0;
+ if (c.length != 13) return stbi__err("bad IHDR len", "Corrupt PNG");
+ s->img_x = stbi__get32be(s);
+ if (s->img_x > 1 << 24) return stbi__err("too large", "Very large image (corrupt?)");
+ s->img_y = stbi__get32be(s);
+ if (s->img_y > 1 << 24) return stbi__err("too large", "Very large image (corrupt?)");
+ z->depth = stbi__get8(s);
+ if (z->depth != 1 && z->depth != 2 && z->depth != 4 && z->depth != 8 && z->depth != 16) return stbi__err("1/2/4/8/16-bit only", "PNG not supported: 1/2/4/8/16-bit only");
+ color = stbi__get8(s);
+ if (color > 6) return stbi__err("bad ctype", "Corrupt PNG");
+ if (color == 3 && z->depth == 16) return stbi__err("bad ctype", "Corrupt PNG");
+ if (color == 3) pal_img_n = 3;
+ else if (color & 1) return stbi__err("bad ctype", "Corrupt PNG");
+ comp = stbi__get8(s);
+ if (comp) return stbi__err("bad comp method", "Corrupt PNG");
+ filter = stbi__get8(s);
+ if (filter) return stbi__err("bad filter method", "Corrupt PNG");
+ interlace = stbi__get8(s);
+ if (interlace > 1) return stbi__err("bad interlace method", "Corrupt PNG");
+ if (!s->img_x || !s->img_y) return stbi__err("0-pixel image", "Corrupt PNG");
+ if (!pal_img_n)
+ {
+ s->img_n = (color & 2 ? 3 : 1) + (color & 4 ? 1 : 0);
+ if ((1 << 30) / s->img_x / s->img_n < s->img_y) return stbi__err("too large", "Image too large to decode");
+ if (scan == STBI__SCAN_header) return 1;
+ }
+ else
+ {
+ // if paletted, then pal_n is our final components, and
+ // img_n is # components to decompress/filter.
+ s->img_n = 1;
+ if ((1 << 30) / s->img_x / 4 < s->img_y) return stbi__err("too large", "Corrupt PNG");
+ // if SCAN_header, have to scan to see if we have a tRNS
+ }
+ break;
}
- break;
- }
- case STBI__PNG_TYPE('P','L','T','E'): {
- if (first) return stbi__err("first not IHDR", "Corrupt PNG");
- if (c.length > 256*3) return stbi__err("invalid PLTE","Corrupt PNG");
- pal_len = c.length / 3;
- if (pal_len * 3 != c.length) return stbi__err("invalid PLTE","Corrupt PNG");
- for (i=0; i < pal_len; ++i) {
- palette[i*4+0] = stbi__get8(s);
- palette[i*4+1] = stbi__get8(s);
- palette[i*4+2] = stbi__get8(s);
- palette[i*4+3] = 255;
+ case STBI__PNG_TYPE('P', 'L', 'T', 'E'):
+ {
+ if (first) return stbi__err("first not IHDR", "Corrupt PNG");
+ if (c.length > 256 * 3) return stbi__err("invalid PLTE", "Corrupt PNG");
+ pal_len = c.length / 3;
+ if (pal_len * 3 != c.length) return stbi__err("invalid PLTE", "Corrupt PNG");
+ for (i = 0; i < pal_len; ++i)
+ {
+ palette[i * 4 + 0] = stbi__get8(s);
+ palette[i * 4 + 1] = stbi__get8(s);
+ palette[i * 4 + 2] = stbi__get8(s);
+ palette[i * 4 + 3] = 255;
+ }
+ break;
}
- break;
- }
- case STBI__PNG_TYPE('t','R','N','S'): {
- if (first) return stbi__err("first not IHDR", "Corrupt PNG");
- if (z->idata) return stbi__err("tRNS after IDAT","Corrupt PNG");
- if (pal_img_n) {
- if (scan == STBI__SCAN_header) { s->img_n = 4; return 1; }
- if (pal_len == 0) return stbi__err("tRNS before PLTE","Corrupt PNG");
- if (c.length > pal_len) return stbi__err("bad tRNS len","Corrupt PNG");
- pal_img_n = 4;
- for (i=0; i < c.length; ++i)
- palette[i*4+3] = stbi__get8(s);
- } else {
- if (!(s->img_n & 1)) return stbi__err("tRNS with alpha","Corrupt PNG");
- if (c.length != (stbi__uint32) s->img_n*2) return stbi__err("bad tRNS len","Corrupt PNG");
- has_trans = 1;
- if (z->depth == 16) {
- for (k = 0; k < s->img_n; ++k) tc16[k] = (stbi__uint16)stbi__get16be(s); // copy the values as-is
- } else {
- for (k = 0; k < s->img_n; ++k) tc[k] = (stbi_uc)(stbi__get16be(s) & 255) * stbi__depth_scale_table[z->depth]; // non 8-bit images will be larger
- }
+ case STBI__PNG_TYPE('t', 'R', 'N', 'S'):
+ {
+ if (first) return stbi__err("first not IHDR", "Corrupt PNG");
+ if (z->idata) return stbi__err("tRNS after IDAT", "Corrupt PNG");
+ if (pal_img_n)
+ {
+ if (scan == STBI__SCAN_header)
+ {
+ s->img_n = 4;
+ return 1;
+ }
+ if (pal_len == 0) return stbi__err("tRNS before PLTE", "Corrupt PNG");
+ if (c.length > pal_len) return stbi__err("bad tRNS len", "Corrupt PNG");
+ pal_img_n = 4;
+ for (i = 0; i < c.length; ++i)
+ palette[i * 4 + 3] = stbi__get8(s);
+ }
+ else
+ {
+ if (!(s->img_n & 1)) return stbi__err("tRNS with alpha", "Corrupt PNG");
+ if (c.length != (stbi__uint32)s->img_n * 2) return stbi__err("bad tRNS len", "Corrupt PNG");
+ has_trans = 1;
+ if (z->depth == 16)
+ {
+ for (k = 0; k < s->img_n; ++k) tc16[k] = (stbi__uint16)stbi__get16be(s); // copy the values as-is
+ }
+ else
+ {
+ for (k = 0; k < s->img_n; ++k) tc[k] = (stbi_uc)(stbi__get16be(s) & 255) * stbi__depth_scale_table[z->depth]; // non 8-bit images will be larger
+ }
+ }
+ break;
}
- break;
- }
- case STBI__PNG_TYPE('I','D','A','T'): {
- if (first) return stbi__err("first not IHDR", "Corrupt PNG");
- if (pal_img_n && !pal_len) return stbi__err("no PLTE","Corrupt PNG");
- if (scan == STBI__SCAN_header) { s->img_n = pal_img_n; return 1; }
- if ((int)(ioff + c.length) < (int)ioff) return 0;
- if (ioff + c.length > idata_limit) {
- stbi__uint32 idata_limit_old = idata_limit;
- stbi_uc *p;
- if (idata_limit == 0) idata_limit = c.length > 4096 ? c.length : 4096;
- while (ioff + c.length > idata_limit)
- idata_limit *= 2;
- STBI_NOTUSED(idata_limit_old);
- p = (stbi_uc *) STBI_REALLOC_SIZED(z->idata, idata_limit_old, idata_limit); if (p == NULL) return stbi__err("outofmem", "Out of memory");
- z->idata = p;
+ case STBI__PNG_TYPE('I', 'D', 'A', 'T'):
+ {
+ if (first) return stbi__err("first not IHDR", "Corrupt PNG");
+ if (pal_img_n && !pal_len) return stbi__err("no PLTE", "Corrupt PNG");
+ if (scan == STBI__SCAN_header)
+ {
+ s->img_n = pal_img_n;
+ return 1;
+ }
+ if ((int)(ioff + c.length) < (int)ioff) return 0;
+ if (ioff + c.length > idata_limit)
+ {
+ stbi__uint32 idata_limit_old = idata_limit;
+ stbi_uc *p;
+ if (idata_limit == 0) idata_limit = c.length > 4096 ? c.length : 4096;
+ while (ioff + c.length > idata_limit)
+ idata_limit *= 2;
+ STBI_NOTUSED(idata_limit_old);
+ p = (stbi_uc *)STBI_REALLOC_SIZED(z->idata, idata_limit_old, idata_limit);
+ if (p == NULL) return stbi__err("outofmem", "Out of memory");
+ z->idata = p;
+ }
+ if (!stbi__getn(s, z->idata + ioff, c.length)) return stbi__err("outofdata", "Corrupt PNG");
+ ioff += c.length;
+ break;
}
- if (!stbi__getn(s, z->idata+ioff,c.length)) return stbi__err("outofdata","Corrupt PNG");
- ioff += c.length;
- break;
- }
- case STBI__PNG_TYPE('I','E','N','D'): {
- stbi__uint32 raw_len, bpl;
- if (first) return stbi__err("first not IHDR", "Corrupt PNG");
- if (scan != STBI__SCAN_load) return 1;
- if (z->idata == NULL) return stbi__err("no IDAT","Corrupt PNG");
- // initial guess for decoded data size to avoid unnecessary reallocs
- bpl = (s->img_x * z->depth + 7) / 8; // bytes per line, per component
- raw_len = bpl * s->img_y * s->img_n /* pixels */ + s->img_y /* filter mode per row */;
- z->expanded = (stbi_uc *) stbi_zlib_decode_malloc_guesssize_headerflag((char *) z->idata, ioff, raw_len, (int *) &raw_len, !is_iphone);
- if (z->expanded == NULL) return 0; // zlib should set error
- STBI_FREE(z->idata); z->idata = NULL;
- if ((req_comp == s->img_n+1 && req_comp != 3 && !pal_img_n) || has_trans)
- s->img_out_n = s->img_n+1;
- else
- s->img_out_n = s->img_n;
- if (!stbi__create_png_image(z, z->expanded, raw_len, s->img_out_n, z->depth, color, interlace)) return 0;
- if (has_trans) {
- if (z->depth == 16) {
- if (!stbi__compute_transparency16(z, tc16, s->img_out_n)) return 0;
- } else {
- if (!stbi__compute_transparency(z, tc, s->img_out_n)) return 0;
- }
+ case STBI__PNG_TYPE('I', 'E', 'N', 'D'):
+ {
+ stbi__uint32 raw_len, bpl;
+ if (first) return stbi__err("first not IHDR", "Corrupt PNG");
+ if (scan != STBI__SCAN_load) return 1;
+ if (z->idata == NULL) return stbi__err("no IDAT", "Corrupt PNG");
+ // initial guess for decoded data size to avoid unnecessary reallocs
+ bpl = (s->img_x * z->depth + 7) / 8; // bytes per line, per component
+ raw_len = bpl * s->img_y * s->img_n /* pixels */ + s->img_y /* filter mode per row */;
+ z->expanded = (stbi_uc *)stbi_zlib_decode_malloc_guesssize_headerflag((char *)z->idata, ioff, raw_len, (int *)&raw_len, !is_iphone);
+ if (z->expanded == NULL) return 0; // zlib should set error
+ STBI_FREE(z->idata);
+ z->idata = NULL;
+ if ((req_comp == s->img_n + 1 && req_comp != 3 && !pal_img_n) || has_trans)
+ s->img_out_n = s->img_n + 1;
+ else
+ s->img_out_n = s->img_n;
+ if (!stbi__create_png_image(z, z->expanded, raw_len, s->img_out_n, z->depth, color, interlace)) return 0;
+ if (has_trans)
+ {
+ if (z->depth == 16)
+ {
+ if (!stbi__compute_transparency16(z, tc16, s->img_out_n)) return 0;
+ }
+ else
+ {
+ if (!stbi__compute_transparency(z, tc, s->img_out_n)) return 0;
+ }
+ }
+ if (is_iphone && stbi__de_iphone_flag && s->img_out_n > 2)
+ stbi__de_iphone(z);
+ if (pal_img_n)
+ {
+ // pal_img_n == 3 or 4
+ s->img_n = pal_img_n; // record the actual colors we had
+ s->img_out_n = pal_img_n;
+ if (req_comp >= 3) s->img_out_n = req_comp;
+ if (!stbi__expand_png_palette(z, palette, pal_len, s->img_out_n))
+ return 0;
+ }
+ else if (has_trans)
+ {
+ // non-paletted image with tRNS -> source image has (constant) alpha
+ ++s->img_n;
+ }
+ STBI_FREE(z->expanded);
+ z->expanded = NULL;
+ return 1;
}
- if (is_iphone && stbi__de_iphone_flag && s->img_out_n > 2)
- stbi__de_iphone(z);
- if (pal_img_n) {
- // pal_img_n == 3 or 4
- s->img_n = pal_img_n; // record the actual colors we had
- s->img_out_n = pal_img_n;
- if (req_comp >= 3) s->img_out_n = req_comp;
- if (!stbi__expand_png_palette(z, palette, pal_len, s->img_out_n))
- return 0;
- } else if (has_trans) {
- // non-paletted image with tRNS -> source image has (constant) alpha
- ++s->img_n;
- }
- STBI_FREE(z->expanded); z->expanded = NULL;
- return 1;
- }
- default:
- // if critical, fail
- if (first) return stbi__err("first not IHDR", "Corrupt PNG");
- if ((c.type & (1 << 29)) == 0) {
- #ifndef STBI_NO_FAILURE_STRINGS
- // not threadsafe
- static char invalid_chunk[] = "XXXX PNG chunk not known";
- invalid_chunk[0] = STBI__BYTECAST(c.type >> 24);
- invalid_chunk[1] = STBI__BYTECAST(c.type >> 16);
- invalid_chunk[2] = STBI__BYTECAST(c.type >> 8);
- invalid_chunk[3] = STBI__BYTECAST(c.type >> 0);
- #endif
- return stbi__err(invalid_chunk, "PNG not supported: unknown PNG chunk type");
- }
- stbi__skip(s, c.length);
- break;
- }
- // end of PNG chunk, read and skip CRC
- stbi__get32be(s);
- }
+ default:
+ // if critical, fail
+ if (first) return stbi__err("first not IHDR", "Corrupt PNG");
+ if ((c.type & 1 << 29) == 0)
+ {
+ #ifndef STBI_NO_FAILURE_STRINGS
+ // not threadsafe
+ static char invalid_chunk[] = "XXXX PNG chunk not known";
+ invalid_chunk[0] = STBI__BYTECAST(c.type>> 24);
+ invalid_chunk[1] = STBI__BYTECAST(c.type>> 16);
+ invalid_chunk[2] = STBI__BYTECAST(c.type>> 8);
+ invalid_chunk[3] = STBI__BYTECAST(c.type>> 0);
+ #endif
+ return stbi__err(invalid_chunk, "PNG not supported: unknown PNG chunk type");
+ }
+ stbi__skip(s, c.length);
+ break;
+ }
+ // end of PNG chunk, read and skip CRC
+ stbi__get32be(s);
+ }
}
static void *stbi__do_png(stbi__png *p, int *x, int *y, int *n, int req_comp, stbi__result_info *ri)
{
- void *result=NULL;
- if (req_comp < 0 || req_comp > 4) return stbi__errpuc("bad req_comp", "Internal error");
- if (stbi__parse_png_file(p, STBI__SCAN_load, req_comp)) {
- if (p->depth < 8)
- ri->bits_per_channel = 8;
- else
- ri->bits_per_channel = p->depth;
- result = p->out;
- p->out = NULL;
- if (req_comp && req_comp != p->s->img_out_n) {
- if (ri->bits_per_channel == 8)
- result = stbi__convert_format((unsigned char *) result, p->s->img_out_n, req_comp, p->s->img_x, p->s->img_y);
- else
- result = stbi__convert_format16((stbi__uint16 *) result, p->s->img_out_n, req_comp, p->s->img_x, p->s->img_y);
- p->s->img_out_n = req_comp;
- if (result == NULL) return result;
- }
- *x = p->s->img_x;
- *y = p->s->img_y;
- if (n) *n = p->s->img_n;
- }
- STBI_FREE(p->out); p->out = NULL;
- STBI_FREE(p->expanded); p->expanded = NULL;
- STBI_FREE(p->idata); p->idata = NULL;
+ void *result = NULL;
+ if (req_comp < 0 || req_comp > 4) return stbi__errpuc("bad req_comp", "Internal error");
+ if (stbi__parse_png_file(p, STBI__SCAN_load, req_comp))
+ {
+ if (p->depth < 8)
+ ri->bits_per_channel = 8;
+ else
+ ri->bits_per_channel = p->depth;
+ result = p->out;
+ p->out = NULL;
+ if (req_comp && req_comp != p->s->img_out_n)
+ {
+ if (ri->bits_per_channel == 8)
+ result = stbi__convert_format(result, p->s->img_out_n, req_comp, p->s->img_x, p->s->img_y);
+ else
+ result = stbi__convert_format16(result, p->s->img_out_n, req_comp, p->s->img_x, p->s->img_y);
+ p->s->img_out_n = req_comp;
+ if (result == NULL) return result;
+ }
+ *x = p->s->img_x;
+ *y = p->s->img_y;
+ if (n) *n = p->s->img_n;
+ }
+ STBI_FREE(p->out);
+ p->out = NULL;
+ STBI_FREE(p->expanded);
+ p->expanded = NULL;
+ STBI_FREE(p->idata);
+ p->idata = NULL;
- return result;
+ return result;
}
static void *stbi__png_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri)
{
- stbi__png p;
- p.s = s;
- return stbi__do_png(&p, x,y,comp,req_comp, ri);
+ stbi__png p;
+ p.s = s;
+ return stbi__do_png(&p, x, y, comp, req_comp, ri);
}
static int stbi__png_test(stbi__context *s)
{
- int r;
- r = stbi__check_png_header(s);
- stbi__rewind(s);
- return r;
+ int r;
+ r = stbi__check_png_header(s);
+ stbi__rewind(s);
+ return r;
}
static int stbi__png_info_raw(stbi__png *p, int *x, int *y, int *comp)
{
- if (!stbi__parse_png_file(p, STBI__SCAN_header, 0)) {
- stbi__rewind( p->s );
- return 0;
- }
- if (x) *x = p->s->img_x;
- if (y) *y = p->s->img_y;
- if (comp) *comp = p->s->img_n;
- return 1;
+ if (!stbi__parse_png_file(p, STBI__SCAN_header, 0))
+ {
+ stbi__rewind(p->s);
+ return 0;
+ }
+ if (x) *x = p->s->img_x;
+ if (y) *y = p->s->img_y;
+ if (comp) *comp = p->s->img_n;
+ return 1;
}
static int stbi__png_info(stbi__context *s, int *x, int *y, int *comp)
{
- stbi__png p;
- p.s = s;
- return stbi__png_info_raw(&p, x, y, comp);
+ stbi__png p;
+ p.s = s;
+ return stbi__png_info_raw(&p, x, y, comp);
}
static int stbi__png_is16(stbi__context *s)
{
- stbi__png p;
- p.s = s;
- if (!stbi__png_info_raw(&p, NULL, NULL, NULL))
- return 0;
- if (p.depth != 16) {
- stbi__rewind(p.s);
- return 0;
- }
- return 1;
+ stbi__png p;
+ p.s = s;
+ if (!stbi__png_info_raw(&p, NULL, NULL, NULL))
+ return 0;
+ if (p.depth != 16)
+ {
+ stbi__rewind(p.s);
+ return 0;
+ }
+ return 1;
}
#endif
@@ -4983,48 +5659,48 @@ static int stbi__png_is16(stbi__context *s)
#ifndef STBI_NO_BMP
static int stbi__bmp_test_raw(stbi__context *s)
{
- int r;
- int sz;
- if (stbi__get8(s) != 'B') return 0;
- if (stbi__get8(s) != 'M') return 0;
- stbi__get32le(s); // discard filesize
- stbi__get16le(s); // discard reserved
- stbi__get16le(s); // discard reserved
- stbi__get32le(s); // discard data offset
- sz = stbi__get32le(s);
- r = (sz == 12 || sz == 40 || sz == 56 || sz == 108 || sz == 124);
- return r;
+ int r;
+ int sz;
+ if (stbi__get8(s) != 'B') return 0;
+ if (stbi__get8(s) != 'M') return 0;
+ stbi__get32le(s); // discard filesize
+ stbi__get16le(s); // discard reserved
+ stbi__get16le(s); // discard reserved
+ stbi__get32le(s); // discard data offset
+ sz = stbi__get32le(s);
+ r = sz == 12 || sz == 40 || sz == 56 || sz == 108 || sz == 124;
+ return r;
}
static int stbi__bmp_test(stbi__context *s)
{
- int r = stbi__bmp_test_raw(s);
- stbi__rewind(s);
- return r;
+ int r = stbi__bmp_test_raw(s);
+ stbi__rewind(s);
+ return r;
}
// returns 0..31 for the highest set bit
static int stbi__high_bit(unsigned int z)
{
- int n=0;
- if (z == 0) return -1;
- if (z >= 0x10000) n += 16, z >>= 16;
- if (z >= 0x00100) n += 8, z >>= 8;
- if (z >= 0x00010) n += 4, z >>= 4;
- if (z >= 0x00004) n += 2, z >>= 2;
- if (z >= 0x00002) n += 1, z >>= 1;
- return n;
+ int n = 0;
+ if (z == 0) return -1;
+ if (z >= 0x10000) n += 16, z >>= 16;
+ if (z >= 0x00100) n += 8, z >>= 8;
+ if (z >= 0x00010) n += 4, z >>= 4;
+ if (z >= 0x00004) n += 2, z >>= 2;
+ if (z >= 0x00002) n += 1, z >>= 1;
+ return n;
}
static int stbi__bitcount(unsigned int a)
{
- a = (a & 0x55555555) + ((a >> 1) & 0x55555555); // max 2
- a = (a & 0x33333333) + ((a >> 2) & 0x33333333); // max 4
- a = (a + (a >> 4)) & 0x0f0f0f0f; // max 8 per 4, now 8 bits
- a = (a + (a >> 8)); // max 16 per 8 bits
- a = (a + (a >> 16)); // max 32 per 8 bits
- return a & 0xff;
+ a = (a & 0x55555555) + (a >> 1 & 0x55555555); // max 2
+ a = (a & 0x33333333) + (a >> 2 & 0x33333333); // max 4
+ a = a + (a >> 4) & 0x0f0f0f0f; // max 8 per 4, now 8 bits
+ a = a + (a >> 8); // max 16 per 8 bits
+ a = a + (a >> 16); // max 32 per 8 bits
+ return a & 0xff;
}
// extract an arbitrarily-aligned N-bit value (N=bits)
@@ -5032,287 +5708,351 @@ static int stbi__bitcount(unsigned int a)
// extend it to full full range.
static int stbi__shiftsigned(int v, int shift, int bits)
{
- static unsigned int mul_table[9] = {
- 0,
- 0xff/*0b11111111*/, 0x55/*0b01010101*/, 0x49/*0b01001001*/, 0x11/*0b00010001*/,
- 0x21/*0b00100001*/, 0x41/*0b01000001*/, 0x81/*0b10000001*/, 0x01/*0b00000001*/,
- };
- static unsigned int shift_table[9] = {
- 0, 0,0,1,0,2,4,6,0,
- };
- if (shift < 0)
- v <<= -shift;
- else
- v >>= shift;
- STBI_ASSERT(v >= 0 && v < 256);
- v >>= (8-bits);
- STBI_ASSERT(bits >= 0 && bits <= 8);
- return (int) ((unsigned) v * mul_table[bits]) >> shift_table[bits];
+ static unsigned int mul_table[9] = {
+ 0,
+ 0xff/*0b11111111*/, 0x55/*0b01010101*/, 0x49/*0b01001001*/, 0x11/*0b00010001*/,
+ 0x21/*0b00100001*/, 0x41/*0b01000001*/, 0x81/*0b10000001*/, 0x01/*0b00000001*/,
+ };
+ static unsigned int shift_table[9] = {
+ 0, 0, 0, 1, 0, 2, 4, 6, 0,
+ };
+ if (shift < 0)
+ v <<= -shift;
+ else
+ v >>= shift;
+ STBI_ASSERT(v >= 0 && v < 256);
+ v >>= 8 - bits;
+ STBI_ASSERT(bits >= 0 && bits <= 8);
+ return (int)((unsigned)v * mul_table[bits]) >> shift_table[bits];
}
typedef struct
{
- int bpp, offset, hsz;
- unsigned int mr,mg,mb,ma, all_a;
+ int bpp, offset, hsz;
+ unsigned int mr, mg, mb, ma, all_a;
} stbi__bmp_data;
static void *stbi__bmp_parse_header(stbi__context *s, stbi__bmp_data *info)
{
- int hsz;
- if (stbi__get8(s) != 'B' || stbi__get8(s) != 'M') return stbi__errpuc("not BMP", "Corrupt BMP");
- stbi__get32le(s); // discard filesize
- stbi__get16le(s); // discard reserved
- stbi__get16le(s); // discard reserved
- info->offset = stbi__get32le(s);
- info->hsz = hsz = stbi__get32le(s);
- info->mr = info->mg = info->mb = info->ma = 0;
+ int hsz;
+ if (stbi__get8(s) != 'B' || stbi__get8(s) != 'M') return stbi__errpuc("not BMP", "Corrupt BMP");
+ stbi__get32le(s); // discard filesize
+ stbi__get16le(s); // discard reserved
+ stbi__get16le(s); // discard reserved
+ info->offset = stbi__get32le(s);
+ info->hsz = hsz = stbi__get32le(s);
+ info->mr = info->mg = info->mb = info->ma = 0;
- if (hsz != 12 && hsz != 40 && hsz != 56 && hsz != 108 && hsz != 124) return stbi__errpuc("unknown BMP", "BMP type not supported: unknown");
- if (hsz == 12) {
- s->img_x = stbi__get16le(s);
- s->img_y = stbi__get16le(s);
- } else {
- s->img_x = stbi__get32le(s);
- s->img_y = stbi__get32le(s);
- }
- if (stbi__get16le(s) != 1) return stbi__errpuc("bad BMP", "bad BMP");
- info->bpp = stbi__get16le(s);
- if (hsz != 12) {
- int compress = stbi__get32le(s);
- if (compress == 1 || compress == 2) return stbi__errpuc("BMP RLE", "BMP type not supported: RLE");
- stbi__get32le(s); // discard sizeof
- stbi__get32le(s); // discard hres
- stbi__get32le(s); // discard vres
- stbi__get32le(s); // discard colorsused
- stbi__get32le(s); // discard max important
- if (hsz == 40 || hsz == 56) {
- if (hsz == 56) {
- stbi__get32le(s);
- stbi__get32le(s);
- stbi__get32le(s);
- stbi__get32le(s);
- }
- if (info->bpp == 16 || info->bpp == 32) {
- if (compress == 0) {
- if (info->bpp == 32) {
- info->mr = 0xffu << 16;
- info->mg = 0xffu << 8;
- info->mb = 0xffu << 0;
- info->ma = 0xffu << 24;
- info->all_a = 0; // if all_a is 0 at end, then we loaded alpha channel but it was all 0
- } else {
- info->mr = 31u << 10;
- info->mg = 31u << 5;
- info->mb = 31u << 0;
- }
- } else if (compress == 3) {
- info->mr = stbi__get32le(s);
- info->mg = stbi__get32le(s);
- info->mb = stbi__get32le(s);
- // not documented, but generated by photoshop and handled by mspaint
- if (info->mr == info->mg && info->mg == info->mb) {
- // ?!?!?
- return stbi__errpuc("bad BMP", "bad BMP");
- }
- } else
- return stbi__errpuc("bad BMP", "bad BMP");
- }
- } else {
- int i;
- if (hsz != 108 && hsz != 124)
- return stbi__errpuc("bad BMP", "bad BMP");
- info->mr = stbi__get32le(s);
- info->mg = stbi__get32le(s);
- info->mb = stbi__get32le(s);
- info->ma = stbi__get32le(s);
- stbi__get32le(s); // discard color space
- for (i=0; i < 12; ++i)
- stbi__get32le(s); // discard color space parameters
- if (hsz == 124) {
- stbi__get32le(s); // discard rendering intent
- stbi__get32le(s); // discard offset of profile data
- stbi__get32le(s); // discard size of profile data
- stbi__get32le(s); // discard reserved
- }
- }
- }
- return (void *) 1;
+ if (hsz != 12 && hsz != 40 && hsz != 56 && hsz != 108 && hsz != 124) return stbi__errpuc("unknown BMP", "BMP type not supported: unknown");
+ if (hsz == 12)
+ {
+ s->img_x = stbi__get16le(s);
+ s->img_y = stbi__get16le(s);
+ }
+ else
+ {
+ s->img_x = stbi__get32le(s);
+ s->img_y = stbi__get32le(s);
+ }
+ if (stbi__get16le(s) != 1) return stbi__errpuc("bad BMP", "bad BMP");
+ info->bpp = stbi__get16le(s);
+ if (hsz != 12)
+ {
+ int compress = stbi__get32le(s);
+ if (compress == 1 || compress == 2) return stbi__errpuc("BMP RLE", "BMP type not supported: RLE");
+ stbi__get32le(s); // discard sizeof
+ stbi__get32le(s); // discard hres
+ stbi__get32le(s); // discard vres
+ stbi__get32le(s); // discard colorsused
+ stbi__get32le(s); // discard max important
+ if (hsz == 40 || hsz == 56)
+ {
+ if (hsz == 56)
+ {
+ stbi__get32le(s);
+ stbi__get32le(s);
+ stbi__get32le(s);
+ stbi__get32le(s);
+ }
+ if (info->bpp == 16 || info->bpp == 32)
+ {
+ if (compress == 0)
+ {
+ if (info->bpp == 32)
+ {
+ info->mr = 0xffu << 16;
+ info->mg = 0xffu << 8;
+ info->mb = 0xffu << 0;
+ info->ma = 0xffu << 24;
+ info->all_a = 0; // if all_a is 0 at end, then we loaded alpha channel but it was all 0
+ }
+ else
+ {
+ info->mr = 31u << 10;
+ info->mg = 31u << 5;
+ info->mb = 31u << 0;
+ }
+ }
+ else if (compress == 3)
+ {
+ info->mr = stbi__get32le(s);
+ info->mg = stbi__get32le(s);
+ info->mb = stbi__get32le(s);
+ // not documented, but generated by photoshop and handled by mspaint
+ if (info->mr == info->mg && info->mg == info->mb)
+ {
+ // ?!?!?
+ return stbi__errpuc("bad BMP", "bad BMP");
+ }
+ }
+ else
+ return stbi__errpuc("bad BMP", "bad BMP");
+ }
+ }
+ else
+ {
+ int i;
+ if (hsz != 108 && hsz != 124)
+ return stbi__errpuc("bad BMP", "bad BMP");
+ info->mr = stbi__get32le(s);
+ info->mg = stbi__get32le(s);
+ info->mb = stbi__get32le(s);
+ info->ma = stbi__get32le(s);
+ stbi__get32le(s); // discard color space
+ for (i = 0; i < 12; ++i)
+ stbi__get32le(s); // discard color space parameters
+ if (hsz == 124)
+ {
+ stbi__get32le(s); // discard rendering intent
+ stbi__get32le(s); // discard offset of profile data
+ stbi__get32le(s); // discard size of profile data
+ stbi__get32le(s); // discard reserved
+ }
+ }
+ }
+ return (void *)1;
}
static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri)
{
- stbi_uc *out;
- unsigned int mr=0,mg=0,mb=0,ma=0, all_a;
- stbi_uc pal[256][4];
- int psize=0,i,j,width;
- int flip_vertically, pad, target;
- stbi__bmp_data info;
- STBI_NOTUSED(ri);
+ stbi_uc *out;
+ unsigned int mr = 0, mg = 0, mb = 0, ma = 0, all_a;
+ stbi_uc pal[256][4];
+ int psize = 0, i, j, width;
+ int flip_vertically, pad, target;
+ stbi__bmp_data info;
+ STBI_NOTUSED(ri);
- info.all_a = 255;
- if (stbi__bmp_parse_header(s, &info) == NULL)
- return NULL; // error code already set
+ info.all_a = 255;
+ if (stbi__bmp_parse_header(s, &info) == NULL)
+ return NULL; // error code already set
- flip_vertically = ((int) s->img_y) > 0;
- s->img_y = abs((int) s->img_y);
+ flip_vertically = (int)s->img_y > 0;
+ s->img_y = abs((int)s->img_y);
- mr = info.mr;
- mg = info.mg;
- mb = info.mb;
- ma = info.ma;
- all_a = info.all_a;
+ mr = info.mr;
+ mg = info.mg;
+ mb = info.mb;
+ ma = info.ma;
+ all_a = info.all_a;
- if (info.hsz == 12) {
- if (info.bpp < 24)
- psize = (info.offset - 14 - 24) / 3;
- } else {
- if (info.bpp < 16)
- psize = (info.offset - 14 - info.hsz) >> 2;
- }
+ if (info.hsz == 12)
+ {
+ if (info.bpp < 24)
+ psize = (info.offset - 14 - 24) / 3;
+ }
+ else
+ {
+ if (info.bpp < 16)
+ psize = (info.offset - 14 - info.hsz) >> 2;
+ }
- s->img_n = ma ? 4 : 3;
- if (req_comp && req_comp >= 3) // we can directly decode 3 or 4
- target = req_comp;
- else
- target = s->img_n; // if they want monochrome, we'll post-convert
+ s->img_n = ma ? 4 : 3;
+ if (req_comp && req_comp >= 3) // we can directly decode 3 or 4
+ target = req_comp;
+ else
+ target = s->img_n; // if they want monochrome, we'll post-convert
- // sanity-check size
- if (!stbi__mad3sizes_valid(target, s->img_x, s->img_y, 0))
- return stbi__errpuc("too large", "Corrupt BMP");
+ // sanity-check size
+ if (!stbi__mad3sizes_valid(target, s->img_x, s->img_y, 0))
+ return stbi__errpuc("too large", "Corrupt BMP");
- out = (stbi_uc *) stbi__malloc_mad3(target, s->img_x, s->img_y, 0);
- if (!out) return stbi__errpuc("outofmem", "Out of memory");
- if (info.bpp < 16) {
- int z=0;
- if (psize == 0 || psize > 256) { STBI_FREE(out); return stbi__errpuc("invalid", "Corrupt BMP"); }
- for (i=0; i < psize; ++i) {
- pal[i][2] = stbi__get8(s);
- pal[i][1] = stbi__get8(s);
- pal[i][0] = stbi__get8(s);
- if (info.hsz != 12) stbi__get8(s);
- pal[i][3] = 255;
- }
- stbi__skip(s, info.offset - 14 - info.hsz - psize * (info.hsz == 12 ? 3 : 4));
- if (info.bpp == 1) width = (s->img_x + 7) >> 3;
- else if (info.bpp == 4) width = (s->img_x + 1) >> 1;
- else if (info.bpp == 8) width = s->img_x;
- else { STBI_FREE(out); return stbi__errpuc("bad bpp", "Corrupt BMP"); }
- pad = (-width)&3;
- if (info.bpp == 1) {
- for (j=0; j < (int) s->img_y; ++j) {
- int bit_offset = 7, v = stbi__get8(s);
- for (i=0; i < (int) s->img_x; ++i) {
- int color = (v>>bit_offset)&0x1;
- out[z++] = pal[color][0];
- out[z++] = pal[color][1];
- out[z++] = pal[color][2];
- if((--bit_offset) < 0) {
- bit_offset = 7;
- v = stbi__get8(s);
- }
+ out = (stbi_uc *)stbi__malloc_mad3(target, s->img_x, s->img_y, 0);
+ if (!out) return stbi__errpuc("outofmem", "Out of memory");
+ if (info.bpp < 16)
+ {
+ int z = 0;
+ if (psize == 0 || psize > 256)
+ {
+ STBI_FREE(out);
+ return stbi__errpuc("invalid", "Corrupt BMP");
+ }
+ for (i = 0; i < psize; ++i)
+ {
+ pal[i][2] = stbi__get8(s);
+ pal[i][1] = stbi__get8(s);
+ pal[i][0] = stbi__get8(s);
+ if (info.hsz != 12) stbi__get8(s);
+ pal[i][3] = 255;
+ }
+ stbi__skip(s, info.offset - 14 - info.hsz - psize * (info.hsz == 12 ? 3 : 4));
+ if (info.bpp == 1) width = (s->img_x + 7) >> 3;
+ else if (info.bpp == 4) width = (s->img_x + 1) >> 1;
+ else if (info.bpp == 8) width = s->img_x;
+ else
+ {
+ STBI_FREE(out);
+ return stbi__errpuc("bad bpp", "Corrupt BMP");
+ }
+ pad = -width & 3;
+ if (info.bpp == 1)
+ {
+ for (j = 0; j < (int)s->img_y; ++j)
+ {
+ int bit_offset = 7, v = stbi__get8(s);
+ for (i = 0; i < (int)s->img_x; ++i)
+ {
+ int color = v >> bit_offset & 0x1;
+ out[z++] = pal[color][0];
+ out[z++] = pal[color][1];
+ out[z++] = pal[color][2];
+ if (--bit_offset < 0)
+ {
+ bit_offset = 7;
+ v = stbi__get8(s);
+ }
+ }
+ stbi__skip(s, pad);
+ }
+ }
+ else
+ {
+ for (j = 0; j < (int)s->img_y; ++j)
+ {
+ for (i = 0; i < (int)s->img_x; i += 2)
+ {
+ int v = stbi__get8(s), v2 = 0;
+ if (info.bpp == 4)
+ {
+ v2 = v & 15;
+ v >>= 4;
+ }
+ out[z++] = pal[v][0];
+ out[z++] = pal[v][1];
+ out[z++] = pal[v][2];
+ if (target == 4) out[z++] = 255;
+ if (i + 1 == (int)s->img_x) break;
+ v = info.bpp == 8 ? stbi__get8(s) : v2;
+ out[z++] = pal[v][0];
+ out[z++] = pal[v][1];
+ out[z++] = pal[v][2];
+ if (target == 4) out[z++] = 255;
+ }
+ stbi__skip(s, pad);
+ }
+ }
+ }
+ else
+ {
+ int rshift = 0, gshift = 0, bshift = 0, ashift = 0, rcount = 0, gcount = 0, bcount = 0, acount = 0;
+ int z = 0;
+ int easy = 0;
+ stbi__skip(s, info.offset - 14 - info.hsz);
+ if (info.bpp == 24) width = 3 * s->img_x;
+ else if (info.bpp == 16) width = 2 * s->img_x;
+ else /* bpp = 32 and pad = 0 */ width = 0;
+ pad = -width & 3;
+ if (info.bpp == 24)
+ {
+ easy = 1;
+ }
+ else if (info.bpp == 32)
+ {
+ if (mb == 0xff && mg == 0xff00 && mr == 0x00ff0000 && ma == 0xff000000)
+ easy = 2;
+ }
+ if (!easy)
+ {
+ if (!mr || !mg || !mb)
+ {
+ STBI_FREE(out);
+ return stbi__errpuc("bad masks", "Corrupt BMP");
+ }
+ // right shift amt to put high bit in position #7
+ rshift = stbi__high_bit(mr) - 7;
+ rcount = stbi__bitcount(mr);
+ gshift = stbi__high_bit(mg) - 7;
+ gcount = stbi__bitcount(mg);
+ bshift = stbi__high_bit(mb) - 7;
+ bcount = stbi__bitcount(mb);
+ ashift = stbi__high_bit(ma) - 7;
+ acount = stbi__bitcount(ma);
+ }
+ for (j = 0; j < (int)s->img_y; ++j)
+ {
+ if (easy)
+ {
+ for (i = 0; i < (int)s->img_x; ++i)
+ {
+ unsigned char a;
+ out[z + 2] = stbi__get8(s);
+ out[z + 1] = stbi__get8(s);
+ out[z + 0] = stbi__get8(s);
+ z += 3;
+ a = easy == 2 ? stbi__get8(s) : 255;
+ all_a |= a;
+ if (target == 4) out[z++] = a;
+ }
+ }
+ else
+ {
+ int bpp = info.bpp;
+ for (i = 0; i < (int)s->img_x; ++i)
+ {
+ stbi__uint32 v = bpp == 16 ? (stbi__uint32)stbi__get16le(s) : stbi__get32le(s);
+ unsigned int a;
+ out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mr, rshift, rcount));
+ out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mg, gshift, gcount));
+ out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mb, bshift, bcount));
+ a = ma ? stbi__shiftsigned(v & ma, ashift, acount) : 255;
+ all_a |= a;
+ if (target == 4) out[z++] = STBI__BYTECAST(a);
+ }
}
stbi__skip(s, pad);
- }
- } else {
- for (j=0; j < (int) s->img_y; ++j) {
- for (i=0; i < (int) s->img_x; i += 2) {
- int v=stbi__get8(s),v2=0;
- if (info.bpp == 4) {
- v2 = v & 15;
- v >>= 4;
- }
- out[z++] = pal[v][0];
- out[z++] = pal[v][1];
- out[z++] = pal[v][2];
- if (target == 4) out[z++] = 255;
- if (i+1 == (int) s->img_x) break;
- v = (info.bpp == 8) ? stbi__get8(s) : v2;
- out[z++] = pal[v][0];
- out[z++] = pal[v][1];
- out[z++] = pal[v][2];
- if (target == 4) out[z++] = 255;
+ }
+ }
+
+ // if alpha channel is all 0s, replace with all 255s
+ if (target == 4 && all_a == 0)
+ for (i = 4 * s->img_x * s->img_y - 1; i >= 0; i -= 4)
+ out[i] = 255;
+
+ if (flip_vertically)
+ {
+ stbi_uc t;
+ for (j = 0; j < (int)s->img_y >> 1; ++j)
+ {
+ stbi_uc *p1 = out + j * s->img_x * target;
+ stbi_uc *p2 = out + (s->img_y - 1 - j) * s->img_x * target;
+ for (i = 0; i < (int)s->img_x * target; ++i)
+ {
+ t = p1[i], p1[i] = p2[i], p2[i] = t;
}
- stbi__skip(s, pad);
- }
- }
- } else {
- int rshift=0,gshift=0,bshift=0,ashift=0,rcount=0,gcount=0,bcount=0,acount=0;
- int z = 0;
- int easy=0;
- stbi__skip(s, info.offset - 14 - info.hsz);
- if (info.bpp == 24) width = 3 * s->img_x;
- else if (info.bpp == 16) width = 2*s->img_x;
- else /* bpp = 32 and pad = 0 */ width=0;
- pad = (-width) & 3;
- if (info.bpp == 24) {
- easy = 1;
- } else if (info.bpp == 32) {
- if (mb == 0xff && mg == 0xff00 && mr == 0x00ff0000 && ma == 0xff000000)
- easy = 2;
- }
- if (!easy) {
- if (!mr || !mg || !mb) { STBI_FREE(out); return stbi__errpuc("bad masks", "Corrupt BMP"); }
- // right shift amt to put high bit in position #7
- rshift = stbi__high_bit(mr)-7; rcount = stbi__bitcount(mr);
- gshift = stbi__high_bit(mg)-7; gcount = stbi__bitcount(mg);
- bshift = stbi__high_bit(mb)-7; bcount = stbi__bitcount(mb);
- ashift = stbi__high_bit(ma)-7; acount = stbi__bitcount(ma);
- }
- for (j=0; j < (int) s->img_y; ++j) {
- if (easy) {
- for (i=0; i < (int) s->img_x; ++i) {
- unsigned char a;
- out[z+2] = stbi__get8(s);
- out[z+1] = stbi__get8(s);
- out[z+0] = stbi__get8(s);
- z += 3;
- a = (easy == 2 ? stbi__get8(s) : 255);
- all_a |= a;
- if (target == 4) out[z++] = a;
- }
- } else {
- int bpp = info.bpp;
- for (i=0; i < (int) s->img_x; ++i) {
- stbi__uint32 v = (bpp == 16 ? (stbi__uint32) stbi__get16le(s) : stbi__get32le(s));
- unsigned int a;
- out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mr, rshift, rcount));
- out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mg, gshift, gcount));
- out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mb, bshift, bcount));
- a = (ma ? stbi__shiftsigned(v & ma, ashift, acount) : 255);
- all_a |= a;
- if (target == 4) out[z++] = STBI__BYTECAST(a);
- }
- }
- stbi__skip(s, pad);
- }
- }
+ }
+ }
- // if alpha channel is all 0s, replace with all 255s
- if (target == 4 && all_a == 0)
- for (i=4*s->img_x*s->img_y-1; i >= 0; i -= 4)
- out[i] = 255;
+ if (req_comp && req_comp != target)
+ {
+ out = stbi__convert_format(out, target, req_comp, s->img_x, s->img_y);
+ if (out == NULL) return out; // stbi__convert_format frees input on failure
+ }
- if (flip_vertically) {
- stbi_uc t;
- for (j=0; j < (int) s->img_y>>1; ++j) {
- stbi_uc *p1 = out + j *s->img_x*target;
- stbi_uc *p2 = out + (s->img_y-1-j)*s->img_x*target;
- for (i=0; i < (int) s->img_x*target; ++i) {
- t = p1[i], p1[i] = p2[i], p2[i] = t;
- }
- }
- }
-
- if (req_comp && req_comp != target) {
- out = stbi__convert_format(out, target, req_comp, s->img_x, s->img_y);
- if (out == NULL) return out; // stbi__convert_format frees input on failure
- }
-
- *x = s->img_x;
- *y = s->img_y;
- if (comp) *comp = s->img_n;
- return out;
+ *x = s->img_x;
+ *y = s->img_y;
+ if (comp) *comp = s->img_n;
+ return out;
}
#endif
@@ -5320,330 +6060,370 @@ static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req
// by Jonathan Dummer
#ifndef STBI_NO_TGA
// returns STBI_rgb or whatever, 0 on error
-static int stbi__tga_get_comp(int bits_per_pixel, int is_grey, int* is_rgb16)
+static int stbi__tga_get_comp(int bits_per_pixel, int is_grey, int *is_rgb16)
{
- // only RGB or RGBA (incl. 16bit) or grey allowed
- if (is_rgb16) *is_rgb16 = 0;
- switch(bits_per_pixel) {
- case 8: return STBI_grey;
- case 16: if(is_grey) return STBI_grey_alpha;
- // fallthrough
- case 15: if(is_rgb16) *is_rgb16 = 1;
- return STBI_rgb;
- case 24: // fallthrough
- case 32: return bits_per_pixel/8;
- default: return 0;
- }
+ // only RGB or RGBA (incl. 16bit) or grey allowed
+ if (is_rgb16) *is_rgb16 = 0;
+ switch (bits_per_pixel)
+ {
+ case 8:
+ return STBI_grey;
+ case 16:
+ if (is_grey) return STBI_grey_alpha;
+ // fallthrough
+ case 15:
+ if (is_rgb16) *is_rgb16 = 1;
+ return STBI_rgb;
+ case 24: // fallthrough
+ case 32:
+ return bits_per_pixel / 8;
+ default:
+ return 0;
+ }
}
static int stbi__tga_info(stbi__context *s, int *x, int *y, int *comp)
{
int tga_w, tga_h, tga_comp, tga_image_type, tga_bits_per_pixel, tga_colormap_bpp;
int sz, tga_colormap_type;
- stbi__get8(s); // discard Offset
+ stbi__get8(s); // discard Offset
tga_colormap_type = stbi__get8(s); // colormap type
- if( tga_colormap_type > 1 ) {
+ if (tga_colormap_type > 1)
+ {
stbi__rewind(s);
- return 0; // only RGB or indexed allowed
+ return 0; // only RGB or indexed allowed
}
tga_image_type = stbi__get8(s); // image type
- if ( tga_colormap_type == 1 ) { // colormapped (paletted) image
- if (tga_image_type != 1 && tga_image_type != 9) {
+ if (tga_colormap_type == 1)
+ { // colormapped (paletted) image
+ if (tga_image_type != 1 && tga_image_type != 9)
+ {
stbi__rewind(s);
return 0;
}
- stbi__skip(s,4); // skip index of first colormap entry and number of entries
- sz = stbi__get8(s); // check bits per palette color entry
- if ( (sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32) ) {
+ stbi__skip(s, 4); // skip index of first colormap entry and number of entries
+ sz = stbi__get8(s); // check bits per palette color entry
+ if ((sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32))
+ {
stbi__rewind(s);
return 0;
}
- stbi__skip(s,4); // skip image x and y origin
+ stbi__skip(s, 4); // skip image x and y origin
tga_colormap_bpp = sz;
- } else { // "normal" image w/o colormap - only RGB or grey allowed, +/- RLE
- if ( (tga_image_type != 2) && (tga_image_type != 3) && (tga_image_type != 10) && (tga_image_type != 11) ) {
+ }
+ else
+ { // "normal" image w/o colormap - only RGB or grey allowed, +/- RLE
+ if ((tga_image_type != 2) && (tga_image_type != 3) && (tga_image_type != 10) && (tga_image_type != 11))
+ {
stbi__rewind(s);
return 0; // only RGB or grey allowed, +/- RLE
}
- stbi__skip(s,9); // skip colormap specification and image x/y origin
+ stbi__skip(s, 9); // skip colormap specification and image x/y origin
tga_colormap_bpp = 0;
}
tga_w = stbi__get16le(s);
- if( tga_w < 1 ) {
+ if (tga_w < 1)
+ {
stbi__rewind(s);
- return 0; // test width
+ return 0; // test width
}
tga_h = stbi__get16le(s);
- if( tga_h < 1 ) {
+ if (tga_h < 1)
+ {
stbi__rewind(s);
- return 0; // test height
+ return 0; // test height
}
tga_bits_per_pixel = stbi__get8(s); // bits per pixel
stbi__get8(s); // ignore alpha bits
- if (tga_colormap_bpp != 0) {
- if((tga_bits_per_pixel != 8) && (tga_bits_per_pixel != 16)) {
+ if (tga_colormap_bpp != 0)
+ {
+ if ((tga_bits_per_pixel != 8) && (tga_bits_per_pixel != 16))
+ {
// when using a colormap, tga_bits_per_pixel is the size of the indexes
// I don't think anything but 8 or 16bit indexes makes sense
stbi__rewind(s);
return 0;
}
tga_comp = stbi__tga_get_comp(tga_colormap_bpp, 0, NULL);
- } else {
+ }
+ else
+ {
tga_comp = stbi__tga_get_comp(tga_bits_per_pixel, (tga_image_type == 3) || (tga_image_type == 11), NULL);
}
- if(!tga_comp) {
- stbi__rewind(s);
- return 0;
+ if (!tga_comp)
+ {
+ stbi__rewind(s);
+ return 0;
}
if (x) *x = tga_w;
if (y) *y = tga_h;
if (comp) *comp = tga_comp;
- return 1; // seems to have passed everything
+ return 1; // seems to have passed everything
}
static int stbi__tga_test(stbi__context *s)
{
- int res = 0;
- int sz, tga_color_type;
- stbi__get8(s); // discard Offset
- tga_color_type = stbi__get8(s); // color type
- if ( tga_color_type > 1 ) goto errorEnd; // only RGB or indexed allowed
- sz = stbi__get8(s); // image type
- if ( tga_color_type == 1 ) { // colormapped (paletted) image
- if (sz != 1 && sz != 9) goto errorEnd; // colortype 1 demands image type 1 or 9
- stbi__skip(s,4); // skip index of first colormap entry and number of entries
- sz = stbi__get8(s); // check bits per palette color entry
- if ( (sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32) ) goto errorEnd;
- stbi__skip(s,4); // skip image x and y origin
- } else { // "normal" image w/o colormap
- if ( (sz != 2) && (sz != 3) && (sz != 10) && (sz != 11) ) goto errorEnd; // only RGB or grey allowed, +/- RLE
- stbi__skip(s,9); // skip colormap specification and image x/y origin
- }
- if ( stbi__get16le(s) < 1 ) goto errorEnd; // test width
- if ( stbi__get16le(s) < 1 ) goto errorEnd; // test height
- sz = stbi__get8(s); // bits per pixel
- if ( (tga_color_type == 1) && (sz != 8) && (sz != 16) ) goto errorEnd; // for colormapped images, bpp is size of an index
- if ( (sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32) ) goto errorEnd;
+ int res = 0;
+ int sz, tga_color_type;
+ stbi__get8(s); // discard Offset
+ tga_color_type = stbi__get8(s); // color type
+ if (tga_color_type > 1) goto errorEnd; // only RGB or indexed allowed
+ sz = stbi__get8(s); // image type
+ if (tga_color_type == 1)
+ { // colormapped (paletted) image
+ if (sz != 1 && sz != 9) goto errorEnd; // colortype 1 demands image type 1 or 9
+ stbi__skip(s, 4); // skip index of first colormap entry and number of entries
+ sz = stbi__get8(s); // check bits per palette color entry
+ if ((sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32)) goto errorEnd;
+ stbi__skip(s, 4); // skip image x and y origin
+ }
+ else
+ { // "normal" image w/o colormap
+ if ((sz != 2) && (sz != 3) && (sz != 10) && (sz != 11)) goto errorEnd; // only RGB or grey allowed, +/- RLE
+ stbi__skip(s, 9); // skip colormap specification and image x/y origin
+ }
+ if (stbi__get16le(s) < 1) goto errorEnd; // test width
+ if (stbi__get16le(s) < 1) goto errorEnd; // test height
+ sz = stbi__get8(s); // bits per pixel
+ if ((tga_color_type == 1) && (sz != 8) && (sz != 16)) goto errorEnd; // for colormapped images, bpp is size of an index
+ if ((sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32)) goto errorEnd;
- res = 1; // if we got this far, everything's good and we can return 1 instead of 0
+ res = 1; // if we got this far, everything's good and we can return 1 instead of 0
-errorEnd:
- stbi__rewind(s);
- return res;
+errorEnd: stbi__rewind(s);
+ return res;
}
// read 16bit value and convert to 24bit RGB
-static void stbi__tga_read_rgb16(stbi__context *s, stbi_uc* out)
+static void stbi__tga_read_rgb16(stbi__context *s, stbi_uc *out)
{
- stbi__uint16 px = (stbi__uint16)stbi__get16le(s);
- stbi__uint16 fiveBitMask = 31;
- // we have 3 channels with 5bits each
- int r = (px >> 10) & fiveBitMask;
- int g = (px >> 5) & fiveBitMask;
- int b = px & fiveBitMask;
- // Note that this saves the data in RGB(A) order, so it doesn't need to be swapped later
- out[0] = (stbi_uc)((r * 255)/31);
- out[1] = (stbi_uc)((g * 255)/31);
- out[2] = (stbi_uc)((b * 255)/31);
+ stbi__uint16 px = (stbi__uint16)stbi__get16le(s);
+ stbi__uint16 fiveBitMask = 31;
+ // we have 3 channels with 5bits each
+ int r = (px >> 10) & fiveBitMask;
+ int g = (px >> 5) & fiveBitMask;
+ int b = px & fiveBitMask;
+ // Note that this saves the data in RGB(A) order, so it doesn't need to be swapped later
+ out[0] = (stbi_uc)((r * 255) / 31);
+ out[1] = (stbi_uc)((g * 255) / 31);
+ out[2] = (stbi_uc)((b * 255) / 31);
- // some people claim that the most significant bit might be used for alpha
- // (possibly if an alpha-bit is set in the "image descriptor byte")
- // but that only made 16bit test images completely translucent..
- // so let's treat all 15 and 16bit TGAs as RGB with no alpha.
+ // some people claim that the most significant bit might be used for alpha
+ // (possibly if an alpha-bit is set in the "image descriptor byte")
+ // but that only made 16bit test images completely translucent..
+ // so let's treat all 15 and 16bit TGAs as RGB with no alpha.
}
static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri)
{
- // read in the TGA header stuff
- int tga_offset = stbi__get8(s);
- int tga_indexed = stbi__get8(s);
- int tga_image_type = stbi__get8(s);
- int tga_is_RLE = 0;
- int tga_palette_start = stbi__get16le(s);
- int tga_palette_len = stbi__get16le(s);
- int tga_palette_bits = stbi__get8(s);
- int tga_x_origin = stbi__get16le(s);
- int tga_y_origin = stbi__get16le(s);
- int tga_width = stbi__get16le(s);
- int tga_height = stbi__get16le(s);
- int tga_bits_per_pixel = stbi__get8(s);
- int tga_comp, tga_rgb16=0;
- int tga_inverted = stbi__get8(s);
- // int tga_alpha_bits = tga_inverted & 15; // the 4 lowest bits - unused (useless?)
- // image data
- unsigned char *tga_data;
- unsigned char *tga_palette = NULL;
- int i, j;
- unsigned char raw_data[4] = {0};
- int RLE_count = 0;
- int RLE_repeating = 0;
- int read_next_pixel = 1;
- STBI_NOTUSED(ri);
+ // read in the TGA header stuff
+ int tga_offset = stbi__get8(s);
+ int tga_indexed = stbi__get8(s);
+ int tga_image_type = stbi__get8(s);
+ int tga_is_RLE = 0;
+ int tga_palette_start = stbi__get16le(s);
+ int tga_palette_len = stbi__get16le(s);
+ int tga_palette_bits = stbi__get8(s);
+ int tga_x_origin = stbi__get16le(s);
+ int tga_y_origin = stbi__get16le(s);
+ int tga_width = stbi__get16le(s);
+ int tga_height = stbi__get16le(s);
+ int tga_bits_per_pixel = stbi__get8(s);
+ int tga_comp, tga_rgb16 = 0;
+ int tga_inverted = stbi__get8(s);
+ // int tga_alpha_bits = tga_inverted & 15; // the 4 lowest bits - unused (useless?)
+ // image data
+ unsigned char *tga_data;
+ unsigned char *tga_palette = NULL;
+ int i, j;
+ unsigned char raw_data[4] = {0};
+ int RLE_count = 0;
+ int RLE_repeating = 0;
+ int read_next_pixel = 1;
+ STBI_NOTUSED(ri);
- // do a tiny bit of precessing
- if ( tga_image_type >= 8 )
- {
- tga_image_type -= 8;
- tga_is_RLE = 1;
- }
- tga_inverted = 1 - ((tga_inverted >> 5) & 1);
+ // do a tiny bit of precessing
+ if (tga_image_type >= 8)
+ {
+ tga_image_type -= 8;
+ tga_is_RLE = 1;
+ }
+ tga_inverted = 1 - ((tga_inverted >> 5) & 1);
- // If I'm paletted, then I'll use the number of bits from the palette
- if ( tga_indexed ) tga_comp = stbi__tga_get_comp(tga_palette_bits, 0, &tga_rgb16);
- else tga_comp = stbi__tga_get_comp(tga_bits_per_pixel, (tga_image_type == 3), &tga_rgb16);
+ // If I'm paletted, then I'll use the number of bits from the palette
+ if (tga_indexed) tga_comp = stbi__tga_get_comp(tga_palette_bits, 0, &tga_rgb16);
+ else tga_comp = stbi__tga_get_comp(tga_bits_per_pixel, (tga_image_type == 3), &tga_rgb16);
- if(!tga_comp) // shouldn't really happen, stbi__tga_test() should have ensured basic consistency
- return stbi__errpuc("bad format", "Can't find out TGA pixelformat");
+ if (!tga_comp) // shouldn't really happen, stbi__tga_test() should have ensured basic consistency
+ return stbi__errpuc("bad format", "Can't find out TGA pixelformat");
- // tga info
- *x = tga_width;
- *y = tga_height;
- if (comp) *comp = tga_comp;
+ // tga info
+ *x = tga_width;
+ *y = tga_height;
+ if (comp) *comp = tga_comp;
- if (!stbi__mad3sizes_valid(tga_width, tga_height, tga_comp, 0))
- return stbi__errpuc("too large", "Corrupt TGA");
+ if (!stbi__mad3sizes_valid(tga_width, tga_height, tga_comp, 0))
+ return stbi__errpuc("too large", "Corrupt TGA");
- tga_data = (unsigned char*)stbi__malloc_mad3(tga_width, tga_height, tga_comp, 0);
- if (!tga_data) return stbi__errpuc("outofmem", "Out of memory");
+ tga_data = (unsigned char *)stbi__malloc_mad3(tga_width, tga_height, tga_comp, 0);
+ if (!tga_data) return stbi__errpuc("outofmem", "Out of memory");
- // skip to the data's starting position (offset usually = 0)
- stbi__skip(s, tga_offset );
+ // skip to the data's starting position (offset usually = 0)
+ stbi__skip(s, tga_offset);
- if ( !tga_indexed && !tga_is_RLE && !tga_rgb16 ) {
- for (i=0; i < tga_height; ++i) {
- int row = tga_inverted ? tga_height -i - 1 : i;
- stbi_uc *tga_row = tga_data + row*tga_width*tga_comp;
- stbi__getn(s, tga_row, tga_width * tga_comp);
- }
- } else {
- // do I need to load a palette?
- if ( tga_indexed)
- {
- // any data to skip? (offset usually = 0)
- stbi__skip(s, tga_palette_start );
- // load the palette
- tga_palette = (unsigned char*)stbi__malloc_mad2(tga_palette_len, tga_comp, 0);
- if (!tga_palette) {
- STBI_FREE(tga_data);
- return stbi__errpuc("outofmem", "Out of memory");
- }
- if (tga_rgb16) {
- stbi_uc *pal_entry = tga_palette;
- STBI_ASSERT(tga_comp == STBI_rgb);
- for (i=0; i < tga_palette_len; ++i) {
- stbi__tga_read_rgb16(s, pal_entry);
- pal_entry += tga_comp;
- }
- } else if (!stbi__getn(s, tga_palette, tga_palette_len * tga_comp)) {
- STBI_FREE(tga_data);
- STBI_FREE(tga_palette);
- return stbi__errpuc("bad palette", "Corrupt TGA");
- }
- }
- // load the data
- for (i=0; i < tga_width * tga_height; ++i)
- {
- // if I'm in RLE mode, do I need to get a RLE stbi__pngchunk?
- if ( tga_is_RLE )
- {
- if ( RLE_count == 0 )
+ if (!tga_indexed && !tga_is_RLE && !tga_rgb16)
+ {
+ for (i = 0; i < tga_height; ++i)
+ {
+ int row = tga_inverted ? tga_height - i - 1 : i;
+ stbi_uc *tga_row = tga_data + row * tga_width * tga_comp;
+ stbi__getn(s, tga_row, tga_width * tga_comp);
+ }
+ }
+ else
+ {
+ // do I need to load a palette?
+ if (tga_indexed)
+ {
+ // any data to skip? (offset usually = 0)
+ stbi__skip(s, tga_palette_start);
+ // load the palette
+ tga_palette = (unsigned char *)stbi__malloc_mad2(tga_palette_len, tga_comp, 0);
+ if (!tga_palette)
{
- // yep, get the next byte as a RLE command
- int RLE_cmd = stbi__get8(s);
- RLE_count = 1 + (RLE_cmd & 127);
- RLE_repeating = RLE_cmd >> 7;
- read_next_pixel = 1;
- } else if ( !RLE_repeating )
- {
- read_next_pixel = 1;
+ STBI_FREE(tga_data);
+ return stbi__errpuc("outofmem", "Out of memory");
}
- } else
- {
- read_next_pixel = 1;
- }
- // OK, if I need to read a pixel, do it now
- if ( read_next_pixel )
- {
- // load however much data we did have
- if ( tga_indexed )
+ if (tga_rgb16)
{
- // read in index, then perform the lookup
- int pal_idx = (tga_bits_per_pixel == 8) ? stbi__get8(s) : stbi__get16le(s);
- if ( pal_idx >= tga_palette_len ) {
- // invalid index
- pal_idx = 0;
- }
- pal_idx *= tga_comp;
- for (j = 0; j < tga_comp; ++j) {
- raw_data[j] = tga_palette[pal_idx+j];
- }
- } else if(tga_rgb16) {
- STBI_ASSERT(tga_comp == STBI_rgb);
- stbi__tga_read_rgb16(s, raw_data);
- } else {
- // read in the data raw
- for (j = 0; j < tga_comp; ++j) {
- raw_data[j] = stbi__get8(s);
- }
+ stbi_uc *pal_entry = tga_palette;
+ STBI_ASSERT(tga_comp == STBI_rgb);
+ for (i = 0; i < tga_palette_len; ++i)
+ {
+ stbi__tga_read_rgb16(s, pal_entry);
+ pal_entry += tga_comp;
+ }
}
- // clear the reading flag for the next pixel
- read_next_pixel = 0;
- } // end of reading a pixel
-
- // copy data
- for (j = 0; j < tga_comp; ++j)
- tga_data[i*tga_comp+j] = raw_data[j];
-
- // in case we're in RLE mode, keep counting down
- --RLE_count;
- }
- // do I need to invert the image?
- if ( tga_inverted )
- {
- for (j = 0; j*2 < tga_height; ++j)
- {
- int index1 = j * tga_width * tga_comp;
- int index2 = (tga_height - 1 - j) * tga_width * tga_comp;
- for (i = tga_width * tga_comp; i > 0; --i)
+ else if (!stbi__getn(s, tga_palette, tga_palette_len * tga_comp))
{
- unsigned char temp = tga_data[index1];
- tga_data[index1] = tga_data[index2];
- tga_data[index2] = temp;
- ++index1;
- ++index2;
+ STBI_FREE(tga_data);
+ STBI_FREE(tga_palette);
+ return stbi__errpuc("bad palette", "Corrupt TGA");
}
- }
- }
- // clear my palette, if I had one
- if ( tga_palette != NULL )
- {
- STBI_FREE( tga_palette );
- }
- }
+ }
+ // load the data
+ for (i = 0; i < tga_width * tga_height; ++i)
+ {
+ // if I'm in RLE mode, do I need to get a RLE stbi__pngchunk?
+ if (tga_is_RLE)
+ {
+ if (RLE_count == 0)
+ {
+ // yep, get the next byte as a RLE command
+ int RLE_cmd = stbi__get8(s);
+ RLE_count = 1 + (RLE_cmd & 127);
+ RLE_repeating = RLE_cmd >> 7;
+ read_next_pixel = 1;
+ }
+ else if (!RLE_repeating)
+ {
+ read_next_pixel = 1;
+ }
+ }
+ else
+ {
+ read_next_pixel = 1;
+ }
+ // OK, if I need to read a pixel, do it now
+ if (read_next_pixel)
+ {
+ // load however much data we did have
+ if (tga_indexed)
+ {
+ // read in index, then perform the lookup
+ int pal_idx = (tga_bits_per_pixel == 8) ? stbi__get8(s) : stbi__get16le(s);
+ if (pal_idx >= tga_palette_len)
+ {
+ // invalid index
+ pal_idx = 0;
+ }
+ pal_idx *= tga_comp;
+ for (j = 0; j < tga_comp; ++j)
+ {
+ raw_data[j] = tga_palette[pal_idx + j];
+ }
+ }
+ else if (tga_rgb16)
+ {
+ STBI_ASSERT(tga_comp == STBI_rgb);
+ stbi__tga_read_rgb16(s, raw_data);
+ }
+ else
+ {
+ // read in the data raw
+ for (j = 0; j < tga_comp; ++j)
+ {
+ raw_data[j] = stbi__get8(s);
+ }
+ }
+ // clear the reading flag for the next pixel
+ read_next_pixel = 0;
+ } // end of reading a pixel
- // swap RGB - if the source data was RGB16, it already is in the right order
- if (tga_comp >= 3 && !tga_rgb16)
- {
- unsigned char* tga_pixel = tga_data;
- for (i=0; i < tga_width * tga_height; ++i)
- {
- unsigned char temp = tga_pixel[0];
- tga_pixel[0] = tga_pixel[2];
- tga_pixel[2] = temp;
- tga_pixel += tga_comp;
- }
- }
+ // copy data
+ for (j = 0; j < tga_comp; ++j)
+ tga_data[i * tga_comp + j] = raw_data[j];
- // convert to target component count
- if (req_comp && req_comp != tga_comp)
- tga_data = stbi__convert_format(tga_data, tga_comp, req_comp, tga_width, tga_height);
+ // in case we're in RLE mode, keep counting down
+ --RLE_count;
+ }
+ // do I need to invert the image?
+ if (tga_inverted)
+ {
+ for (j = 0; j * 2 < tga_height; ++j)
+ {
+ int index1 = j * tga_width * tga_comp;
+ int index2 = (tga_height - 1 - j) * tga_width * tga_comp;
+ for (i = tga_width * tga_comp; i > 0; --i)
+ {
+ unsigned char temp = tga_data[index1];
+ tga_data[index1] = tga_data[index2];
+ tga_data[index2] = temp;
+ ++index1;
+ ++index2;
+ }
+ }
+ }
+ // clear my palette, if I had one
+ if (tga_palette != NULL)
+ {
+ STBI_FREE(tga_palette);
+ }
+ }
- // the things I do to get rid of an error message, and yet keep
- // Microsoft's C compilers happy... [8^(
- tga_palette_start = tga_palette_len = tga_palette_bits =
- tga_x_origin = tga_y_origin = 0;
- // OK, done
- return tga_data;
+ // swap RGB - if the source data was RGB16, it already is in the right order
+ if (tga_comp >= 3 && !tga_rgb16)
+ {
+ unsigned char *tga_pixel = tga_data;
+ for (i = 0; i < tga_width * tga_height; ++i)
+ {
+ unsigned char temp = tga_pixel[0];
+ tga_pixel[0] = tga_pixel[2];
+ tga_pixel[2] = temp;
+ tga_pixel += tga_comp;
+ }
+ }
+
+ // convert to target component count
+ if (req_comp && req_comp != tga_comp)
+ tga_data = stbi__convert_format(tga_data, tga_comp, req_comp, tga_width, tga_height);
+
+ // the things I do to get rid of an error message, and yet keep
+ // Microsoft's C compilers happy... [8^(
+ tga_palette_start = tga_palette_len = tga_palette_bits =
+ tga_x_origin = tga_y_origin = 0;
+ // OK, done
+ return tga_data;
}
#endif
@@ -5653,245 +6433,284 @@ static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req
#ifndef STBI_NO_PSD
static int stbi__psd_test(stbi__context *s)
{
- int r = (stbi__get32be(s) == 0x38425053);
- stbi__rewind(s);
- return r;
+ int r = stbi__get32be(s) == 0x38425053;
+ stbi__rewind(s);
+ return r;
}
static int stbi__psd_decode_rle(stbi__context *s, stbi_uc *p, int pixelCount)
{
- int count, nleft, len;
+ int count, nleft, len;
- count = 0;
- while ((nleft = pixelCount - count) > 0) {
- len = stbi__get8(s);
- if (len == 128) {
- // No-op.
- } else if (len < 128) {
- // Copy next len+1 bytes literally.
- len++;
- if (len > nleft) return 0; // corrupt data
- count += len;
- while (len) {
- *p = stbi__get8(s);
- p += 4;
- len--;
- }
- } else if (len > 128) {
- stbi_uc val;
- // Next -len+1 bytes in the dest are replicated from next source byte.
- // (Interpret len as a negative 8-bit int.)
- len = 257 - len;
- if (len > nleft) return 0; // corrupt data
- val = stbi__get8(s);
- count += len;
- while (len) {
- *p = val;
- p += 4;
- len--;
- }
- }
- }
+ count = 0;
+ while ((nleft = pixelCount - count) > 0)
+ {
+ len = stbi__get8(s);
+ if (len == 128)
+ {
+ // No-op.
+ }
+ else if (len < 128)
+ {
+ // Copy next len+1 bytes literally.
+ len++;
+ if (len > nleft) return 0; // corrupt data
+ count += len;
+ while (len)
+ {
+ *p = stbi__get8(s);
+ p += 4;
+ len--;
+ }
+ }
+ else if (len > 128)
+ {
+ stbi_uc val;
+ // Next -len+1 bytes in the dest are replicated from next source byte.
+ // (Interpret len as a negative 8-bit int.)
+ len = 257 - len;
+ if (len > nleft) return 0; // corrupt data
+ val = stbi__get8(s);
+ count += len;
+ while (len)
+ {
+ *p = val;
+ p += 4;
+ len--;
+ }
+ }
+ }
- return 1;
+ return 1;
}
static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc)
{
- int pixelCount;
- int channelCount, compression;
- int channel, i;
- int bitdepth;
- int w,h;
- stbi_uc *out;
- STBI_NOTUSED(ri);
+ int pixelCount;
+ int channelCount, compression;
+ int channel, i;
+ int bitdepth;
+ int w, h;
+ stbi_uc *out;
+ STBI_NOTUSED(ri);
- // Check identifier
- if (stbi__get32be(s) != 0x38425053) // "8BPS"
- return stbi__errpuc("not PSD", "Corrupt PSD image");
+ // Check identifier
+ if (stbi__get32be(s) != 0x38425053) // "8BPS"
+ return stbi__errpuc("not PSD", "Corrupt PSD image");
- // Check file type version.
- if (stbi__get16be(s) != 1)
- return stbi__errpuc("wrong version", "Unsupported version of PSD image");
+ // Check file type version.
+ if (stbi__get16be(s) != 1)
+ return stbi__errpuc("wrong version", "Unsupported version of PSD image");
- // Skip 6 reserved bytes.
- stbi__skip(s, 6 );
+ // Skip 6 reserved bytes.
+ stbi__skip(s, 6);
- // Read the number of channels (R, G, B, A, etc).
- channelCount = stbi__get16be(s);
- if (channelCount < 0 || channelCount > 16)
- return stbi__errpuc("wrong channel count", "Unsupported number of channels in PSD image");
+ // Read the number of channels (R, G, B, A, etc).
+ channelCount = stbi__get16be(s);
+ if (channelCount < 0 || channelCount > 16)
+ return stbi__errpuc("wrong channel count", "Unsupported number of channels in PSD image");
- // Read the rows and columns of the image.
- h = stbi__get32be(s);
- w = stbi__get32be(s);
+ // Read the rows and columns of the image.
+ h = stbi__get32be(s);
+ w = stbi__get32be(s);
- // Make sure the depth is 8 bits.
- bitdepth = stbi__get16be(s);
- if (bitdepth != 8 && bitdepth != 16)
- return stbi__errpuc("unsupported bit depth", "PSD bit depth is not 8 or 16 bit");
+ // Make sure the depth is 8 bits.
+ bitdepth = stbi__get16be(s);
+ if (bitdepth != 8 && bitdepth != 16)
+ return stbi__errpuc("unsupported bit depth", "PSD bit depth is not 8 or 16 bit");
- // Make sure the color mode is RGB.
- // Valid options are:
- // 0: Bitmap
- // 1: Grayscale
- // 2: Indexed color
- // 3: RGB color
- // 4: CMYK color
- // 7: Multichannel
- // 8: Duotone
- // 9: Lab color
- if (stbi__get16be(s) != 3)
- return stbi__errpuc("wrong color format", "PSD is not in RGB color format");
+ // Make sure the color mode is RGB.
+ // Valid options are:
+ // 0: Bitmap
+ // 1: Grayscale
+ // 2: Indexed color
+ // 3: RGB color
+ // 4: CMYK color
+ // 7: Multichannel
+ // 8: Duotone
+ // 9: Lab color
+ if (stbi__get16be(s) != 3)
+ return stbi__errpuc("wrong color format", "PSD is not in RGB color format");
- // Skip the Mode Data. (It's the palette for indexed color; other info for other modes.)
- stbi__skip(s,stbi__get32be(s) );
+ // Skip the Mode Data. (It's the palette for indexed color; other info for other modes.)
+ stbi__skip(s, stbi__get32be(s));
- // Skip the image resources. (resolution, pen tool paths, etc)
- stbi__skip(s, stbi__get32be(s) );
+ // Skip the image resources. (resolution, pen tool paths, etc)
+ stbi__skip(s, stbi__get32be(s));
- // Skip the reserved data.
- stbi__skip(s, stbi__get32be(s) );
+ // Skip the reserved data.
+ stbi__skip(s, stbi__get32be(s));
- // Find out if the data is compressed.
- // Known values:
- // 0: no compression
- // 1: RLE compressed
- compression = stbi__get16be(s);
- if (compression > 1)
- return stbi__errpuc("bad compression", "PSD has an unknown compression format");
+ // Find out if the data is compressed.
+ // Known values:
+ // 0: no compression
+ // 1: RLE compressed
+ compression = stbi__get16be(s);
+ if (compression > 1)
+ return stbi__errpuc("bad compression", "PSD has an unknown compression format");
- // Check size
- if (!stbi__mad3sizes_valid(4, w, h, 0))
- return stbi__errpuc("too large", "Corrupt PSD");
+ // Check size
+ if (!stbi__mad3sizes_valid(4, w, h, 0))
+ return stbi__errpuc("too large", "Corrupt PSD");
- // Create the destination image.
+ // Create the destination image.
- if (!compression && bitdepth == 16 && bpc == 16) {
- out = (stbi_uc *) stbi__malloc_mad3(8, w, h, 0);
- ri->bits_per_channel = 16;
- } else
- out = (stbi_uc *) stbi__malloc(4 * w*h);
+ if (!compression && bitdepth == 16 && bpc == 16)
+ {
+ out = (stbi_uc *)stbi__malloc_mad3(8, w, h, 0);
+ ri->bits_per_channel = 16;
+ }
+ else
+ out = (stbi_uc *)stbi__malloc(4 * w * h);
- if (!out) return stbi__errpuc("outofmem", "Out of memory");
- pixelCount = w*h;
+ if (!out) return stbi__errpuc("outofmem", "Out of memory");
+ pixelCount = w * h;
- // Initialize the data to zero.
- //memset( out, 0, pixelCount * 4 );
+ // Initialize the data to zero.
+ //memset( out, 0, pixelCount * 4 );
- // Finally, the image data.
- if (compression) {
- // RLE as used by .PSD and .TIFF
- // Loop until you get the number of unpacked bytes you are expecting:
- // Read the next source byte into n.
- // If n is between 0 and 127 inclusive, copy the next n+1 bytes literally.
- // Else if n is between -127 and -1 inclusive, copy the next byte -n+1 times.
- // Else if n is 128, noop.
- // Endloop
+ // Finally, the image data.
+ if (compression)
+ {
+ // RLE as used by .PSD and .TIFF
+ // Loop until you get the number of unpacked bytes you are expecting:
+ // Read the next source byte into n.
+ // If n is between 0 and 127 inclusive, copy the next n+1 bytes literally.
+ // Else if n is between -127 and -1 inclusive, copy the next byte -n+1 times.
+ // Else if n is 128, noop.
+ // Endloop
- // The RLE-compressed data is preceeded by a 2-byte data count for each row in the data,
- // which we're going to just skip.
- stbi__skip(s, h * channelCount * 2 );
+ // The RLE-compressed data is preceeded by a 2-byte data count for each row in the data,
+ // which we're going to just skip.
+ stbi__skip(s, h * channelCount * 2);
- // Read the RLE data by channel.
- for (channel = 0; channel < 4; channel++) {
- stbi_uc *p;
+ // Read the RLE data by channel.
+ for (channel = 0; channel < 4; channel++)
+ {
+ stbi_uc *p;
- p = out+channel;
- if (channel >= channelCount) {
- // Fill this channel with default data.
- for (i = 0; i < pixelCount; i++, p += 4)
- *p = (channel == 3 ? 255 : 0);
- } else {
- // Read the RLE data.
- if (!stbi__psd_decode_rle(s, p, pixelCount)) {
- STBI_FREE(out);
- return stbi__errpuc("corrupt", "bad RLE data");
+ p = out + channel;
+ if (channel >= channelCount)
+ {
+ // Fill this channel with default data.
+ for (i = 0; i < pixelCount; i++, p += 4)
+ *p = channel == 3 ? 255 : 0;
}
- }
- }
-
- } else {
- // We're at the raw image data. It's each channel in order (Red, Green, Blue, Alpha, ...)
- // where each channel consists of an 8-bit (or 16-bit) value for each pixel in the image.
-
- // Read the data by channel.
- for (channel = 0; channel < 4; channel++) {
- if (channel >= channelCount) {
- // Fill this channel with default data.
- if (bitdepth == 16 && bpc == 16) {
- stbi__uint16 *q = ((stbi__uint16 *) out) + channel;
- stbi__uint16 val = channel == 3 ? 65535 : 0;
- for (i = 0; i < pixelCount; i++, q += 4)
- *q = val;
- } else {
- stbi_uc *p = out+channel;
- stbi_uc val = channel == 3 ? 255 : 0;
- for (i = 0; i < pixelCount; i++, p += 4)
- *p = val;
+ else
+ {
+ // Read the RLE data.
+ if (!stbi__psd_decode_rle(s, p, pixelCount))
+ {
+ STBI_FREE(out);
+ return stbi__errpuc("corrupt", "bad RLE data");
+ }
}
- } else {
- if (ri->bits_per_channel == 16) { // output bpc
- stbi__uint16 *q = ((stbi__uint16 *) out) + channel;
- for (i = 0; i < pixelCount; i++, q += 4)
- *q = (stbi__uint16) stbi__get16be(s);
- } else {
- stbi_uc *p = out+channel;
- if (bitdepth == 16) { // input bpc
- for (i = 0; i < pixelCount; i++, p += 4)
- *p = (stbi_uc) (stbi__get16be(s) >> 8);
- } else {
- for (i = 0; i < pixelCount; i++, p += 4)
- *p = stbi__get8(s);
- }
+ }
+ }
+ else
+ {
+ // We're at the raw image data. It's each channel in order (Red, Green, Blue, Alpha, ...)
+ // where each channel consists of an 8-bit (or 16-bit) value for each pixel in the image.
+
+ // Read the data by channel.
+ for (channel = 0; channel < 4; channel++)
+ {
+ if (channel >= channelCount)
+ {
+ // Fill this channel with default data.
+ if (bitdepth == 16 && bpc == 16)
+ {
+ stbi__uint16 *q = (stbi__uint16 *)out + channel;
+ stbi__uint16 val = channel == 3 ? 65535 : 0;
+ for (i = 0; i < pixelCount; i++, q += 4)
+ *q = val;
+ }
+ else
+ {
+ stbi_uc *p = out + channel;
+ stbi_uc val = channel == 3 ? 255 : 0;
+ for (i = 0; i < pixelCount; i++, p += 4)
+ *p = val;
+ }
}
- }
- }
- }
-
- // remove weird white matte from PSD
- if (channelCount >= 4) {
- if (ri->bits_per_channel == 16) {
- for (i=0; i < w*h; ++i) {
- stbi__uint16 *pixel = (stbi__uint16 *) out + 4*i;
- if (pixel[3] != 0 && pixel[3] != 65535) {
- float a = pixel[3] / 65535.0f;
- float ra = 1.0f / a;
- float inv_a = 65535.0f * (1 - ra);
- pixel[0] = (stbi__uint16) (pixel[0]*ra + inv_a);
- pixel[1] = (stbi__uint16) (pixel[1]*ra + inv_a);
- pixel[2] = (stbi__uint16) (pixel[2]*ra + inv_a);
+ else
+ {
+ if (ri->bits_per_channel == 16)
+ { // output bpc
+ stbi__uint16 *q = (stbi__uint16 *)out + channel;
+ for (i = 0; i < pixelCount; i++, q += 4)
+ *q = (stbi__uint16)stbi__get16be(s);
+ }
+ else
+ {
+ stbi_uc *p = out + channel;
+ if (bitdepth == 16)
+ { // input bpc
+ for (i = 0; i < pixelCount; i++, p += 4)
+ *p = (stbi_uc)(stbi__get16be(s) >> 8);
+ }
+ else
+ {
+ for (i = 0; i < pixelCount; i++, p += 4)
+ *p = stbi__get8(s);
+ }
+ }
}
- }
- } else {
- for (i=0; i < w*h; ++i) {
- unsigned char *pixel = out + 4*i;
- if (pixel[3] != 0 && pixel[3] != 255) {
- float a = pixel[3] / 255.0f;
- float ra = 1.0f / a;
- float inv_a = 255.0f * (1 - ra);
- pixel[0] = (unsigned char) (pixel[0]*ra + inv_a);
- pixel[1] = (unsigned char) (pixel[1]*ra + inv_a);
- pixel[2] = (unsigned char) (pixel[2]*ra + inv_a);
+ }
+ }
+
+ // remove weird white matte from PSD
+ if (channelCount >= 4)
+ {
+ if (ri->bits_per_channel == 16)
+ {
+ for (i = 0; i < w * h; ++i)
+ {
+ stbi__uint16 *pixel = (stbi__uint16 *)out + 4 * i;
+ if (pixel[3] != 0 && pixel[3] != 65535)
+ {
+ float a = pixel[3] / 65535.0f;
+ float ra = 1.0f / a;
+ float inv_a = 65535.0f * (1 - ra);
+ pixel[0] = (stbi__uint16)(pixel[0] * ra + inv_a);
+ pixel[1] = (stbi__uint16)(pixel[1] * ra + inv_a);
+ pixel[2] = (stbi__uint16)(pixel[2] * ra + inv_a);
+ }
}
- }
- }
- }
+ }
+ else
+ {
+ for (i = 0; i < w * h; ++i)
+ {
+ unsigned char *pixel = out + 4 * i;
+ if (pixel[3] != 0 && pixel[3] != 255)
+ {
+ float a = pixel[3] / 255.0f;
+ float ra = 1.0f / a;
+ float inv_a = 255.0f * (1 - ra);
+ pixel[0] = (unsigned char)(pixel[0] * ra + inv_a);
+ pixel[1] = (unsigned char)(pixel[1] * ra + inv_a);
+ pixel[2] = (unsigned char)(pixel[2] * ra + inv_a);
+ }
+ }
+ }
+ }
- // convert to desired output format
- if (req_comp && req_comp != 4) {
- if (ri->bits_per_channel == 16)
- out = (stbi_uc *) stbi__convert_format16((stbi__uint16 *) out, 4, req_comp, w, h);
- else
- out = stbi__convert_format(out, 4, req_comp, w, h);
- if (out == NULL) return out; // stbi__convert_format frees input on failure
- }
+ // convert to desired output format
+ if (req_comp && req_comp != 4)
+ {
+ if (ri->bits_per_channel == 16)
+ out = (stbi_uc *)stbi__convert_format16((stbi__uint16 *)out, 4, req_comp, w, h);
+ else
+ out = stbi__convert_format(out, 4, req_comp, w, h);
+ if (out == NULL) return out; // stbi__convert_format frees input on failure
+ }
- if (comp) *comp = 4;
- *y = h;
- *x = w;
+ if (comp) *comp = 4;
+ *y = h;
+ *x = w;
- return out;
+ return out;
}
#endif
@@ -5903,211 +6722,226 @@ static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req
// See http://ozviz.wasp.uwa.edu.au/~pbourke/dataformats/softimagepic/
#ifndef STBI_NO_PIC
-static int stbi__pic_is4(stbi__context *s,const char *str)
+static int stbi__pic_is4(stbi__context *s, const char *str)
{
- int i;
- for (i=0; i<4; ++i)
- if (stbi__get8(s) != (stbi_uc)str[i])
- return 0;
+ int i;
+ for (i = 0; i < 4; ++i)
+ if (stbi__get8(s) != (stbi_uc)str[i])
+ return 0;
- return 1;
+ return 1;
}
static int stbi__pic_test_core(stbi__context *s)
{
- int i;
+ int i;
- if (!stbi__pic_is4(s,"\x53\x80\xF6\x34"))
- return 0;
+ if (!stbi__pic_is4(s, "\x53\x80\xF6\x34"))
+ return 0;
- for(i=0;i<84;++i)
- stbi__get8(s);
+ for (i = 0; i < 84; ++i)
+ stbi__get8(s);
- if (!stbi__pic_is4(s,"PICT"))
- return 0;
+ if (!stbi__pic_is4(s, "PICT"))
+ return 0;
- return 1;
+ return 1;
}
typedef struct
{
- stbi_uc size,type,channel;
+ stbi_uc size, type, channel;
} stbi__pic_packet;
static stbi_uc *stbi__readval(stbi__context *s, int channel, stbi_uc *dest)
{
- int mask=0x80, i;
+ int mask = 0x80, i;
- for (i=0; i<4; ++i, mask>>=1) {
- if (channel & mask) {
- if (stbi__at_eof(s)) return stbi__errpuc("bad file","PIC file too short");
- dest[i]=stbi__get8(s);
- }
- }
+ for (i = 0; i < 4; ++i, mask >>= 1)
+ {
+ if (channel & mask)
+ {
+ if (stbi__at_eof(s)) return stbi__errpuc("bad file", "PIC file too short");
+ dest[i] = stbi__get8(s);
+ }
+ }
- return dest;
+ return dest;
}
-static void stbi__copyval(int channel,stbi_uc *dest,const stbi_uc *src)
+static void stbi__copyval(int channel, stbi_uc *dest, const stbi_uc *src)
{
- int mask=0x80,i;
+ int mask = 0x80, i;
- for (i=0;i<4; ++i, mask>>=1)
- if (channel&mask)
- dest[i]=src[i];
+ for (i = 0; i < 4; ++i, mask >>= 1)
+ if (channel & mask)
+ dest[i] = src[i];
}
-static stbi_uc *stbi__pic_load_core(stbi__context *s,int width,int height,int *comp, stbi_uc *result)
+static stbi_uc *stbi__pic_load_core(stbi__context *s, int width, int height, int *comp, stbi_uc *result)
{
- int act_comp=0,num_packets=0,y,chained;
- stbi__pic_packet packets[10];
+ int act_comp = 0, num_packets = 0, y, chained;
+ stbi__pic_packet packets[10];
- // this will (should...) cater for even some bizarre stuff like having data
+ // this will (should...) cater for even some bizarre stuff like having data
// for the same channel in multiple packets.
- do {
- stbi__pic_packet *packet;
+ do
+ {
+ stbi__pic_packet *packet;
- if (num_packets==sizeof(packets)/sizeof(packets[0]))
- return stbi__errpuc("bad format","too many packets");
+ if (num_packets == sizeof(packets) / sizeof(packets[0]))
+ return stbi__errpuc("bad format", "too many packets");
- packet = &packets[num_packets++];
+ packet = &packets[num_packets++];
- chained = stbi__get8(s);
- packet->size = stbi__get8(s);
- packet->type = stbi__get8(s);
- packet->channel = stbi__get8(s);
+ chained = stbi__get8(s);
+ packet->size = stbi__get8(s);
+ packet->type = stbi__get8(s);
+ packet->channel = stbi__get8(s);
- act_comp |= packet->channel;
+ act_comp |= packet->channel;
- if (stbi__at_eof(s)) return stbi__errpuc("bad file","file too short (reading packets)");
- if (packet->size != 8) return stbi__errpuc("bad format","packet isn't 8bpp");
- } while (chained);
+ if (stbi__at_eof(s)) return stbi__errpuc("bad file", "file too short (reading packets)");
+ if (packet->size != 8) return stbi__errpuc("bad format", "packet isn't 8bpp");
+ }
+ while (chained);
- *comp = (act_comp & 0x10 ? 4 : 3); // has alpha channel?
+ *comp = act_comp & 0x10 ? 4 : 3; // has alpha channel?
- for(y=0; ytype) {
- default:
- return stbi__errpuc("bad format","packet has bad compression type");
+ switch (packet->type)
+ {
+ default:
+ return stbi__errpuc("bad format", "packet has bad compression type");
- case 0: {//uncompressed
- int x;
+ case 0:
+ { //uncompressed
+ int x;
- for(x=0;xchannel,dest))
- return 0;
- break;
+ for (x = 0; x < width; ++x, dest += 4)
+ if (!stbi__readval(s, packet->channel, dest))
+ return 0;
+ break;
+ }
+
+ case 1: //Pure RLE
+ {
+ int left = width, i;
+
+ while (left > 0)
+ {
+ stbi_uc count, value[4];
+
+ count = stbi__get8(s);
+ if (stbi__at_eof(s)) return stbi__errpuc("bad file", "file too short (pure read count)");
+
+ if (count > left)
+ count = (stbi_uc)left;
+
+ if (!stbi__readval(s, packet->channel, value)) return 0;
+
+ for (i = 0; i < count; ++i, dest += 4)
+ stbi__copyval(packet->channel, dest, value);
+ left -= count;
+ }
+ }
+ break;
+
+ case 2:
+ { //Mixed RLE
+ int left = width;
+ while (left > 0)
+ {
+ int count = stbi__get8(s), i;
+ if (stbi__at_eof(s)) return stbi__errpuc("bad file", "file too short (mixed read count)");
+
+ if (count >= 128)
+ { // Repeated
+ stbi_uc value[4];
+
+ if (count == 128)
+ count = stbi__get16be(s);
+ else
+ count -= 127;
+ if (count > left)
+ return stbi__errpuc("bad file", "scanline overrun");
+
+ if (!stbi__readval(s, packet->channel, value))
+ return 0;
+
+ for (i = 0; i < count; ++i, dest += 4)
+ stbi__copyval(packet->channel, dest, value);
+ }
+ else
+ { // Raw
+ ++count;
+ if (count > left) return stbi__errpuc("bad file", "scanline overrun");
+
+ for (i = 0; i < count; ++i, dest += 4)
+ if (!stbi__readval(s, packet->channel, dest))
+ return 0;
+ }
+ left -= count;
+ }
+ break;
+ }
}
+ }
+ }
- case 1://Pure RLE
- {
- int left=width, i;
-
- while (left>0) {
- stbi_uc count,value[4];
-
- count=stbi__get8(s);
- if (stbi__at_eof(s)) return stbi__errpuc("bad file","file too short (pure read count)");
-
- if (count > left)
- count = (stbi_uc) left;
-
- if (!stbi__readval(s,packet->channel,value)) return 0;
-
- for(i=0; ichannel,dest,value);
- left -= count;
- }
- }
- break;
-
- case 2: {//Mixed RLE
- int left=width;
- while (left>0) {
- int count = stbi__get8(s), i;
- if (stbi__at_eof(s)) return stbi__errpuc("bad file","file too short (mixed read count)");
-
- if (count >= 128) { // Repeated
- stbi_uc value[4];
-
- if (count==128)
- count = stbi__get16be(s);
- else
- count -= 127;
- if (count > left)
- return stbi__errpuc("bad file","scanline overrun");
-
- if (!stbi__readval(s,packet->channel,value))
- return 0;
-
- for(i=0;ichannel,dest,value);
- } else { // Raw
- ++count;
- if (count>left) return stbi__errpuc("bad file","scanline overrun");
-
- for(i=0;ichannel,dest))
- return 0;
- }
- left-=count;
- }
- break;
- }
- }
- }
- }
-
- return result;
+ return result;
}
-static void *stbi__pic_load(stbi__context *s,int *px,int *py,int *comp,int req_comp, stbi__result_info *ri)
+static void *stbi__pic_load(stbi__context *s, int *px, int *py, int *comp, int req_comp, stbi__result_info *ri)
{
- stbi_uc *result;
- int i, x,y, internal_comp;
- STBI_NOTUSED(ri);
+ stbi_uc *result;
+ int i, x, y, internal_comp;
+ STBI_NOTUSED(ri);
- if (!comp) comp = &internal_comp;
+ if (!comp) comp = &internal_comp;
- for (i=0; i<92; ++i)
- stbi__get8(s);
+ for (i = 0; i < 92; ++i)
+ stbi__get8(s);
- x = stbi__get16be(s);
- y = stbi__get16be(s);
- if (stbi__at_eof(s)) return stbi__errpuc("bad file","file too short (pic header)");
- if (!stbi__mad3sizes_valid(x, y, 4, 0)) return stbi__errpuc("too large", "PIC image too large to decode");
+ x = stbi__get16be(s);
+ y = stbi__get16be(s);
+ if (stbi__at_eof(s)) return stbi__errpuc("bad file", "file too short (pic header)");
+ if (!stbi__mad3sizes_valid(x, y, 4, 0)) return stbi__errpuc("too large", "PIC image too large to decode");
- stbi__get32be(s); //skip `ratio'
- stbi__get16be(s); //skip `fields'
- stbi__get16be(s); //skip `pad'
+ stbi__get32be(s); //skip `ratio'
+ stbi__get16be(s); //skip `fields'
+ stbi__get16be(s); //skip `pad'
- // intermediate buffer is RGBA
- result = (stbi_uc *) stbi__malloc_mad3(x, y, 4, 0);
- memset(result, 0xff, x*y*4);
+ // intermediate buffer is RGBA
+ result = (stbi_uc *)stbi__malloc_mad3(x, y, 4, 0);
+ memset(result, 0xff, x * y * 4);
- if (!stbi__pic_load_core(s,x,y,comp, result)) {
- STBI_FREE(result);
- result=0;
- }
- *px = x;
- *py = y;
- if (req_comp == 0) req_comp = *comp;
- result=stbi__convert_format(result,4,req_comp,x,y);
+ if (!stbi__pic_load_core(s, x, y, comp, result))
+ {
+ STBI_FREE(result);
+ result = 0;
+ }
+ *px = x;
+ *py = y;
+ if (req_comp == 0) req_comp = *comp;
+ result = stbi__convert_format(result, 4, req_comp, x, y);
- return result;
+ return result;
}
static int stbi__pic_test(stbi__context *s)
{
- int r = stbi__pic_test_core(s);
- stbi__rewind(s);
- return r;
+ int r = stbi__pic_test_core(s);
+ stbi__rewind(s);
+ return r;
}
#endif
@@ -6117,477 +6951,550 @@ static int stbi__pic_test(stbi__context *s)
#ifndef STBI_NO_GIF
typedef struct
{
- stbi__int16 prefix;
- stbi_uc first;
- stbi_uc suffix;
+ stbi__int16 prefix;
+ stbi_uc first;
+ stbi_uc suffix;
} stbi__gif_lzw;
typedef struct
{
- int w,h;
- stbi_uc *out; // output buffer (always 4 components)
- stbi_uc *background; // The current "background" as far as a gif is concerned
- stbi_uc *history;
- int flags, bgindex, ratio, transparent, eflags;
- stbi_uc pal[256][4];
- stbi_uc lpal[256][4];
- stbi__gif_lzw codes[8192];
- stbi_uc *color_table;
- int parse, step;
- int lflags;
- int start_x, start_y;
- int max_x, max_y;
- int cur_x, cur_y;
- int line_size;
- int delay;
+ int w, h;
+ stbi_uc *out; // output buffer (always 4 components)
+ stbi_uc *background; // The current "background" as far as a gif is concerned
+ stbi_uc *history;
+ int flags, bgindex, ratio, transparent, eflags;
+ stbi_uc pal[256][4];
+ stbi_uc lpal[256][4];
+ stbi__gif_lzw codes[8192];
+ stbi_uc *color_table;
+ int parse, step;
+ int lflags;
+ int start_x, start_y;
+ int max_x, max_y;
+ int cur_x, cur_y;
+ int line_size;
+ int delay;
} stbi__gif;
static int stbi__gif_test_raw(stbi__context *s)
{
- int sz;
- if (stbi__get8(s) != 'G' || stbi__get8(s) != 'I' || stbi__get8(s) != 'F' || stbi__get8(s) != '8') return 0;
- sz = stbi__get8(s);
- if (sz != '9' && sz != '7') return 0;
- if (stbi__get8(s) != 'a') return 0;
- return 1;
+ int sz;
+ if (stbi__get8(s) != 'G' || stbi__get8(s) != 'I' || stbi__get8(s) != 'F' || stbi__get8(s) != '8') return 0;
+ sz = stbi__get8(s);
+ if (sz != '9' && sz != '7') return 0;
+ if (stbi__get8(s) != 'a') return 0;
+ return 1;
}
static int stbi__gif_test(stbi__context *s)
{
- int r = stbi__gif_test_raw(s);
- stbi__rewind(s);
- return r;
+ int r = stbi__gif_test_raw(s);
+ stbi__rewind(s);
+ return r;
}
static void stbi__gif_parse_colortable(stbi__context *s, stbi_uc pal[256][4], int num_entries, int transp)
{
- int i;
- for (i=0; i < num_entries; ++i) {
- pal[i][2] = stbi__get8(s);
- pal[i][1] = stbi__get8(s);
- pal[i][0] = stbi__get8(s);
- pal[i][3] = transp == i ? 0 : 255;
- }
+ int i;
+ for (i = 0; i < num_entries; ++i)
+ {
+ pal[i][2] = stbi__get8(s);
+ pal[i][1] = stbi__get8(s);
+ pal[i][0] = stbi__get8(s);
+ pal[i][3] = transp == i ? 0 : 255;
+ }
}
static int stbi__gif_header(stbi__context *s, stbi__gif *g, int *comp, int is_info)
{
- stbi_uc version;
- if (stbi__get8(s) != 'G' || stbi__get8(s) != 'I' || stbi__get8(s) != 'F' || stbi__get8(s) != '8')
- return stbi__err("not GIF", "Corrupt GIF");
+ stbi_uc version;
+ if (stbi__get8(s) != 'G' || stbi__get8(s) != 'I' || stbi__get8(s) != 'F' || stbi__get8(s) != '8')
+ return stbi__err("not GIF", "Corrupt GIF");
- version = stbi__get8(s);
- if (version != '7' && version != '9') return stbi__err("not GIF", "Corrupt GIF");
- if (stbi__get8(s) != 'a') return stbi__err("not GIF", "Corrupt GIF");
+ version = stbi__get8(s);
+ if (version != '7' && version != '9') return stbi__err("not GIF", "Corrupt GIF");
+ if (stbi__get8(s) != 'a') return stbi__err("not GIF", "Corrupt GIF");
- stbi__g_failure_reason = "";
- g->w = stbi__get16le(s);
- g->h = stbi__get16le(s);
- g->flags = stbi__get8(s);
- g->bgindex = stbi__get8(s);
- g->ratio = stbi__get8(s);
- g->transparent = -1;
+ stbi__g_failure_reason = "";
+ g->w = stbi__get16le(s);
+ g->h = stbi__get16le(s);
+ g->flags = stbi__get8(s);
+ g->bgindex = stbi__get8(s);
+ g->ratio = stbi__get8(s);
+ g->transparent = -1;
- if (comp != 0) *comp = 4; // can't actually tell whether it's 3 or 4 until we parse the comments
+ if (comp != 0) *comp = 4; // can't actually tell whether it's 3 or 4 until we parse the comments
- if (is_info) return 1;
+ if (is_info) return 1;
- if (g->flags & 0x80)
- stbi__gif_parse_colortable(s,g->pal, 2 << (g->flags & 7), -1);
+ if (g->flags & 0x80)
+ stbi__gif_parse_colortable(s, g->pal, 2 << (g->flags & 7), -1);
- return 1;
+ return 1;
}
static int stbi__gif_info_raw(stbi__context *s, int *x, int *y, int *comp)
{
- stbi__gif* g = (stbi__gif*) stbi__malloc(sizeof(stbi__gif));
- if (!stbi__gif_header(s, g, comp, 1)) {
- STBI_FREE(g);
- stbi__rewind( s );
- return 0;
- }
- if (x) *x = g->w;
- if (y) *y = g->h;
- STBI_FREE(g);
- return 1;
+ stbi__gif *g = stbi__malloc(sizeof(stbi__gif));
+ if (!stbi__gif_header(s, g, comp, 1))
+ {
+ STBI_FREE(g);
+ stbi__rewind(s);
+ return 0;
+ }
+ if (x) *x = g->w;
+ if (y) *y = g->h;
+ STBI_FREE(g);
+ return 1;
}
static void stbi__out_gif_code(stbi__gif *g, stbi__uint16 code)
{
- stbi_uc *p, *c;
- int idx;
+ stbi_uc *p, *c;
+ int idx;
- // recurse to decode the prefixes, since the linked-list is backwards,
- // and working backwards through an interleaved image would be nasty
- if (g->codes[code].prefix >= 0)
- stbi__out_gif_code(g, g->codes[code].prefix);
+ // recurse to decode the prefixes, since the linked-list is backwards,
+ // and working backwards through an interleaved image would be nasty
+ if (g->codes[code].prefix >= 0)
+ stbi__out_gif_code(g, g->codes[code].prefix);
- if (g->cur_y >= g->max_y) return;
+ if (g->cur_y >= g->max_y) return;
- idx = g->cur_x + g->cur_y;
- p = &g->out[idx];
- g->history[idx / 4] = 1;
+ idx = g->cur_x + g->cur_y;
+ p = &g->out[idx];
+ g->history[idx / 4] = 1;
- c = &g->color_table[g->codes[code].suffix * 4];
- if (c[3] > 128) { // don't render transparent pixels;
- p[0] = c[2];
- p[1] = c[1];
- p[2] = c[0];
- p[3] = c[3];
- }
- g->cur_x += 4;
+ c = &g->color_table[g->codes[code].suffix * 4];
+ if (c[3] > 128)
+ { // don't render transparent pixels;
+ p[0] = c[2];
+ p[1] = c[1];
+ p[2] = c[0];
+ p[3] = c[3];
+ }
+ g->cur_x += 4;
- if (g->cur_x >= g->max_x) {
- g->cur_x = g->start_x;
- g->cur_y += g->step;
+ if (g->cur_x >= g->max_x)
+ {
+ g->cur_x = g->start_x;
+ g->cur_y += g->step;
- while (g->cur_y >= g->max_y && g->parse > 0) {
- g->step = (1 << g->parse) * g->line_size;
- g->cur_y = g->start_y + (g->step >> 1);
- --g->parse;
- }
- }
+ while (g->cur_y >= g->max_y && g->parse > 0)
+ {
+ g->step = (1 << g->parse) * g->line_size;
+ g->cur_y = g->start_y + (g->step >> 1);
+ --g->parse;
+ }
+ }
}
static stbi_uc *stbi__process_gif_raster(stbi__context *s, stbi__gif *g)
{
- stbi_uc lzw_cs;
- stbi__int32 len, init_code;
- stbi__uint32 first;
- stbi__int32 codesize, codemask, avail, oldcode, bits, valid_bits, clear;
- stbi__gif_lzw *p;
+ stbi_uc lzw_cs;
+ stbi__int32 len, init_code;
+ stbi__uint32 first;
+ stbi__int32 codesize, codemask, avail, oldcode, bits, valid_bits, clear;
+ stbi__gif_lzw *p;
- lzw_cs = stbi__get8(s);
- if (lzw_cs > 12) return NULL;
- clear = 1 << lzw_cs;
- first = 1;
- codesize = lzw_cs + 1;
- codemask = (1 << codesize) - 1;
- bits = 0;
- valid_bits = 0;
- for (init_code = 0; init_code < clear; init_code++) {
- g->codes[init_code].prefix = -1;
- g->codes[init_code].first = (stbi_uc) init_code;
- g->codes[init_code].suffix = (stbi_uc) init_code;
- }
+ lzw_cs = stbi__get8(s);
+ if (lzw_cs > 12) return NULL;
+ clear = 1 << lzw_cs;
+ first = 1;
+ codesize = lzw_cs + 1;
+ codemask = (1 << codesize) - 1;
+ bits = 0;
+ valid_bits = 0;
+ for (init_code = 0; init_code < clear; init_code++)
+ {
+ g->codes[init_code].prefix = -1;
+ g->codes[init_code].first = (stbi_uc)init_code;
+ g->codes[init_code].suffix = (stbi_uc)init_code;
+ }
- // support no starting clear code
- avail = clear+2;
- oldcode = -1;
+ // support no starting clear code
+ avail = clear + 2;
+ oldcode = -1;
- len = 0;
- for(;;) {
- if (valid_bits < codesize) {
- if (len == 0) {
- len = stbi__get8(s); // start new block
+ len = 0;
+ for (;;)
+ {
+ if (valid_bits < codesize)
+ {
if (len == 0)
- return g->out;
- }
- --len;
- bits |= (stbi__int32) stbi__get8(s) << valid_bits;
- valid_bits += 8;
- } else {
- stbi__int32 code = bits & codemask;
- bits >>= codesize;
- valid_bits -= codesize;
- // @OPTIMIZE: is there some way we can accelerate the non-clear path?
- if (code == clear) { // clear code
- codesize = lzw_cs + 1;
- codemask = (1 << codesize) - 1;
- avail = clear + 2;
- oldcode = -1;
- first = 0;
- } else if (code == clear + 1) { // end of stream code
- stbi__skip(s, len);
- while ((len = stbi__get8(s)) > 0)
- stbi__skip(s,len);
- return g->out;
- } else if (code <= avail) {
- if (first) {
- return stbi__errpuc("no clear code", "Corrupt GIF");
+ {
+ len = stbi__get8(s); // start new block
+ if (len == 0)
+ return g->out;
}
-
- if (oldcode >= 0) {
- p = &g->codes[avail++];
- if (avail > 8192) {
- return stbi__errpuc("too many codes", "Corrupt GIF");
- }
-
- p->prefix = (stbi__int16) oldcode;
- p->first = g->codes[oldcode].first;
- p->suffix = (code == avail) ? p->first : g->codes[code].first;
- } else if (code == avail)
- return stbi__errpuc("illegal code in raster", "Corrupt GIF");
-
- stbi__out_gif_code(g, (stbi__uint16) code);
-
- if ((avail & codemask) == 0 && avail <= 0x0FFF) {
- codesize++;
- codemask = (1 << codesize) - 1;
+ --len;
+ bits |= (stbi__int32)stbi__get8(s) << valid_bits;
+ valid_bits += 8;
+ }
+ else
+ {
+ stbi__int32 code = bits & codemask;
+ bits >>= codesize;
+ valid_bits -= codesize;
+ // @OPTIMIZE: is there some way we can accelerate the non-clear path?
+ if (code == clear)
+ { // clear code
+ codesize = lzw_cs + 1;
+ codemask = (1 << codesize) - 1;
+ avail = clear + 2;
+ oldcode = -1;
+ first = 0;
}
+ else if (code == clear + 1)
+ { // end of stream code
+ stbi__skip(s, len);
+ while ((len = stbi__get8(s)) > 0)
+ stbi__skip(s, len);
+ return g->out;
+ }
+ else if (code <= avail)
+ {
+ if (first)
+ {
+ return stbi__errpuc("no clear code", "Corrupt GIF");
+ }
- oldcode = code;
- } else {
- return stbi__errpuc("illegal code in raster", "Corrupt GIF");
- }
- }
- }
+ if (oldcode >= 0)
+ {
+ p = &g->codes[avail++];
+ if (avail > 8192)
+ {
+ return stbi__errpuc("too many codes", "Corrupt GIF");
+ }
+
+ p->prefix = (stbi__int16)oldcode;
+ p->first = g->codes[oldcode].first;
+ p->suffix = code == avail ? p->first : g->codes[code].first;
+ }
+ else if (code == avail)
+ return stbi__errpuc("illegal code in raster", "Corrupt GIF");
+
+ stbi__out_gif_code(g, (stbi__uint16)code);
+
+ if ((avail & codemask) == 0 && avail <= 0x0FFF)
+ {
+ codesize++;
+ codemask = (1 << codesize) - 1;
+ }
+
+ oldcode = code;
+ }
+ else
+ {
+ return stbi__errpuc("illegal code in raster", "Corrupt GIF");
+ }
+ }
+ }
}
// this function is designed to support animated gifs, although stb_image doesn't support it
// two back is the image from two frames ago, used for a very specific disposal format
static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, int req_comp, stbi_uc *two_back)
{
- int dispose;
- int first_frame;
- int pi;
- int pcount;
+ int dispose;
+ int first_frame;
+ int pi;
+ int pcount;
- // on first frame, any non-written pixels get the background colour (non-transparent)
- first_frame = 0;
- if (g->out == 0) {
- if (!stbi__gif_header(s, g, comp,0)) return 0; // stbi__g_failure_reason set by stbi__gif_header
- g->out = (stbi_uc *) stbi__malloc(4 * g->w * g->h);
- g->background = (stbi_uc *) stbi__malloc(4 * g->w * g->h);
- g->history = (stbi_uc *) stbi__malloc(g->w * g->h);
- if (g->out == 0) return stbi__errpuc("outofmem", "Out of memory");
+ // on first frame, any non-written pixels get the background colour (non-transparent)
+ first_frame = 0;
+ if (g->out == 0)
+ {
+ if (!stbi__gif_header(s, g, comp, 0)) return 0; // stbi__g_failure_reason set by stbi__gif_header
+ g->out = (stbi_uc *)stbi__malloc(4 * g->w * g->h);
+ g->background = (stbi_uc *)stbi__malloc(4 * g->w * g->h);
+ g->history = (stbi_uc *)stbi__malloc(g->w * g->h);
+ if (g->out == 0) return stbi__errpuc("outofmem", "Out of memory");
- // image is treated as "tranparent" at the start - ie, nothing overwrites the current background;
- // background colour is only used for pixels that are not rendered first frame, after that "background"
- // color refers to teh color that was there the previous frame.
- memset( g->out, 0x00, 4 * g->w * g->h );
- memset( g->background, 0x00, 4 * g->w * g->h ); // state of the background (starts transparent)
- memset( g->history, 0x00, g->w * g->h ); // pixels that were affected previous frame
- first_frame = 1;
- } else {
- // second frame - how do we dispoase of the previous one?
- dispose = (g->eflags & 0x1C) >> 2;
- pcount = g->w * g->h;
+ // image is treated as "tranparent" at the start - ie, nothing overwrites the current background;
+ // background colour is only used for pixels that are not rendered first frame, after that "background"
+ // color refers to teh color that was there the previous frame.
+ memset(g->out, 0x00, 4 * g->w * g->h);
+ memset(g->background, 0x00, 4 * g->w * g->h); // state of the background (starts transparent)
+ memset(g->history, 0x00, g->w * g->h); // pixels that were affected previous frame
+ first_frame = 1;
+ }
+ else
+ {
+ // second frame - how do we dispoase of the previous one?
+ dispose = (g->eflags & 0x1C) >> 2;
+ pcount = g->w * g->h;
- if ((dispose == 3) && (two_back == 0)) {
- dispose = 2; // if I don't have an image to revert back to, default to the old background
- }
+ if (dispose == 3 && two_back == 0)
+ {
+ dispose = 2; // if I don't have an image to revert back to, default to the old background
+ }
- if (dispose == 3) { // use previous graphic
- for (pi = 0; pi < pcount; ++pi) {
- if (g->history[pi]) {
- memcpy( &g->out[pi * 4], &two_back[pi * 4], 4 );
+ if (dispose == 3)
+ { // use previous graphic
+ for (pi = 0; pi < pcount; ++pi)
+ {
+ if (g->history[pi])
+ {
+ memcpy(&g->out[pi * 4], &two_back[pi * 4], 4);
+ }
}
- }
- } else if (dispose == 2) {
- // restore what was changed last frame to background before that frame;
- for (pi = 0; pi < pcount; ++pi) {
- if (g->history[pi]) {
- memcpy( &g->out[pi * 4], &g->background[pi * 4], 4 );
+ }
+ else if (dispose == 2)
+ {
+ // restore what was changed last frame to background before that frame;
+ for (pi = 0; pi < pcount; ++pi)
+ {
+ if (g->history[pi])
+ {
+ memcpy(&g->out[pi * 4], &g->background[pi * 4], 4);
+ }
}
- }
- } else {
- // This is a non-disposal case eithe way, so just
- // leave the pixels as is, and they will become the new background
- // 1: do not dispose
- // 0: not specified.
- }
+ }
+ else
+ {
+ // This is a non-disposal case eithe way, so just
+ // leave the pixels as is, and they will become the new background
+ // 1: do not dispose
+ // 0: not specified.
+ }
- // background is what out is after the undoing of the previou frame;
- memcpy( g->background, g->out, 4 * g->w * g->h );
- }
+ // background is what out is after the undoing of the previou frame;
+ memcpy(g->background, g->out, 4 * g->w * g->h);
+ }
- // clear my history;
- memset( g->history, 0x00, g->w * g->h ); // pixels that were affected previous frame
+ // clear my history;
+ memset(g->history, 0x00, g->w * g->h); // pixels that were affected previous frame
- for (;;) {
- int tag = stbi__get8(s);
- switch (tag) {
- case 0x2C: /* Image Descriptor */
- {
- stbi__int32 x, y, w, h;
- stbi_uc *o;
+ for (;;)
+ {
+ int tag = stbi__get8(s);
+ switch (tag)
+ {
+ case 0x2C: /* Image Descriptor */
+ {
+ stbi__int32 x, y, w, h;
+ stbi_uc *o;
- x = stbi__get16le(s);
- y = stbi__get16le(s);
- w = stbi__get16le(s);
- h = stbi__get16le(s);
- if (((x + w) > (g->w)) || ((y + h) > (g->h)))
- return stbi__errpuc("bad Image Descriptor", "Corrupt GIF");
+ x = stbi__get16le(s);
+ y = stbi__get16le(s);
+ w = stbi__get16le(s);
+ h = stbi__get16le(s);
+ if (x + w > g->w || y + h > g->h)
+ return stbi__errpuc("bad Image Descriptor", "Corrupt GIF");
- g->line_size = g->w * 4;
- g->start_x = x * 4;
- g->start_y = y * g->line_size;
- g->max_x = g->start_x + w * 4;
- g->max_y = g->start_y + h * g->line_size;
- g->cur_x = g->start_x;
- g->cur_y = g->start_y;
+ g->line_size = g->w * 4;
+ g->start_x = x * 4;
+ g->start_y = y * g->line_size;
+ g->max_x = g->start_x + w * 4;
+ g->max_y = g->start_y + h * g->line_size;
+ g->cur_x = g->start_x;
+ g->cur_y = g->start_y;
- g->lflags = stbi__get8(s);
+ g->lflags = stbi__get8(s);
- if (g->lflags & 0x40) {
- g->step = 8 * g->line_size; // first interlaced spacing
- g->parse = 3;
- } else {
- g->step = g->line_size;
- g->parse = 0;
+ if (g->lflags & 0x40)
+ {
+ g->step = 8 * g->line_size; // first interlaced spacing
+ g->parse = 3;
+ }
+ else
+ {
+ g->step = g->line_size;
+ g->parse = 0;
+ }
+
+ if (g->lflags & 0x80)
+ {
+ stbi__gif_parse_colortable(s, g->lpal, 2 << (g->lflags & 7), g->eflags & 0x01 ? g->transparent : -1);
+ g->color_table = (stbi_uc *)g->lpal;
+ }
+ else if (g->flags & 0x80)
+ {
+ g->color_table = (stbi_uc *)g->pal;
+ }
+ else
+ return stbi__errpuc("missing color table", "Corrupt GIF");
+
+ o = stbi__process_gif_raster(s, g);
+ if (o == NULL) return NULL;
+
+ // if this was the first frame,
+ pcount = g->w * g->h;
+ if (first_frame && g->bgindex > 0)
+ {
+ // if first frame, any pixel not drawn to gets the background color
+ for (pi = 0; pi < pcount; ++pi)
+ {
+ if (g->history[pi] == 0)
+ {
+ g->pal[g->bgindex][3] = 255; // just in case it was made transparent, undo that; It will be reset next frame if need be;
+ memcpy(&g->out[pi * 4], &g->pal[g->bgindex], 4);
+ }
+ }
+ }
+
+ return o;
}
- if (g->lflags & 0x80) {
- stbi__gif_parse_colortable(s,g->lpal, 2 << (g->lflags & 7), g->eflags & 0x01 ? g->transparent : -1);
- g->color_table = (stbi_uc *) g->lpal;
- } else if (g->flags & 0x80) {
- g->color_table = (stbi_uc *) g->pal;
- } else
- return stbi__errpuc("missing color table", "Corrupt GIF");
-
- o = stbi__process_gif_raster(s, g);
- if (o == NULL) return NULL;
+ case 0x21: // Comment Extension.
+ {
+ int len;
+ int ext = stbi__get8(s);
+ if (ext == 0xF9)
+ { // Graphic Control Extension.
+ len = stbi__get8(s);
+ if (len == 4)
+ {
+ g->eflags = stbi__get8(s);
+ g->delay = 10 * stbi__get16le(s); // delay - 1/100th of a second, saving as 1/1000ths.
- // if this was the first frame,
- pcount = g->w * g->h;
- if (first_frame && (g->bgindex > 0)) {
- // if first frame, any pixel not drawn to gets the background color
- for (pi = 0; pi < pcount; ++pi) {
- if (g->history[pi] == 0) {
- g->pal[g->bgindex][3] = 255; // just in case it was made transparent, undo that; It will be reset next frame if need be;
- memcpy( &g->out[pi * 4], &g->pal[g->bgindex], 4 );
- }
- }
+ // unset old transparent
+ if (g->transparent >= 0)
+ {
+ g->pal[g->transparent][3] = 255;
+ }
+ if (g->eflags & 0x01)
+ {
+ g->transparent = stbi__get8(s);
+ if (g->transparent >= 0)
+ {
+ g->pal[g->transparent][3] = 0;
+ }
+ }
+ else
+ {
+ // don't need transparent
+ stbi__skip(s, 1);
+ g->transparent = -1;
+ }
+ }
+ else
+ {
+ stbi__skip(s, len);
+ break;
+ }
+ }
+ while ((len = stbi__get8(s)) != 0)
+ {
+ stbi__skip(s, len);
+ }
+ break;
}
- return o;
- }
+ case 0x3B: // gif stream termination code
+ return (stbi_uc *)s; // using '1' causes warning on some compilers
- case 0x21: // Comment Extension.
- {
- int len;
- int ext = stbi__get8(s);
- if (ext == 0xF9) { // Graphic Control Extension.
- len = stbi__get8(s);
- if (len == 4) {
- g->eflags = stbi__get8(s);
- g->delay = 10 * stbi__get16le(s); // delay - 1/100th of a second, saving as 1/1000ths.
-
- // unset old transparent
- if (g->transparent >= 0) {
- g->pal[g->transparent][3] = 255;
- }
- if (g->eflags & 0x01) {
- g->transparent = stbi__get8(s);
- if (g->transparent >= 0) {
- g->pal[g->transparent][3] = 0;
- }
- } else {
- // don't need transparent
- stbi__skip(s, 1);
- g->transparent = -1;
- }
- } else {
- stbi__skip(s, len);
- break;
- }
- }
- while ((len = stbi__get8(s)) != 0) {
- stbi__skip(s, len);
- }
- break;
- }
-
- case 0x3B: // gif stream termination code
- return (stbi_uc *) s; // using '1' causes warning on some compilers
-
- default:
- return stbi__errpuc("unknown code", "Corrupt GIF");
- }
- }
+ default:
+ return stbi__errpuc("unknown code", "Corrupt GIF");
+ }
+ }
}
static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, int *z, int *comp, int req_comp)
{
- if (stbi__gif_test(s)) {
- int layers = 0;
- stbi_uc *u = 0;
- stbi_uc *out = 0;
- stbi_uc *two_back = 0;
- stbi__gif g;
- int stride;
- memset(&g, 0, sizeof(g));
- if (delays) {
- *delays = 0;
- }
+ if (stbi__gif_test(s))
+ {
+ int layers = 0;
+ stbi_uc *u = 0;
+ stbi_uc *out = 0;
+ stbi_uc *two_back = 0;
+ stbi__gif g;
+ int stride;
+ memset(&g, 0, sizeof(g));
+ if (delays)
+ {
+ *delays = 0;
+ }
- do {
- u = stbi__gif_load_next(s, &g, comp, req_comp, two_back);
- if (u == (stbi_uc *) s) u = 0; // end of animated gif marker
+ do
+ {
+ u = stbi__gif_load_next(s, &g, comp, req_comp, two_back);
+ if (u == (stbi_uc *)s) u = 0; // end of animated gif marker
- if (u) {
- *x = g.w;
- *y = g.h;
- ++layers;
- stride = g.w * g.h * 4;
-
- if (out) {
- out = (stbi_uc*) STBI_REALLOC( out, layers * stride );
- if (delays) {
- *delays = (int*) STBI_REALLOC( *delays, sizeof(int) * layers );
- }
- } else {
- out = (stbi_uc*)stbi__malloc( layers * stride );
- if (delays) {
- *delays = (int*) stbi__malloc( layers * sizeof(int) );
- }
- }
- memcpy( out + ((layers - 1) * stride), u, stride );
- if (layers >= 2) {
- two_back = out - 2 * stride;
+ if (u)
+ {
+ *x = g.w;
+ *y = g.h;
+ ++layers;
+ stride = g.w * g.h * 4;
+
+ if (out)
+ {
+ out = (stbi_uc *)STBI_REALLOC(out, layers * stride);
+ if (delays)
+ {
+ *delays = (int *)STBI_REALLOC(*delays, sizeof(int) * layers);
+ }
+ }
+ else
+ {
+ out = (stbi_uc *)stbi__malloc(layers * stride);
+ if (delays)
+ {
+ *delays = (int *)stbi__malloc(layers * sizeof(int));
+ }
+ }
+ memcpy(out + (layers - 1) * stride, u, stride);
+ if (layers >= 2)
+ {
+ two_back = out - 2 * stride;
+ }
+
+ if (delays)
+ {
+ (*delays)[layers - 1U] = g.delay;
+ }
}
+ }
+ while (u != 0);
- if (delays) {
- (*delays)[layers - 1U] = g.delay;
- }
- }
- } while (u != 0);
+ // free temp buffer;
+ STBI_FREE(g.out);
+ STBI_FREE(g.history);
+ STBI_FREE(g.background);
- // free temp buffer;
- STBI_FREE(g.out);
- STBI_FREE(g.history);
- STBI_FREE(g.background);
+ // do the final conversion after loading everything;
+ if (req_comp && req_comp != 4)
+ out = stbi__convert_format(out, 4, req_comp, layers * g.w, g.h);
- // do the final conversion after loading everything;
- if (req_comp && req_comp != 4)
- out = stbi__convert_format(out, 4, req_comp, layers * g.w, g.h);
-
- *z = layers;
- return out;
- } else {
- return stbi__errpuc("not GIF", "Image was not as a gif type.");
- }
+ *z = layers;
+ return out;
+ }
+ else
+ {
+ return stbi__errpuc("not GIF", "Image was not as a gif type.");
+ }
}
static void *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri)
{
- stbi_uc *u = 0;
- stbi__gif g;
- memset(&g, 0, sizeof(g));
+ stbi_uc *u = 0;
+ stbi__gif g;
+ memset(&g, 0, sizeof(g));
- u = stbi__gif_load_next(s, &g, comp, req_comp, 0);
- if (u == (stbi_uc *) s) u = 0; // end of animated gif marker
- if (u) {
- *x = g.w;
- *y = g.h;
+ u = stbi__gif_load_next(s, &g, comp, req_comp, 0);
+ if (u == (stbi_uc *)s) u = 0; // end of animated gif marker
+ if (u)
+ {
+ *x = g.w;
+ *y = g.h;
- // moved conversion to after successful load so that the same
- // can be done for multiple frames.
- if (req_comp && req_comp != 4)
- u = stbi__convert_format(u, 4, req_comp, g.w, g.h);
- }
+ // moved conversion to after successful load so that the same
+ // can be done for multiple frames.
+ if (req_comp && req_comp != 4)
+ u = stbi__convert_format(u, 4, req_comp, g.w, g.h);
+ }
- // free buffers needed for multiple frame loading;
- STBI_FREE(g.history);
- STBI_FREE(g.background);
+ // free buffers needed for multiple frame loading;
+ STBI_FREE(g.history);
+ STBI_FREE(g.background);
- return u;
+ return u;
}
static int stbi__gif_info(stbi__context *s, int *x, int *y, int *comp)
{
- return stbi__gif_info_raw(s,x,y,comp);
+ return stbi__gif_info_raw(s, x, y, comp);
}
#endif
@@ -6597,386 +7504,447 @@ static int stbi__gif_info(stbi__context *s, int *x, int *y, int *comp)
#ifndef STBI_NO_HDR
static int stbi__hdr_test_core(stbi__context *s, const char *signature)
{
- int i;
- for (i=0; signature[i]; ++i)
- if (stbi__get8(s) != signature[i])
- return 0;
- stbi__rewind(s);
- return 1;
+ int i;
+ for (i = 0; signature[i]; ++i)
+ if (stbi__get8(s) != signature[i])
+ return 0;
+ stbi__rewind(s);
+ return 1;
}
-static int stbi__hdr_test(stbi__context* s)
+static int stbi__hdr_test(stbi__context *s)
{
- int r = stbi__hdr_test_core(s, "#?RADIANCE\n");
- stbi__rewind(s);
- if(!r) {
- r = stbi__hdr_test_core(s, "#?RGBE\n");
- stbi__rewind(s);
- }
- return r;
+ int r = stbi__hdr_test_core(s, "#?RADIANCE\n");
+ stbi__rewind(s);
+ if (!r)
+ {
+ r = stbi__hdr_test_core(s, "#?RGBE\n");
+ stbi__rewind(s);
+ }
+ return r;
}
#define STBI__HDR_BUFLEN 1024
static char *stbi__hdr_gettoken(stbi__context *z, char *buffer)
{
- int len=0;
- char c = '\0';
+ int len = 0;
+ char c = '\0';
- c = (char) stbi__get8(z);
+ c = (char)stbi__get8(z);
- while (!stbi__at_eof(z) && c != '\n') {
- buffer[len++] = c;
- if (len == STBI__HDR_BUFLEN-1) {
- // flush to end of line
- while (!stbi__at_eof(z) && stbi__get8(z) != '\n')
- ;
- break;
- }
- c = (char) stbi__get8(z);
- }
+ while (!stbi__at_eof(z) && c != '\n')
+ {
+ buffer[len++] = c;
+ if (len == STBI__HDR_BUFLEN - 1)
+ {
+ // flush to end of line
+ while (!stbi__at_eof(z) && stbi__get8(z) != '\n');
+ break;
+ }
+ c = (char)stbi__get8(z);
+ }
- buffer[len] = 0;
- return buffer;
+ buffer[len] = 0;
+ return buffer;
}
static void stbi__hdr_convert(float *output, stbi_uc *input, int req_comp)
{
- if ( input[3] != 0 ) {
- float f1;
- // Exponent
- f1 = (float) ldexp(1.0f, input[3] - (int)(128 + 8));
- if (req_comp <= 2)
- output[0] = (input[0] + input[1] + input[2]) * f1 / 3;
- else {
- output[0] = input[0] * f1;
- output[1] = input[1] * f1;
- output[2] = input[2] * f1;
- }
- if (req_comp == 2) output[1] = 1;
- if (req_comp == 4) output[3] = 1;
- } else {
- switch (req_comp) {
- case 4: output[3] = 1; /* fallthrough */
- case 3: output[0] = output[1] = output[2] = 0;
- break;
- case 2: output[1] = 1; /* fallthrough */
- case 1: output[0] = 0;
- break;
- }
- }
+ if (input[3] != 0)
+ {
+ float f1;
+ // Exponent
+ f1 = (float)ldexp(1.0f, input[3] - (int)(128 + 8));
+ if (req_comp <= 2)
+ output[0] = (input[0] + input[1] + input[2]) * f1 / 3;
+ else
+ {
+ output[0] = input[0] * f1;
+ output[1] = input[1] * f1;
+ output[2] = input[2] * f1;
+ }
+ if (req_comp == 2) output[1] = 1;
+ if (req_comp == 4) output[3] = 1;
+ }
+ else
+ {
+ switch (req_comp)
+ {
+ case 4:
+ output[3] = 1; /* fallthrough */
+ case 3:
+ output[0] = output[1] = output[2] = 0;
+ break;
+ case 2:
+ output[1] = 1; /* fallthrough */
+ case 1:
+ output[0] = 0;
+ break;
+ }
+ }
}
static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri)
{
- char buffer[STBI__HDR_BUFLEN];
- char *token;
- int valid = 0;
- int width, height;
- stbi_uc *scanline;
- float *hdr_data;
- int len;
- unsigned char count, value;
- int i, j, k, c1,c2, z;
- const char *headerToken;
- STBI_NOTUSED(ri);
+ char buffer[STBI__HDR_BUFLEN];
+ char *token;
+ int valid = 0;
+ int width, height;
+ stbi_uc *scanline;
+ float *hdr_data;
+ int len;
+ unsigned char count, value;
+ int i, j, k, c1, c2, z;
+ const char *headerToken;
+ STBI_NOTUSED(ri);
- // Check identifier
- headerToken = stbi__hdr_gettoken(s,buffer);
- if (strcmp(headerToken, "#?RADIANCE") != 0 && strcmp(headerToken, "#?RGBE") != 0)
- return stbi__errpf("not HDR", "Corrupt HDR image");
+ // Check identifier
+ headerToken = stbi__hdr_gettoken(s, buffer);
+ if (strcmp(headerToken, "#?RADIANCE") != 0 && strcmp(headerToken, "#?RGBE") != 0)
+ return stbi__errpf("not HDR", "Corrupt HDR image");
- // Parse header
- for(;;) {
- token = stbi__hdr_gettoken(s,buffer);
- if (token[0] == 0) break;
- if (strcmp(token, "FORMAT=32-bit_rle_rgbe") == 0) valid = 1;
- }
+ // Parse header
+ for (;;)
+ {
+ token = stbi__hdr_gettoken(s, buffer);
+ if (token[0] == 0) break;
+ if (strcmp(token, "FORMAT=32-bit_rle_rgbe") == 0) valid = 1;
+ }
- if (!valid) return stbi__errpf("unsupported format", "Unsupported HDR format");
+ if (!valid) return stbi__errpf("unsupported format", "Unsupported HDR format");
- // Parse width and height
- // can't use sscanf() if we're not using stdio!
- token = stbi__hdr_gettoken(s,buffer);
- if (strncmp(token, "-Y ", 3)) return stbi__errpf("unsupported data layout", "Unsupported HDR format");
- token += 3;
- height = (int) strtol(token, &token, 10);
- while (*token == ' ') ++token;
- if (strncmp(token, "+X ", 3)) return stbi__errpf("unsupported data layout", "Unsupported HDR format");
- token += 3;
- width = (int) strtol(token, NULL, 10);
+ // Parse width and height
+ // can't use sscanf() if we're not using stdio!
+ token = stbi__hdr_gettoken(s, buffer);
+ if (strncmp(token, "-Y ", 3)) return stbi__errpf("unsupported data layout", "Unsupported HDR format");
+ token += 3;
+ height = (int)strtol(token, &token, 10);
+ while (*token == ' ') ++token;
+ if (strncmp(token, "+X ", 3)) return stbi__errpf("unsupported data layout", "Unsupported HDR format");
+ token += 3;
+ width = (int)strtol(token, NULL, 10);
- *x = width;
- *y = height;
+ *x = width;
+ *y = height;
- if (comp) *comp = 3;
- if (req_comp == 0) req_comp = 3;
+ if (comp) *comp = 3;
+ if (req_comp == 0) req_comp = 3;
- if (!stbi__mad4sizes_valid(width, height, req_comp, sizeof(float), 0))
- return stbi__errpf("too large", "HDR image is too large");
+ if (!stbi__mad4sizes_valid(width, height, req_comp, sizeof(float), 0))
+ return stbi__errpf("too large", "HDR image is too large");
- // Read data
- hdr_data = (float *) stbi__malloc_mad4(width, height, req_comp, sizeof(float), 0);
- if (!hdr_data)
- return stbi__errpf("outofmem", "Out of memory");
+ // Read data
+ hdr_data = (float *)stbi__malloc_mad4(width, height, req_comp, sizeof(float), 0);
+ if (!hdr_data)
+ return stbi__errpf("outofmem", "Out of memory");
- // Load image data
- // image data is stored as some number of sca
- if ( width < 8 || width >= 32768) {
- // Read flat data
- for (j=0; j < height; ++j) {
- for (i=0; i < width; ++i) {
- stbi_uc rgbe[4];
- main_decode_loop:
- stbi__getn(s, rgbe, 4);
- stbi__hdr_convert(hdr_data + j * width * req_comp + i * req_comp, rgbe, req_comp);
- }
- }
- } else {
- // Read RLE-encoded data
- scanline = NULL;
+ // Load image data
+ // image data is stored as some number of sca
+ if (width < 8 || width >= 32768)
+ {
+ // Read flat data
+ for (j = 0; j < height; ++j)
+ {
+ for (i = 0; i < width; ++i)
+ {
+ stbi_uc rgbe[4];
+ main_decode_loop: stbi__getn(s, rgbe, 4);
+ stbi__hdr_convert(hdr_data + j * width * req_comp + i * req_comp, rgbe, req_comp);
+ }
+ }
+ }
+ else
+ {
+ // Read RLE-encoded data
+ scanline = NULL;
- for (j = 0; j < height; ++j) {
- c1 = stbi__get8(s);
- c2 = stbi__get8(s);
- len = stbi__get8(s);
- if (c1 != 2 || c2 != 2 || (len & 0x80)) {
- // not run-length encoded, so we have to actually use THIS data as a decoded
- // pixel (note this can't be a valid pixel--one of RGB must be >= 128)
- stbi_uc rgbe[4];
- rgbe[0] = (stbi_uc) c1;
- rgbe[1] = (stbi_uc) c2;
- rgbe[2] = (stbi_uc) len;
- rgbe[3] = (stbi_uc) stbi__get8(s);
- stbi__hdr_convert(hdr_data, rgbe, req_comp);
- i = 1;
- j = 0;
+ for (j = 0; j < height; ++j)
+ {
+ c1 = stbi__get8(s);
+ c2 = stbi__get8(s);
+ len = stbi__get8(s);
+ if (c1 != 2 || c2 != 2 || (len & 0x80))
+ {
+ // not run-length encoded, so we have to actually use THIS data as a decoded
+ // pixel (note this can't be a valid pixel--one of RGB must be >= 128)
+ stbi_uc rgbe[4];
+ rgbe[0] = (stbi_uc)c1;
+ rgbe[1] = (stbi_uc)c2;
+ rgbe[2] = (stbi_uc)len;
+ rgbe[3] = (stbi_uc)stbi__get8(s);
+ stbi__hdr_convert(hdr_data, rgbe, req_comp);
+ i = 1;
+ j = 0;
+ STBI_FREE(scanline);
+ goto main_decode_loop; // yes, this makes no sense
+ }
+ len <<= 8;
+ len |= stbi__get8(s);
+ if (len != width)
+ {
+ STBI_FREE(hdr_data);
+ STBI_FREE(scanline);
+ return stbi__errpf("invalid decoded scanline length", "corrupt HDR");
+ }
+ if (scanline == NULL)
+ {
+ scanline = (stbi_uc *)stbi__malloc_mad2(width, 4, 0);
+ if (!scanline)
+ {
+ STBI_FREE(hdr_data);
+ return stbi__errpf("outofmem", "Out of memory");
+ }
+ }
+
+ for (k = 0; k < 4; ++k)
+ {
+ int nleft;
+ i = 0;
+ while ((nleft = width - i) > 0)
+ {
+ count = stbi__get8(s);
+ if (count > 128)
+ {
+ // Run
+ value = stbi__get8(s);
+ count -= 128;
+ if (count > nleft)
+ {
+ STBI_FREE(hdr_data);
+ STBI_FREE(scanline);
+ return stbi__errpf("corrupt", "bad RLE data in HDR");
+ }
+ for (z = 0; z < count; ++z)
+ scanline[i++ * 4 + k] = value;
+ }
+ else
+ {
+ // Dump
+ if (count > nleft)
+ {
+ STBI_FREE(hdr_data);
+ STBI_FREE(scanline);
+ return stbi__errpf("corrupt", "bad RLE data in HDR");
+ }
+ for (z = 0; z < count; ++z)
+ scanline[i++ * 4 + k] = stbi__get8(s);
+ }
+ }
+ }
+ for (i = 0; i < width; ++i)
+ stbi__hdr_convert(hdr_data + (j * width + i) * req_comp, scanline + i * 4, req_comp);
+ }
+ if (scanline)
STBI_FREE(scanline);
- goto main_decode_loop; // yes, this makes no sense
- }
- len <<= 8;
- len |= stbi__get8(s);
- if (len != width) { STBI_FREE(hdr_data); STBI_FREE(scanline); return stbi__errpf("invalid decoded scanline length", "corrupt HDR"); }
- if (scanline == NULL) {
- scanline = (stbi_uc *) stbi__malloc_mad2(width, 4, 0);
- if (!scanline) {
- STBI_FREE(hdr_data);
- return stbi__errpf("outofmem", "Out of memory");
- }
- }
+ }
- for (k = 0; k < 4; ++k) {
- int nleft;
- i = 0;
- while ((nleft = width - i) > 0) {
- count = stbi__get8(s);
- if (count > 128) {
- // Run
- value = stbi__get8(s);
- count -= 128;
- if (count > nleft) { STBI_FREE(hdr_data); STBI_FREE(scanline); return stbi__errpf("corrupt", "bad RLE data in HDR"); }
- for (z = 0; z < count; ++z)
- scanline[i++ * 4 + k] = value;
- } else {
- // Dump
- if (count > nleft) { STBI_FREE(hdr_data); STBI_FREE(scanline); return stbi__errpf("corrupt", "bad RLE data in HDR"); }
- for (z = 0; z < count; ++z)
- scanline[i++ * 4 + k] = stbi__get8(s);
- }
- }
- }
- for (i=0; i < width; ++i)
- stbi__hdr_convert(hdr_data+(j*width + i)*req_comp, scanline + i*4, req_comp);
- }
- if (scanline)
- STBI_FREE(scanline);
- }
-
- return hdr_data;
+ return hdr_data;
}
static int stbi__hdr_info(stbi__context *s, int *x, int *y, int *comp)
{
- char buffer[STBI__HDR_BUFLEN];
- char *token;
- int valid = 0;
- int dummy;
+ char buffer[STBI__HDR_BUFLEN];
+ char *token;
+ int valid = 0;
+ int dummy;
- if (!x) x = &dummy;
- if (!y) y = &dummy;
- if (!comp) comp = &dummy;
+ if (!x) x = &dummy;
+ if (!y) y = &dummy;
+ if (!comp) comp = &dummy;
- if (stbi__hdr_test(s) == 0) {
- stbi__rewind( s );
- return 0;
- }
+ if (stbi__hdr_test(s) == 0)
+ {
+ stbi__rewind(s);
+ return 0;
+ }
- for(;;) {
- token = stbi__hdr_gettoken(s,buffer);
- if (token[0] == 0) break;
- if (strcmp(token, "FORMAT=32-bit_rle_rgbe") == 0) valid = 1;
- }
+ for (;;)
+ {
+ token = stbi__hdr_gettoken(s, buffer);
+ if (token[0] == 0) break;
+ if (strcmp(token, "FORMAT=32-bit_rle_rgbe") == 0) valid = 1;
+ }
- if (!valid) {
- stbi__rewind( s );
- return 0;
- }
- token = stbi__hdr_gettoken(s,buffer);
- if (strncmp(token, "-Y ", 3)) {
- stbi__rewind( s );
- return 0;
- }
- token += 3;
- *y = (int) strtol(token, &token, 10);
- while (*token == ' ') ++token;
- if (strncmp(token, "+X ", 3)) {
- stbi__rewind( s );
- return 0;
- }
- token += 3;
- *x = (int) strtol(token, NULL, 10);
- *comp = 3;
- return 1;
+ if (!valid)
+ {
+ stbi__rewind(s);
+ return 0;
+ }
+ token = stbi__hdr_gettoken(s, buffer);
+ if (strncmp(token, "-Y ", 3))
+ {
+ stbi__rewind(s);
+ return 0;
+ }
+ token += 3;
+ *y = (int)strtol(token, &token, 10);
+ while (*token == ' ') ++token;
+ if (strncmp(token, "+X ", 3))
+ {
+ stbi__rewind(s);
+ return 0;
+ }
+ token += 3;
+ *x = (int)strtol(token, NULL, 10);
+ *comp = 3;
+ return 1;
}
#endif // STBI_NO_HDR
#ifndef STBI_NO_BMP
static int stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp)
{
- void *p;
- stbi__bmp_data info;
+ void *p;
+ stbi__bmp_data info;
- info.all_a = 255;
- p = stbi__bmp_parse_header(s, &info);
- stbi__rewind( s );
- if (p == NULL)
- return 0;
- if (x) *x = s->img_x;
- if (y) *y = s->img_y;
- if (comp) *comp = info.ma ? 4 : 3;
- return 1;
+ info.all_a = 255;
+ p = stbi__bmp_parse_header(s, &info);
+ stbi__rewind(s);
+ if (p == NULL)
+ return 0;
+ if (x) *x = s->img_x;
+ if (y) *y = s->img_y;
+ if (comp) *comp = info.ma ? 4 : 3;
+ return 1;
}
#endif
#ifndef STBI_NO_PSD
static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp)
{
- int channelCount, dummy, depth;
- if (!x) x = &dummy;
- if (!y) y = &dummy;
- if (!comp) comp = &dummy;
- if (stbi__get32be(s) != 0x38425053) {
- stbi__rewind( s );
- return 0;
- }
- if (stbi__get16be(s) != 1) {
- stbi__rewind( s );
- return 0;
- }
- stbi__skip(s, 6);
- channelCount = stbi__get16be(s);
- if (channelCount < 0 || channelCount > 16) {
- stbi__rewind( s );
- return 0;
- }
- *y = stbi__get32be(s);
- *x = stbi__get32be(s);
- depth = stbi__get16be(s);
- if (depth != 8 && depth != 16) {
- stbi__rewind( s );
- return 0;
- }
- if (stbi__get16be(s) != 3) {
- stbi__rewind( s );
- return 0;
- }
- *comp = 4;
- return 1;
+ int channelCount, dummy, depth;
+ if (!x) x = &dummy;
+ if (!y) y = &dummy;
+ if (!comp) comp = &dummy;
+ if (stbi__get32be(s) != 0x38425053)
+ {
+ stbi__rewind(s);
+ return 0;
+ }
+ if (stbi__get16be(s) != 1)
+ {
+ stbi__rewind(s);
+ return 0;
+ }
+ stbi__skip(s, 6);
+ channelCount = stbi__get16be(s);
+ if (channelCount < 0 || channelCount > 16)
+ {
+ stbi__rewind(s);
+ return 0;
+ }
+ *y = stbi__get32be(s);
+ *x = stbi__get32be(s);
+ depth = stbi__get16be(s);
+ if (depth != 8 && depth != 16)
+ {
+ stbi__rewind(s);
+ return 0;
+ }
+ if (stbi__get16be(s) != 3)
+ {
+ stbi__rewind(s);
+ return 0;
+ }
+ *comp = 4;
+ return 1;
}
static int stbi__psd_is16(stbi__context *s)
{
- int channelCount, depth;
- if (stbi__get32be(s) != 0x38425053) {
- stbi__rewind( s );
- return 0;
- }
- if (stbi__get16be(s) != 1) {
- stbi__rewind( s );
- return 0;
- }
- stbi__skip(s, 6);
- channelCount = stbi__get16be(s);
- if (channelCount < 0 || channelCount > 16) {
- stbi__rewind( s );
- return 0;
- }
- (void) stbi__get32be(s);
- (void) stbi__get32be(s);
- depth = stbi__get16be(s);
- if (depth != 16) {
- stbi__rewind( s );
- return 0;
- }
- return 1;
+ int channelCount, depth;
+ if (stbi__get32be(s) != 0x38425053)
+ {
+ stbi__rewind(s);
+ return 0;
+ }
+ if (stbi__get16be(s) != 1)
+ {
+ stbi__rewind(s);
+ return 0;
+ }
+ stbi__skip(s, 6);
+ channelCount = stbi__get16be(s);
+ if (channelCount < 0 || channelCount > 16)
+ {
+ stbi__rewind(s);
+ return 0;
+ }
+ (void)stbi__get32be(s);
+ (void)stbi__get32be(s);
+ depth = stbi__get16be(s);
+ if (depth != 16)
+ {
+ stbi__rewind(s);
+ return 0;
+ }
+ return 1;
}
#endif
#ifndef STBI_NO_PIC
static int stbi__pic_info(stbi__context *s, int *x, int *y, int *comp)
{
- int act_comp=0,num_packets=0,chained,dummy;
- stbi__pic_packet packets[10];
+ int act_comp = 0, num_packets = 0, chained, dummy;
+ stbi__pic_packet packets[10];
- if (!x) x = &dummy;
- if (!y) y = &dummy;
- if (!comp) comp = &dummy;
+ if (!x) x = &dummy;
+ if (!y) y = &dummy;
+ if (!comp) comp = &dummy;
- if (!stbi__pic_is4(s,"\x53\x80\xF6\x34")) {
- stbi__rewind(s);
- return 0;
- }
+ if (!stbi__pic_is4(s, "\x53\x80\xF6\x34"))
+ {
+ stbi__rewind(s);
+ return 0;
+ }
- stbi__skip(s, 88);
+ stbi__skip(s, 88);
- *x = stbi__get16be(s);
- *y = stbi__get16be(s);
- if (stbi__at_eof(s)) {
- stbi__rewind( s);
- return 0;
- }
- if ( (*x) != 0 && (1 << 28) / (*x) < (*y)) {
- stbi__rewind( s );
- return 0;
- }
+ *x = stbi__get16be(s);
+ *y = stbi__get16be(s);
+ if (stbi__at_eof(s))
+ {
+ stbi__rewind(s);
+ return 0;
+ }
+ if (*x != 0 && (1 << 28) / *x < *y)
+ {
+ stbi__rewind(s);
+ return 0;
+ }
- stbi__skip(s, 8);
+ stbi__skip(s, 8);
- do {
- stbi__pic_packet *packet;
+ do
+ {
+ stbi__pic_packet *packet;
- if (num_packets==sizeof(packets)/sizeof(packets[0]))
- return 0;
+ if (num_packets == sizeof(packets) / sizeof(packets[0]))
+ return 0;
- packet = &packets[num_packets++];
- chained = stbi__get8(s);
- packet->size = stbi__get8(s);
- packet->type = stbi__get8(s);
- packet->channel = stbi__get8(s);
- act_comp |= packet->channel;
+ packet = &packets[num_packets++];
+ chained = stbi__get8(s);
+ packet->size = stbi__get8(s);
+ packet->type = stbi__get8(s);
+ packet->channel = stbi__get8(s);
+ act_comp |= packet->channel;
- if (stbi__at_eof(s)) {
- stbi__rewind( s );
- return 0;
- }
- if (packet->size != 8) {
- stbi__rewind( s );
- return 0;
- }
- } while (chained);
+ if (stbi__at_eof(s))
+ {
+ stbi__rewind(s);
+ return 0;
+ }
+ if (packet->size != 8)
+ {
+ stbi__rewind(s);
+ return 0;
+ }
+ }
+ while (chained);
- *comp = (act_comp & 0x10 ? 4 : 3);
+ *comp = act_comp & 0x10 ? 4 : 3;
- return 1;
+ return 1;
}
#endif
@@ -6994,172 +7962,177 @@ static int stbi__pic_info(stbi__context *s, int *x, int *y, int *comp)
#ifndef STBI_NO_PNM
-static int stbi__pnm_test(stbi__context *s)
+static int stbi__pnm_test(stbi__context *s)
{
- char p, t;
- p = (char) stbi__get8(s);
- t = (char) stbi__get8(s);
- if (p != 'P' || (t != '5' && t != '6')) {
- stbi__rewind( s );
- return 0;
- }
- return 1;
+ char p, t;
+ p = (char)stbi__get8(s);
+ t = (char)stbi__get8(s);
+ if (p != 'P' || (t != '5' && t != '6'))
+ {
+ stbi__rewind(s);
+ return 0;
+ }
+ return 1;
}
static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri)
{
- stbi_uc *out;
- STBI_NOTUSED(ri);
+ stbi_uc *out;
+ STBI_NOTUSED(ri);
- if (!stbi__pnm_info(s, (int *)&s->img_x, (int *)&s->img_y, (int *)&s->img_n))
- return 0;
+ if (!stbi__pnm_info(s, (int *)&s->img_x, (int *)&s->img_y, &s->img_n))
+ return 0;
- *x = s->img_x;
- *y = s->img_y;
- if (comp) *comp = s->img_n;
+ *x = s->img_x;
+ *y = s->img_y;
+ if (comp) *comp = s->img_n;
- if (!stbi__mad3sizes_valid(s->img_n, s->img_x, s->img_y, 0))
- return stbi__errpuc("too large", "PNM too large");
+ if (!stbi__mad3sizes_valid(s->img_n, s->img_x, s->img_y, 0))
+ return stbi__errpuc("too large", "PNM too large");
- out = (stbi_uc *) stbi__malloc_mad3(s->img_n, s->img_x, s->img_y, 0);
- if (!out) return stbi__errpuc("outofmem", "Out of memory");
- stbi__getn(s, out, s->img_n * s->img_x * s->img_y);
+ out = (stbi_uc *)stbi__malloc_mad3(s->img_n, s->img_x, s->img_y, 0);
+ if (!out) return stbi__errpuc("outofmem", "Out of memory");
+ stbi__getn(s, out, s->img_n * s->img_x * s->img_y);
- if (req_comp && req_comp != s->img_n) {
- out = stbi__convert_format(out, s->img_n, req_comp, s->img_x, s->img_y);
- if (out == NULL) return out; // stbi__convert_format frees input on failure
- }
- return out;
+ if (req_comp && req_comp != s->img_n)
+ {
+ out = stbi__convert_format(out, s->img_n, req_comp, s->img_x, s->img_y);
+ if (out == NULL) return out; // stbi__convert_format frees input on failure
+ }
+ return out;
}
-static int stbi__pnm_isspace(char c)
+static int stbi__pnm_isspace(char c)
{
- return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r';
+ return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r';
}
-static void stbi__pnm_skip_whitespace(stbi__context *s, char *c)
+static void stbi__pnm_skip_whitespace(stbi__context *s, char *c)
{
- for (;;) {
- while (!stbi__at_eof(s) && stbi__pnm_isspace(*c))
- *c = (char) stbi__get8(s);
+ for (;;)
+ {
+ while (!stbi__at_eof(s) && stbi__pnm_isspace(*c))
+ *c = (char)stbi__get8(s);
- if (stbi__at_eof(s) || *c != '#')
- break;
+ if (stbi__at_eof(s) || *c != '#')
+ break;
- while (!stbi__at_eof(s) && *c != '\n' && *c != '\r' )
- *c = (char) stbi__get8(s);
- }
+ while (!stbi__at_eof(s) && *c != '\n' && *c != '\r')
+ *c = (char)stbi__get8(s);
+ }
}
-static int stbi__pnm_isdigit(char c)
+static int stbi__pnm_isdigit(char c)
{
- return c >= '0' && c <= '9';
+ return c >= '0' && c <= '9';
}
-static int stbi__pnm_getinteger(stbi__context *s, char *c)
+static int stbi__pnm_getinteger(stbi__context *s, char *c)
{
- int value = 0;
+ int value = 0;
- while (!stbi__at_eof(s) && stbi__pnm_isdigit(*c)) {
- value = value*10 + (*c - '0');
- *c = (char) stbi__get8(s);
- }
+ while (!stbi__at_eof(s) && stbi__pnm_isdigit(*c))
+ {
+ value = value * 10 + (*c - '0');
+ *c = (char)stbi__get8(s);
+ }
- return value;
+ return value;
}
-static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp)
+static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp)
{
- int maxv, dummy;
- char c, p, t;
+ int maxv, dummy;
+ char c, p, t;
- if (!x) x = &dummy;
- if (!y) y = &dummy;
- if (!comp) comp = &dummy;
+ if (!x) x = &dummy;
+ if (!y) y = &dummy;
+ if (!comp) comp = &dummy;
- stbi__rewind(s);
+ stbi__rewind(s);
- // Get identifier
- p = (char) stbi__get8(s);
- t = (char) stbi__get8(s);
- if (p != 'P' || (t != '5' && t != '6')) {
- stbi__rewind(s);
- return 0;
- }
+ // Get identifier
+ p = (char)stbi__get8(s);
+ t = (char)stbi__get8(s);
+ if (p != 'P' || (t != '5' && t != '6'))
+ {
+ stbi__rewind(s);
+ return 0;
+ }
- *comp = (t == '6') ? 3 : 1; // '5' is 1-component .pgm; '6' is 3-component .ppm
+ *comp = t == '6' ? 3 : 1; // '5' is 1-component .pgm; '6' is 3-component .ppm
- c = (char) stbi__get8(s);
- stbi__pnm_skip_whitespace(s, &c);
+ c = (char)stbi__get8(s);
+ stbi__pnm_skip_whitespace(s, &c);
- *x = stbi__pnm_getinteger(s, &c); // read width
- stbi__pnm_skip_whitespace(s, &c);
+ *x = stbi__pnm_getinteger(s, &c); // read width
+ stbi__pnm_skip_whitespace(s, &c);
- *y = stbi__pnm_getinteger(s, &c); // read height
- stbi__pnm_skip_whitespace(s, &c);
+ *y = stbi__pnm_getinteger(s, &c); // read height
+ stbi__pnm_skip_whitespace(s, &c);
- maxv = stbi__pnm_getinteger(s, &c); // read max value
+ maxv = stbi__pnm_getinteger(s, &c); // read max value
- if (maxv > 255)
- return stbi__err("max value > 255", "PPM image not 8-bit");
- else
- return 1;
+ if (maxv > 255)
+ return stbi__err("max value > 255", "PPM image not 8-bit");
+ else
+ return 1;
}
#endif
static int stbi__info_main(stbi__context *s, int *x, int *y, int *comp)
{
- #ifndef STBI_NO_JPEG
- if (stbi__jpeg_info(s, x, y, comp)) return 1;
- #endif
+ #ifndef STBI_NO_JPEG
+ if (stbi__jpeg_info(s, x, y, comp)) return 1;
+ #endif
- #ifndef STBI_NO_PNG
- if (stbi__png_info(s, x, y, comp)) return 1;
- #endif
+ #ifndef STBI_NO_PNG
+ if (stbi__png_info(s, x, y, comp)) return 1;
+ #endif
- #ifndef STBI_NO_GIF
- if (stbi__gif_info(s, x, y, comp)) return 1;
- #endif
+ #ifndef STBI_NO_GIF
+ if (stbi__gif_info(s, x, y, comp)) return 1;
+ #endif
- #ifndef STBI_NO_BMP
- if (stbi__bmp_info(s, x, y, comp)) return 1;
- #endif
+ #ifndef STBI_NO_BMP
+ if (stbi__bmp_info(s, x, y, comp)) return 1;
+ #endif
- #ifndef STBI_NO_PSD
- if (stbi__psd_info(s, x, y, comp)) return 1;
- #endif
+ #ifndef STBI_NO_PSD
+ if (stbi__psd_info(s, x, y, comp)) return 1;
+ #endif
- #ifndef STBI_NO_PIC
- if (stbi__pic_info(s, x, y, comp)) return 1;
- #endif
+ #ifndef STBI_NO_PIC
+ if (stbi__pic_info(s, x, y, comp)) return 1;
+ #endif
- #ifndef STBI_NO_PNM
- if (stbi__pnm_info(s, x, y, comp)) return 1;
- #endif
+ #ifndef STBI_NO_PNM
+ if (stbi__pnm_info(s, x, y, comp)) return 1;
+ #endif
- #ifndef STBI_NO_HDR
- if (stbi__hdr_info(s, x, y, comp)) return 1;
- #endif
+ #ifndef STBI_NO_HDR
+ if (stbi__hdr_info(s, x, y, comp)) return 1;
+ #endif
- // test tga last because it's a crappy test!
- #ifndef STBI_NO_TGA
- if (stbi__tga_info(s, x, y, comp))
- return 1;
- #endif
- return stbi__err("unknown image type", "Image not of any known type, or corrupt");
+ // test tga last because it's a crappy test!
+ #ifndef STBI_NO_TGA
+ if (stbi__tga_info(s, x, y, comp))
+ return 1;
+ #endif
+ return stbi__err("unknown image type", "Image not of any known type, or corrupt");
}
static int stbi__is_16_main(stbi__context *s)
{
- #ifndef STBI_NO_PNG
- if (stbi__png_is16(s)) return 1;
- #endif
+ #ifndef STBI_NO_PNG
+ if (stbi__png_is16(s)) return 1;
+ #endif
- #ifndef STBI_NO_PSD
- if (stbi__psd_is16(s)) return 1;
- #endif
+ #ifndef STBI_NO_PSD
+ if (stbi__psd_is16(s)) return 1;
+ #endif
- return 0;
+ return 0;
}
#ifndef STBI_NO_STDIO
@@ -7175,13 +8148,13 @@ STBIDEF int stbi_info(char const *filename, int *x, int *y, int *comp)
STBIDEF int stbi_info_from_file(FILE *f, int *x, int *y, int *comp)
{
- int r;
- stbi__context s;
- long pos = ftell(f);
- stbi__start_file(&s, f);
- r = stbi__info_main(&s,x,y,comp);
- fseek(f,pos,SEEK_SET);
- return r;
+ int r;
+ stbi__context s;
+ long pos = ftell(f);
+ stbi__start_file(&s, f);
+ r = stbi__info_main(&s, x, y, comp);
+ fseek(f, pos, SEEK_SET);
+ return r;
}
STBIDEF int stbi_is_16_bit(char const *filename)
@@ -7196,42 +8169,42 @@ STBIDEF int stbi_is_16_bit(char const *filename)
STBIDEF int stbi_is_16_bit_from_file(FILE *f)
{
- int r;
- stbi__context s;
- long pos = ftell(f);
- stbi__start_file(&s, f);
- r = stbi__is_16_main(&s);
- fseek(f,pos,SEEK_SET);
- return r;
+ int r;
+ stbi__context s;
+ long pos = ftell(f);
+ stbi__start_file(&s, f);
+ r = stbi__is_16_main(&s);
+ fseek(f, pos, SEEK_SET);
+ return r;
}
#endif // !STBI_NO_STDIO
STBIDEF int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp)
{
- stbi__context s;
- stbi__start_mem(&s,buffer,len);
- return stbi__info_main(&s,x,y,comp);
+ stbi__context s;
+ stbi__start_mem(&s, buffer, len);
+ return stbi__info_main(&s, x, y, comp);
}
STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *c, void *user, int *x, int *y, int *comp)
{
- stbi__context s;
- stbi__start_callbacks(&s, (stbi_io_callbacks *) c, user);
- return stbi__info_main(&s,x,y,comp);
+ stbi__context s;
+ stbi__start_callbacks(&s, (stbi_io_callbacks *)c, user);
+ return stbi__info_main(&s, x, y, comp);
}
STBIDEF int stbi_is_16_bit_from_memory(stbi_uc const *buffer, int len)
{
- stbi__context s;
- stbi__start_mem(&s,buffer,len);
- return stbi__is_16_main(&s);
+ stbi__context s;
+ stbi__start_mem(&s, buffer, len);
+ return stbi__is_16_main(&s);
}
STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const *c, void *user)
{
- stbi__context s;
- stbi__start_callbacks(&s, (stbi_io_callbacks *) c, user);
- return stbi__is_16_main(&s);
+ stbi__context s;
+ stbi__start_callbacks(&s, (stbi_io_callbacks *)c, user);
+ return stbi__is_16_main(&s);
}
#endif // STB_IMAGE_IMPLEMENTATION
diff --git a/src/decomp/tools/stb/stb_image_write.h b/src/decomp/tools/stb/stb_image_write.h
index c05e958..5a06824 100644
--- a/src/decomp/tools/stb/stb_image_write.h
+++ b/src/decomp/tools/stb/stb_image_write.h
@@ -168,20 +168,28 @@ extern int stbi_write_force_png_filter;
#endif
#ifndef STBI_WRITE_NO_STDIO
-STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
-STBIWDEF int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
-STBIWDEF int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
+STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
+
+STBIWDEF int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
+
+STBIWDEF int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
+
STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);
-STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality);
+
+STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality);
#endif
typedef void stbi_write_func(void *context, void *data, int size);
-STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data, int stride_in_bytes);
-STBIWDEF int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data);
-STBIWDEF int stbi_write_tga_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data);
+STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data, int stride_in_bytes);
+
+STBIWDEF int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data);
+
+STBIWDEF int stbi_write_tga_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data);
+
STBIWDEF int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const float *data);
-STBIWDEF int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality);
+
+STBIWDEF int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality);
STBIWDEF void stbi_flip_vertically_on_write(int flip_boolean);
@@ -190,12 +198,12 @@ STBIWDEF void stbi_flip_vertically_on_write(int flip_boolean);
#ifdef STB_IMAGE_WRITE_IMPLEMENTATION
#ifdef _WIN32
- #ifndef _CRT_SECURE_NO_WARNINGS
- #define _CRT_SECURE_NO_WARNINGS
- #endif
- #ifndef _CRT_NONSTDC_NO_DEPRECATE
- #define _CRT_NONSTDC_NO_DEPRECATE
- #endif
+#ifndef _CRT_SECURE_NO_WARNINGS
+#define _CRT_SECURE_NO_WARNINGS
+#endif
+#ifndef _CRT_NONSTDC_NO_DEPRECATE
+#define _CRT_NONSTDC_NO_DEPRECATE
+#endif
#endif
#ifndef STBI_WRITE_NO_STDIO
@@ -239,310 +247,357 @@ STBIWDEF void stbi_flip_vertically_on_write(int flip_boolean);
#define STBIW_UCHAR(x) (unsigned char) ((x) & 0xff)
#ifdef STB_IMAGE_WRITE_STATIC
-static int stbi__flip_vertically_on_write=0;
+static int stbi__flip_vertically_on_write = 0;
static int stbi_write_png_compression_level = 8;
static int stbi_write_tga_with_rle = 1;
static int stbi_write_force_png_filter = -1;
#else
int stbi_write_png_compression_level = 8;
-int stbi__flip_vertically_on_write=0;
+int stbi__flip_vertically_on_write = 0;
int stbi_write_tga_with_rle = 1;
int stbi_write_force_png_filter = -1;
#endif
STBIWDEF void stbi_flip_vertically_on_write(int flag)
{
- stbi__flip_vertically_on_write = flag;
+ stbi__flip_vertically_on_write = flag;
}
typedef struct
{
- stbi_write_func *func;
- void *context;
+ stbi_write_func *func;
+ void *context;
} stbi__write_context;
// initialize a callback-based context
static void stbi__start_write_callbacks(stbi__write_context *s, stbi_write_func *c, void *context)
{
- s->func = c;
- s->context = context;
+ s->func = c;
+ s->context = context;
}
#ifndef STBI_WRITE_NO_STDIO
static void stbi__stdio_write(void *context, void *data, int size)
{
- fwrite(data,1,size,(FILE*) context);
+ fwrite(data, 1, size, context);
}
static int stbi__start_write_file(stbi__write_context *s, const char *filename)
{
- FILE *f;
+ FILE *f;
#ifdef STBI_MSC_SECURE_CRT
- if (fopen_s(&f, filename, "wb"))
- f = NULL;
+if (fopen_s(&f, filename, "wb"))
+f=NULL;
#else
- f = fopen(filename, "wb");
+f= fopen(filename, "wb");
#endif
- stbi__start_write_callbacks(s, stbi__stdio_write, (void *) f);
- return f != NULL;
+stbi__start_write_callbacks(s, stbi__stdio_write, f);
+ return f!= NULL;
}
static void stbi__end_write_file(stbi__write_context *s)
{
- fclose((FILE *)s->context);
+ fclose(s->context);
}
#endif // !STBI_WRITE_NO_STDIO
typedef unsigned int stbiw_uint32;
-typedef int stb_image_write_test[sizeof(stbiw_uint32)==4 ? 1 : -1];
+typedef int stb_image_write_test[sizeof(stbiw_uint32) == 4 ? 1 : -1];
static void stbiw__writefv(stbi__write_context *s, const char *fmt, va_list v)
{
- while (*fmt) {
- switch (*fmt++) {
- case ' ': break;
- case '1': { unsigned char x = STBIW_UCHAR(va_arg(v, int));
- s->func(s->context,&x,1);
- break; }
- case '2': { int x = va_arg(v,int);
- unsigned char b[2];
- b[0] = STBIW_UCHAR(x);
- b[1] = STBIW_UCHAR(x>>8);
- s->func(s->context,b,2);
- break; }
- case '4': { stbiw_uint32 x = va_arg(v,int);
- unsigned char b[4];
- b[0]=STBIW_UCHAR(x);
- b[1]=STBIW_UCHAR(x>>8);
- b[2]=STBIW_UCHAR(x>>16);
- b[3]=STBIW_UCHAR(x>>24);
- s->func(s->context,b,4);
- break; }
- default:
- STBIW_ASSERT(0);
- return;
- }
- }
+ while (*fmt)
+ {
+ switch (*fmt++)
+ {
+ case ' ':
+ break;
+ case '1':
+ {
+ unsigned char x = STBIW_UCHAR(va_arg(v, int));
+ s->func(s->context, &x, 1);
+ break;
+ }
+ case '2':
+ {
+ int x = va_arg(v, int);
+ unsigned char b[2];
+ b[0] = STBIW_UCHAR(x);
+ b[1] = STBIW_UCHAR(x >> 8);
+ s->func(s->context, b, 2);
+ break;
+ }
+ case '4':
+ {
+ stbiw_uint32 x = va_arg(v, int);
+ unsigned char b[4];
+ b[0] = STBIW_UCHAR(x);
+ b[1] = STBIW_UCHAR(x >> 8);
+ b[2] = STBIW_UCHAR(x >> 16);
+ b[3] = STBIW_UCHAR(x >> 24);
+ s->func(s->context, b, 4);
+ break;
+ }
+ default:
+ STBIW_ASSERT(0);
+ return;
+ }
+ }
}
static void stbiw__writef(stbi__write_context *s, const char *fmt, ...)
{
- va_list v;
- va_start(v, fmt);
- stbiw__writefv(s, fmt, v);
- va_end(v);
+ va_list v;
+ va_start(v, fmt);
+ stbiw__writefv(s, fmt, v);
+ va_end(v);
}
static void stbiw__putc(stbi__write_context *s, unsigned char c)
{
- s->func(s->context, &c, 1);
+ s->func(s->context, &c, 1);
}
static void stbiw__write3(stbi__write_context *s, unsigned char a, unsigned char b, unsigned char c)
{
- unsigned char arr[3];
- arr[0] = a, arr[1] = b, arr[2] = c;
- s->func(s->context, arr, 3);
+ unsigned char arr[3];
+ arr[0] = a, arr[1] = b, arr[2] = c;
+ s->func(s->context, arr, 3);
}
static void stbiw__write_pixel(stbi__write_context *s, int rgb_dir, int comp, int write_alpha, int expand_mono, unsigned char *d)
{
- unsigned char bg[3] = { 255, 0, 255}, px[3];
- int k;
+ unsigned char bg[3] = {255, 0, 255}, px[3];
+ int k;
- if (write_alpha < 0)
- s->func(s->context, &d[comp - 1], 1);
+ if (write_alpha < 0)
+ s->func(s->context, &d[comp - 1], 1);
- switch (comp) {
- case 2: // 2 pixels = mono + alpha, alpha is written separately, so same as 1-channel case
- case 1:
- if (expand_mono)
- stbiw__write3(s, d[0], d[0], d[0]); // monochrome bmp
- else
- s->func(s->context, d, 1); // monochrome TGA
- break;
- case 4:
- if (!write_alpha) {
- // composite against pink background
- for (k = 0; k < 3; ++k)
- px[k] = bg[k] + ((d[k] - bg[k]) * d[3]) / 255;
- stbiw__write3(s, px[1 - rgb_dir], px[1], px[1 + rgb_dir]);
+ switch (comp)
+ {
+ case 2: // 2 pixels = mono + alpha, alpha is written separately, so same as 1-channel case
+ case 1:
+ if (expand_mono)
+ stbiw__write3(s, d[0], d[0], d[0]); // monochrome bmp
+ else
+ s->func(s->context, d, 1); // monochrome TGA
break;
- }
- /* FALLTHROUGH */
- case 3:
- stbiw__write3(s, d[1 - rgb_dir], d[1], d[1 + rgb_dir]);
- break;
- }
- if (write_alpha > 0)
- s->func(s->context, &d[comp - 1], 1);
+ case 4:
+ if (!write_alpha)
+ {
+ // composite against pink background
+ for (k = 0; k < 3; ++k)
+ px[k] = bg[k] + (d[k] - bg[k]) * d[3] / 255;
+ stbiw__write3(s, px[1 - rgb_dir], px[1], px[1 + rgb_dir]);
+ break;
+ }
+ /* FALLTHROUGH */
+ case 3:
+ stbiw__write3(s, d[1 - rgb_dir], d[1], d[1 + rgb_dir]);
+ break;
+ }
+ if (write_alpha > 0)
+ s->func(s->context, &d[comp - 1], 1);
}
static void stbiw__write_pixels(stbi__write_context *s, int rgb_dir, int vdir, int x, int y, int comp, void *data, int write_alpha, int scanline_pad, int expand_mono)
{
- stbiw_uint32 zero = 0;
- int i,j, j_end;
+ stbiw_uint32 zero = 0;
+ int i, j, j_end;
- if (y <= 0)
- return;
+ if (y <= 0)
+ return;
- if (stbi__flip_vertically_on_write)
- vdir *= -1;
+ if (stbi__flip_vertically_on_write)
+ vdir *= -1;
- if (vdir < 0)
- j_end = -1, j = y-1;
- else
- j_end = y, j = 0;
+ if (vdir < 0)
+ j_end = -1, j = y - 1;
+ else
+ j_end = y, j = 0;
- for (; j != j_end; j += vdir) {
- for (i=0; i < x; ++i) {
- unsigned char *d = (unsigned char *) data + (j*x+i)*comp;
- stbiw__write_pixel(s, rgb_dir, comp, write_alpha, expand_mono, d);
- }
- s->func(s->context, &zero, scanline_pad);
- }
+ for (; j != j_end; j += vdir)
+ {
+ for (i = 0; i < x; ++i)
+ {
+ unsigned char *d = (unsigned char *)data + (j * x + i) * comp;
+ stbiw__write_pixel(s, rgb_dir, comp, write_alpha, expand_mono, d);
+ }
+ s->func(s->context, &zero, scanline_pad);
+ }
}
static int stbiw__outfile(stbi__write_context *s, int rgb_dir, int vdir, int x, int y, int comp, int expand_mono, void *data, int alpha, int pad, const char *fmt, ...)
{
- if (y < 0 || x < 0) {
- return 0;
- } else {
- va_list v;
- va_start(v, fmt);
- stbiw__writefv(s, fmt, v);
- va_end(v);
- stbiw__write_pixels(s,rgb_dir,vdir,x,y,comp,data,alpha,pad, expand_mono);
- return 1;
- }
+ if (y < 0 || x < 0)
+ {
+ return 0;
+ }
+ else
+ {
+ va_list v;
+ va_start(v, fmt);
+ stbiw__writefv(s, fmt, v);
+ va_end(v);
+ stbiw__write_pixels(s, rgb_dir, vdir, x, y, comp, data, alpha, pad, expand_mono);
+ return 1;
+ }
}
static int stbi_write_bmp_core(stbi__write_context *s, int x, int y, int comp, const void *data)
{
- int pad = (-x*3) & 3;
- return stbiw__outfile(s,-1,-1,x,y,comp,1,(void *) data,0,pad,
- "11 4 22 4" "4 44 22 444444",
- 'B', 'M', 14+40+(x*3+pad)*y, 0,0, 14+40, // file header
- 40, x,y, 1,24, 0,0,0,0,0,0); // bitmap header
+ int pad = -x * 3 & 3;
+ return stbiw__outfile(s, -1, -1, x, y, comp, 1, (void *)data, 0, pad,
+ "11 4 22 4" "4 44 22 444444",
+ 'B', 'M', 14 + 40 + (x * 3 + pad) * y, 0, 0, 14 + 40, // file header
+ 40, x, y, 1, 24, 0, 0, 0, 0, 0, 0); // bitmap header
}
STBIWDEF int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data)
{
- stbi__write_context s;
- stbi__start_write_callbacks(&s, func, context);
- return stbi_write_bmp_core(&s, x, y, comp, data);
+ stbi__write_context s;
+ stbi__start_write_callbacks(&s, func, context);
+ return stbi_write_bmp_core(&s, x, y, comp, data);
}
#ifndef STBI_WRITE_NO_STDIO
STBIWDEF int stbi_write_bmp(char const *filename, int x, int y, int comp, const void *data)
{
- stbi__write_context s;
- if (stbi__start_write_file(&s,filename)) {
- int r = stbi_write_bmp_core(&s, x, y, comp, data);
- stbi__end_write_file(&s);
- return r;
- } else
- return 0;
+ stbi__write_context s;
+ if (stbi__start_write_file(&s, filename))
+ {
+ int r = stbi_write_bmp_core(&s, x, y, comp, data);
+ stbi__end_write_file(&s);
+ return r;
+ }
+ else
+ return 0;
}
#endif //!STBI_WRITE_NO_STDIO
static int stbi_write_tga_core(stbi__write_context *s, int x, int y, int comp, void *data)
{
- int has_alpha = (comp == 2 || comp == 4);
- int colorbytes = has_alpha ? comp-1 : comp;
- int format = colorbytes < 2 ? 3 : 2; // 3 color channels (RGB/RGBA) = 2, 1 color channel (Y/YA) = 3
+ int has_alpha = comp == 2 || comp == 4;
+ int colorbytes = has_alpha ? comp - 1 : comp;
+ int format = colorbytes < 2 ? 3 : 2; // 3 color channels (RGB/RGBA) = 2, 1 color channel (Y/YA) = 3
- if (y < 0 || x < 0)
- return 0;
+ if (y < 0 || x < 0)
+ return 0;
- if (!stbi_write_tga_with_rle) {
- return stbiw__outfile(s, -1, -1, x, y, comp, 0, (void *) data, has_alpha, 0,
- "111 221 2222 11", 0, 0, format, 0, 0, 0, 0, 0, x, y, (colorbytes + has_alpha) * 8, has_alpha * 8);
- } else {
- int i,j,k;
- int jend, jdir;
+ if (!stbi_write_tga_with_rle)
+ {
+ return stbiw__outfile(s, -1, -1, x, y, comp, 0, (void *)data, has_alpha, 0,
+ "111 221 2222 11", 0, 0, format, 0, 0, 0, 0, 0, x, y, (colorbytes + has_alpha) * 8, has_alpha * 8);
+ }
+ else
+ {
+ int i, j, k;
+ int jend, jdir;
- stbiw__writef(s, "111 221 2222 11", 0,0,format+8, 0,0,0, 0,0,x,y, (colorbytes + has_alpha) * 8, has_alpha * 8);
+ stbiw__writef(s, "111 221 2222 11", 0, 0, format + 8, 0, 0, 0, 0, 0, x, y, (colorbytes + has_alpha) * 8, has_alpha * 8);
- if (stbi__flip_vertically_on_write) {
- j = 0;
- jend = y;
- jdir = 1;
- } else {
- j = y-1;
- jend = -1;
- jdir = -1;
- }
- for (; j != jend; j += jdir) {
- unsigned char *row = (unsigned char *) data + j * x * comp;
- int len;
+ if (stbi__flip_vertically_on_write)
+ {
+ j = 0;
+ jend = y;
+ jdir = 1;
+ }
+ else
+ {
+ j = y - 1;
+ jend = -1;
+ jdir = -1;
+ }
+ for (; j != jend; j += jdir)
+ {
+ unsigned char *row = (unsigned char *)data + j * x * comp;
+ int len;
- for (i = 0; i < x; i += len) {
- unsigned char *begin = row + i * comp;
- int diff = 1;
- len = 1;
+ for (i = 0; i < x; i += len)
+ {
+ unsigned char *begin = row + i * comp;
+ int diff = 1;
+ len = 1;
- if (i < x - 1) {
- ++len;
- diff = memcmp(begin, row + (i + 1) * comp, comp);
- if (diff) {
- const unsigned char *prev = begin;
- for (k = i + 2; k < x && len < 128; ++k) {
- if (memcmp(prev, row + k * comp, comp)) {
- prev += comp;
- ++len;
- } else {
- --len;
- break;
- }
- }
- } else {
- for (k = i + 2; k < x && len < 128; ++k) {
- if (!memcmp(begin, row + k * comp, comp)) {
- ++len;
- } else {
- break;
- }
- }
- }
+ if (i < x - 1)
+ {
+ ++len;
+ diff = memcmp(begin, row + (i + 1) * comp, comp);
+ if (diff)
+ {
+ const unsigned char *prev = begin;
+ for (k = i + 2; k < x && len < 128; ++k)
+ {
+ if (memcmp(prev, row + k * comp, comp))
+ {
+ prev += comp;
+ ++len;
+ }
+ else
+ {
+ --len;
+ break;
+ }
+ }
+ }
+ else
+ {
+ for (k = i + 2; k < x && len < 128; ++k)
+ {
+ if (!memcmp(begin, row + k * comp, comp))
+ {
+ ++len;
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+ }
+
+ if (diff)
+ {
+ unsigned char header = STBIW_UCHAR(len - 1);
+ s->func(s->context, &header, 1);
+ for (k = 0; k < len; ++k)
+ {
+ stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin + k * comp);
+ }
+ }
+ else
+ {
+ unsigned char header = STBIW_UCHAR(len - 129);
+ s->func(s->context, &header, 1);
+ stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin);
+ }
}
-
- if (diff) {
- unsigned char header = STBIW_UCHAR(len - 1);
- s->func(s->context, &header, 1);
- for (k = 0; k < len; ++k) {
- stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin + k * comp);
- }
- } else {
- unsigned char header = STBIW_UCHAR(len - 129);
- s->func(s->context, &header, 1);
- stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin);
- }
- }
- }
- }
- return 1;
+ }
+ }
+ return 1;
}
STBIWDEF int stbi_write_tga_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data)
{
- stbi__write_context s;
- stbi__start_write_callbacks(&s, func, context);
- return stbi_write_tga_core(&s, x, y, comp, (void *) data);
+ stbi__write_context s;
+ stbi__start_write_callbacks(&s, func, context);
+ return stbi_write_tga_core(&s, x, y, comp, (void *)data);
}
#ifndef STBI_WRITE_NO_STDIO
STBIWDEF int stbi_write_tga(char const *filename, int x, int y, int comp, const void *data)
{
- stbi__write_context s;
- if (stbi__start_write_file(&s,filename)) {
- int r = stbi_write_tga_core(&s, x, y, comp, (void *) data);
- stbi__end_write_file(&s);
- return r;
- } else
- return 0;
+ stbi__write_context s;
+ if (stbi__start_write_file(&s, filename))
+ {
+ int r = stbi_write_tga_core(&s, x, y, comp, (void *)data);
+ stbi__end_write_file(&s);
+ return r;
+ }
+ else
+ return 0;
}
#endif
@@ -554,169 +609,190 @@ STBIWDEF int stbi_write_tga(char const *filename, int x, int y, int comp, const
void stbiw__linear_to_rgbe(unsigned char *rgbe, float *linear)
{
- int exponent;
- float maxcomp = stbiw__max(linear[0], stbiw__max(linear[1], linear[2]));
+ int exponent;
+ float maxcomp = stbiw__max(linear[0], stbiw__max(linear[1], linear[2]));
- if (maxcomp < 1e-32f) {
- rgbe[0] = rgbe[1] = rgbe[2] = rgbe[3] = 0;
- } else {
- float normalize = (float) frexp(maxcomp, &exponent) * 256.0f/maxcomp;
+ if (maxcomp < 1e-32f)
+ {
+ rgbe[0] = rgbe[1] = rgbe[2] = rgbe[3] = 0;
+ }
+ else
+ {
+ float normalize = (float)frexp(maxcomp, &exponent) * 256.0f / maxcomp;
- rgbe[0] = (unsigned char)(linear[0] * normalize);
- rgbe[1] = (unsigned char)(linear[1] * normalize);
- rgbe[2] = (unsigned char)(linear[2] * normalize);
- rgbe[3] = (unsigned char)(exponent + 128);
- }
+ rgbe[0] = (unsigned char)(linear[0] * normalize);
+ rgbe[1] = (unsigned char)(linear[1] * normalize);
+ rgbe[2] = (unsigned char)(linear[2] * normalize);
+ rgbe[3] = (unsigned char)(exponent + 128);
+ }
}
void stbiw__write_run_data(stbi__write_context *s, int length, unsigned char databyte)
{
- unsigned char lengthbyte = STBIW_UCHAR(length+128);
- STBIW_ASSERT(length+128 <= 255);
- s->func(s->context, &lengthbyte, 1);
- s->func(s->context, &databyte, 1);
+ unsigned char lengthbyte = STBIW_UCHAR(length + 128);
+ STBIW_ASSERT(length + 128 <= 255);
+ s->func(s->context, &lengthbyte, 1);
+ s->func(s->context, &databyte, 1);
}
void stbiw__write_dump_data(stbi__write_context *s, int length, unsigned char *data)
{
- unsigned char lengthbyte = STBIW_UCHAR(length);
- STBIW_ASSERT(length <= 128); // inconsistent with spec but consistent with official code
- s->func(s->context, &lengthbyte, 1);
- s->func(s->context, data, length);
+ unsigned char lengthbyte = STBIW_UCHAR(length);
+ STBIW_ASSERT(length <= 128); // inconsistent with spec but consistent with official code
+ s->func(s->context, &lengthbyte, 1);
+ s->func(s->context, data, length);
}
void stbiw__write_hdr_scanline(stbi__write_context *s, int width, int ncomp, unsigned char *scratch, float *scanline)
{
- unsigned char scanlineheader[4] = { 2, 2, 0, 0 };
- unsigned char rgbe[4];
- float linear[3];
- int x;
+ unsigned char scanlineheader[4] = {2, 2, 0, 0};
+ unsigned char rgbe[4];
+ float linear[3];
+ int x;
- scanlineheader[2] = (width&0xff00)>>8;
- scanlineheader[3] = (width&0x00ff);
+ scanlineheader[2] = (width & 0xff00) >> 8;
+ scanlineheader[3] = width & 0x00ff;
- /* skip RLE for images too small or large */
- if (width < 8 || width >= 32768) {
- for (x=0; x < width; x++) {
- switch (ncomp) {
- case 4: /* fallthrough */
- case 3: linear[2] = scanline[x*ncomp + 2];
- linear[1] = scanline[x*ncomp + 1];
- linear[0] = scanline[x*ncomp + 0];
+ /* skip RLE for images too small or large */
+ if (width < 8 || width >= 32768)
+ {
+ for (x = 0; x < width; x++)
+ {
+ switch (ncomp)
+ {
+ case 4: /* fallthrough */
+ case 3:
+ linear[2] = scanline[x * ncomp + 2];
+ linear[1] = scanline[x * ncomp + 1];
+ linear[0] = scanline[x * ncomp + 0];
break;
- default:
- linear[0] = linear[1] = linear[2] = scanline[x*ncomp + 0];
+ default:
+ linear[0] = linear[1] = linear[2] = scanline[x * ncomp + 0];
break;
- }
- stbiw__linear_to_rgbe(rgbe, linear);
- s->func(s->context, rgbe, 4);
- }
- } else {
- int c,r;
- /* encode into scratch buffer */
- for (x=0; x < width; x++) {
- switch(ncomp) {
- case 4: /* fallthrough */
- case 3: linear[2] = scanline[x*ncomp + 2];
- linear[1] = scanline[x*ncomp + 1];
- linear[0] = scanline[x*ncomp + 0];
- break;
- default:
- linear[0] = linear[1] = linear[2] = scanline[x*ncomp + 0];
- break;
- }
- stbiw__linear_to_rgbe(rgbe, linear);
- scratch[x + width*0] = rgbe[0];
- scratch[x + width*1] = rgbe[1];
- scratch[x + width*2] = rgbe[2];
- scratch[x + width*3] = rgbe[3];
- }
-
- s->func(s->context, scanlineheader, 4);
-
- /* RLE each component separately */
- for (c=0; c < 4; c++) {
- unsigned char *comp = &scratch[width*c];
-
- x = 0;
- while (x < width) {
- // find first run
- r = x;
- while (r+2 < width) {
- if (comp[r] == comp[r+1] && comp[r] == comp[r+2])
- break;
- ++r;
}
- if (r+2 >= width)
- r = width;
- // dump up to first run
- while (x < r) {
- int len = r-x;
- if (len > 128) len = 128;
- stbiw__write_dump_data(s, len, &comp[x]);
- x += len;
+ stbiw__linear_to_rgbe(rgbe, linear);
+ s->func(s->context, rgbe, 4);
+ }
+ }
+ else
+ {
+ int c, r;
+ /* encode into scratch buffer */
+ for (x = 0; x < width; x++)
+ {
+ switch (ncomp)
+ {
+ case 4: /* fallthrough */
+ case 3:
+ linear[2] = scanline[x * ncomp + 2];
+ linear[1] = scanline[x * ncomp + 1];
+ linear[0] = scanline[x * ncomp + 0];
+ break;
+ default:
+ linear[0] = linear[1] = linear[2] = scanline[x * ncomp + 0];
+ break;
}
- // if there's a run, output it
- if (r+2 < width) { // same test as what we break out of in search loop, so only true if we break'd
- // find next byte after run
- while (r < width && comp[r] == comp[x])
- ++r;
- // output run up to r
- while (x < r) {
- int len = r-x;
- if (len > 127) len = 127;
- stbiw__write_run_data(s, len, comp[x]);
- x += len;
- }
+ stbiw__linear_to_rgbe(rgbe, linear);
+ scratch[x + width * 0] = rgbe[0];
+ scratch[x + width * 1] = rgbe[1];
+ scratch[x + width * 2] = rgbe[2];
+ scratch[x + width * 3] = rgbe[3];
+ }
+
+ s->func(s->context, scanlineheader, 4);
+
+ /* RLE each component separately */
+ for (c = 0; c < 4; c++)
+ {
+ unsigned char *comp = &scratch[width * c];
+
+ x = 0;
+ while (x < width)
+ {
+ // find first run
+ r = x;
+ while (r + 2 < width)
+ {
+ if (comp[r] == comp[r + 1] && comp[r] == comp[r + 2])
+ break;
+ ++r;
+ }
+ if (r + 2 >= width)
+ r = width;
+ // dump up to first run
+ while (x < r)
+ {
+ int len = r - x;
+ if (len > 128) len = 128;
+ stbiw__write_dump_data(s, len, &comp[x]);
+ x += len;
+ }
+ // if there's a run, output it
+ if (r + 2 < width)
+ { // same test as what we break out of in search loop, so only true if we break'd
+ // find next byte after run
+ while (r < width && comp[r] == comp[x])
+ ++r;
+ // output run up to r
+ while (x < r)
+ {
+ int len = r - x;
+ if (len > 127) len = 127;
+ stbiw__write_run_data(s, len, comp[x]);
+ x += len;
+ }
+ }
}
- }
- }
- }
+ }
+ }
}
static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, float *data)
{
- if (y <= 0 || x <= 0 || data == NULL)
- return 0;
- else {
- // Each component is stored separately. Allocate scratch space for full output scanline.
- unsigned char *scratch = (unsigned char *) STBIW_MALLOC(x*4);
- int i, len;
- char buffer[128];
- char header[] = "#?RADIANCE\n# Written by stb_image_write.h\nFORMAT=32-bit_rle_rgbe\n";
- s->func(s->context, header, sizeof(header)-1);
+ if (y <= 0 || x <= 0 || data == NULL)
+ return 0;
+ else
+ {
+ // Each component is stored separately. Allocate scratch space for full output scanline.
+ unsigned char *scratch = STBIW_MALLOC(x * 4);
+ int i, len;
+ char buffer[128];
+ char header[] = "#?RADIANCE\n# Written by stb_image_write.h\nFORMAT=32-bit_rle_rgbe\n";
+ s->func(s->context, header, sizeof(header) - 1);
#ifdef STBI_MSC_SECURE_CRT
- len = sprintf_s(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
+len= sprintf_s(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
#else
- len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
+len= sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
#endif
- s->func(s->context, buffer, len);
+s->func (s->context, buffer, len);
- for(i=0; i < y; i++)
- stbiw__write_hdr_scanline(s, x, comp, scratch, data + comp*x*(stbi__flip_vertically_on_write ? y-1-i : i)*x);
- STBIW_FREE(scratch);
+ for(i=0; i= 8) {
- stbiw__sbpush(data, STBIW_UCHAR(*bitbuffer));
- *bitbuffer >>= 8;
- *bitcount -= 8;
- }
- return data;
+ while (*bitcount >= 8)
+ {
+ stbiw__sbpush(data, STBIW_UCHAR(*bitbuffer));
+ *bitbuffer >>= 8;
+ *bitcount -= 8;
+ }
+ return data;
}
static int stbiw__zlib_bitrev(int code, int codebits)
{
- int res=0;
- while (codebits--) {
- res = (res << 1) | (code & 1);
- code >>= 1;
- }
- return res;
+ int res = 0;
+ while (codebits--)
+ {
+ res = res << 1 | code & 1;
+ code >>= 1;
+ }
+ return res;
}
static unsigned int stbiw__zlib_countm(unsigned char *a, unsigned char *b, int limit)
{
- int i;
- for (i=0; i < limit && i < 258; ++i)
- if (a[i] != b[i]) break;
- return i;
+ int i;
+ for (i = 0; i < limit && i < 258; ++i)
+ if (a[i] != b[i]) break;
+ return i;
}
static unsigned int stbiw__zhash(unsigned char *data)
{
- stbiw_uint32 hash = data[0] + (data[1] << 8) + (data[2] << 16);
- hash ^= hash << 3;
- hash += hash >> 5;
- hash ^= hash << 4;
- hash += hash >> 17;
- hash ^= hash << 25;
- hash += hash >> 6;
- return hash;
+ stbiw_uint32 hash = data[0] + (data[1] << 8) + (data[2] << 16);
+ hash ^= hash << 3;
+ hash += hash >> 5;
+ hash ^= hash << 4;
+ hash += hash >> 17;
+ hash ^= hash << 25;
+ hash += hash >> 6;
+ return hash;
}
#define stbiw__zlib_flush() (out = stbiw__zlib_flushf(out, &bitbuf, &bitcount))
@@ -809,161 +888,175 @@ static unsigned int stbiw__zhash(unsigned char *data)
#endif // STBIW_ZLIB_COMPRESS
-unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_len, int quality)
+unsigned char *stbi_zlib_compress(unsigned char *data, int data_len, int *out_len, int quality)
{
+
+
#ifdef STBIW_ZLIB_COMPRESS
- // user provided a zlib compress implementation, use that
- return STBIW_ZLIB_COMPRESS(data, data_len, out_len, quality);
+// user provided a zlib compress implementation, use that
+return STBIW_ZLIB_COMPRESS(data, data_len, out_len, quality);
#else // use builtin
- static unsigned short lengthc[] = { 3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258, 259 };
- static unsigned char lengtheb[]= { 0,0,0,0,0,0,0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0 };
- static unsigned short distc[] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577, 32768 };
- static unsigned char disteb[] = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13 };
- unsigned int bitbuf=0;
- int i,j, bitcount=0;
- unsigned char *out = NULL;
- unsigned char ***hash_table = (unsigned char***) STBIW_MALLOC(stbiw__ZHASH * sizeof(char**));
- if (hash_table == NULL)
+static unsigned short lengthc[] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 259};
+static unsigned char lengtheb[] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0};
+static unsigned short distc[] = {1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 32768};
+static unsigned char disteb[] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13};
+unsigned int bitbuf = 0;
+int i, j, bitcount = 0;
+unsigned char *out = NULL;
+unsigned char ***hash_table = STBIW_MALLOC(stbiw__ZHASH * sizeof(char **));
+ if (hash_table== NULL)
return NULL;
- if (quality < 5) quality = 5;
+ if (quality<5) quality=5;
- stbiw__sbpush(out, 0x78); // DEFLATE 32K window
- stbiw__sbpush(out, 0x5e); // FLEVEL = 1
- stbiw__zlib_add(1,1); // BFINAL = 1
- stbiw__zlib_add(1,2); // BTYPE = 1 -- fixed huffman
+stbiw__sbpush(out, 0x78); // DEFLATE 32K window
+stbiw__sbpush(out, 0x5e); // FLEVEL = 1
+stbiw__zlib_add (1,1); // BFINAL = 1
+stbiw__zlib_add (1,2); // BTYPE = 1 -- fixed huffman
- for (i=0; i < stbiw__ZHASH; ++i)
- hash_table[i] = NULL;
+ for (i=0; i i-32768) { // if entry lies within window
- int d = stbiw__zlib_countm(hlist[j], data+i, data_len-i);
- if (d >= best) best=d,bestloc=hlist[j];
- }
- }
- // when hash table entry is too long, delete half the entries
- if (hash_table[h] && stbiw__sbn(hash_table[h]) == 2*quality) {
- STBIW_MEMMOVE(hash_table[h], hash_table[h]+quality, sizeof(hash_table[h][0])*quality);
- stbiw__sbn(hash_table[h]) = quality;
- }
- stbiw__sbpush(hash_table[h],data+i);
+i=0;
+ while (i i - 32768)
+ { // if entry lies within window
+ int d = stbiw__zlib_countm(hlist[j], data + i, data_len - i);
+ if (d >= best) best = d, bestloc = hlist[j];
+ }
+ }
+ // when hash table entry is too long, delete half the entries
+ if (hash_table[h] && stbiw__sbn(hash_table[h]) == 2 * quality)
+ {
+ STBIW_MEMMOVE(hash_table[h], hash_table[h] + quality, sizeof(hash_table[h][0]) * quality);
+ stbiw__sbn(hash_table[h]) = quality;
+ }
+ stbiw__sbpush(hash_table[h], data + i);
- if (bestloc) {
- // "lazy matching" - check match at *next* byte, and if it's better, do cur byte as literal
- h = stbiw__zhash(data+i+1)&(stbiw__ZHASH-1);
- hlist = hash_table[h];
- n = stbiw__sbcount(hlist);
- for (j=0; j < n; ++j) {
- if (hlist[j]-data > i-32767) {
- int e = stbiw__zlib_countm(hlist[j], data+i+1, data_len-i-1);
- if (e > best) { // if next match is better, bail on current match
- bestloc = NULL;
- break;
- }
+ if (bestloc)
+ {
+ // "lazy matching" - check match at *next* byte, and if it's better, do cur byte as literal
+ h = stbiw__zhash(data + i + 1) & stbiw__ZHASH - 1;
+ hlist = hash_table[h];
+ n = stbiw__sbcount(hlist);
+ for (j = 0; j < n; ++j)
+ {
+ if (hlist[j] - data > i - 32767)
+ {
+ int e = stbiw__zlib_countm(hlist[j], data + i + 1, data_len - i - 1);
+ if (e > best)
+ { // if next match is better, bail on current match
+ bestloc = NULL;
+ break;
+ }
}
- }
- }
+ }
+ }
- if (bestloc) {
- int d = (int) (data+i - bestloc); // distance back
- STBIW_ASSERT(d <= 32767 && best <= 258);
- for (j=0; best > lengthc[j+1]-1; ++j);
- stbiw__zlib_huff(j+257);
- if (lengtheb[j]) stbiw__zlib_add(best - lengthc[j], lengtheb[j]);
- for (j=0; d > distc[j+1]-1; ++j);
- stbiw__zlib_add(stbiw__zlib_bitrev(j,5),5);
- if (disteb[j]) stbiw__zlib_add(d - distc[j], disteb[j]);
- i += best;
- } else {
- stbiw__zlib_huffb(data[i]);
- ++i;
- }
- }
- // write out final bytes
- for (;i < data_len; ++i)
- stbiw__zlib_huffb(data[i]);
- stbiw__zlib_huff(256); // end of block
- // pad with 0 bits to byte boundary
+ if (bestloc)
+ {
+ int d = (int)(data + i - bestloc); // distance back
+ STBIW_ASSERT(d <= 32767 && best <= 258);
+ for (j = 0; best > lengthc[j + 1] - 1; ++j);
+ stbiw__zlib_huff(j + 257);
+ if (lengtheb[j]) stbiw__zlib_add(best - lengthc[j], lengtheb[j]);
+ for (j = 0; d > distc[j + 1] - 1; ++j);
+ stbiw__zlib_add(stbiw__zlib_bitrev(j, 5), 5);
+ if (disteb[j]) stbiw__zlib_add(d - distc[j], disteb[j]);
+ i += best;
+ }
+ else
+ {
+ stbiw__zlib_huffb(data[i]);
+ ++i;
+ }
+}
+// write out final bytes
+ for (;i> 8));
- stbiw__sbpush(out, STBIW_UCHAR(s2));
- stbiw__sbpush(out, STBIW_UCHAR(s1 >> 8));
- stbiw__sbpush(out, STBIW_UCHAR(s1));
- }
- *out_len = stbiw__sbn(out);
- // make returned pointer freeable
- STBIW_MEMMOVE(stbiw__sbraw(out), out, *out_len);
- return (unsigned char *) stbiw__sbraw(out);
+{
+ // compute adler32 on input
+ unsigned int s1 = 1, s2 = 0;
+ int blocklen = data_len % 5552;
+ j = 0;
+ while (j < data_len)
+ {
+ for (i = 0; i < blocklen; ++i) s1 += data[j + i], s2 += s1;
+ s1 %= 65521, s2 %= 65521;
+ j += blocklen;
+ blocklen = 5552;
+ }
+ stbiw__sbpush(out, STBIW_UCHAR(s2 >> 8));
+ stbiw__sbpush(out, STBIW_UCHAR(s2));
+ stbiw__sbpush(out, STBIW_UCHAR(s1 >> 8));
+ stbiw__sbpush(out, STBIW_UCHAR(s1));
+}
+ *out_len= stbiw__sbn(out);
+// make returned pointer freeable
+STBIW_MEMMOVE (stbiw__sbraw(out), out, *out_len);
+ return (unsigned char *) stbiw__sbraw (out);
#endif // STBIW_ZLIB_COMPRESS
}
static unsigned int stbiw__crc32(unsigned char *buffer, int len)
{
- static unsigned int crc_table[256] =
- {
- 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
- 0x0eDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
- 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
- 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
- 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
- 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
- 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
- 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
- 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
- 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
- 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
- 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
- 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
- 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
- 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
- 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
- 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
- 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
- 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
- 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
- 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
- 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
- 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
- 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
- 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
- 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
- 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
- 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
- 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
- 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
- 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
- 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
- };
+ static unsigned int crc_table[256] =
+ {
+ 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
+ 0x0eDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
+ 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
+ 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
+ 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
+ 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
+ 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
+ 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
+ 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
+ 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
+ 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
+ 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
+ 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
+ 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
+ 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
+ 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
+ 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
+ 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
+ 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
+ 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
+ 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
+ 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
+ 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
+ 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
+ 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
+ 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
+ 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
+ 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
+ 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
+ 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
+ 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
+ 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
+ };
- unsigned int crc = ~0u;
- int i;
- for (i=0; i < len; ++i)
- crc = (crc >> 8) ^ crc_table[buffer[i] ^ (crc & 0xff)];
- return ~crc;
+ unsigned int crc = ~0u;
+ int i;
+ for (i = 0; i < len; ++i)
+ crc = crc >> 8 ^ crc_table[buffer[i] ^ crc & 0xff];
+ return ~crc;
}
#define stbiw__wpng4(o,a,b,c,d) ((o)[0]=STBIW_UCHAR(a),(o)[1]=STBIW_UCHAR(b),(o)[2]=STBIW_UCHAR(c),(o)[3]=STBIW_UCHAR(d),(o)+=4)
@@ -972,167 +1065,215 @@ static unsigned int stbiw__crc32(unsigned char *buffer, int len)
static void stbiw__wpcrc(unsigned char **data, int len)
{
- unsigned int crc = stbiw__crc32(*data - len - 4, len+4);
- stbiw__wp32(*data, crc);
+ unsigned int crc = stbiw__crc32(*data - len - 4, len + 4);
+ stbiw__wp32(*data, crc);
}
static unsigned char stbiw__paeth(int a, int b, int c)
{
- int p = a + b - c, pa = abs(p-a), pb = abs(p-b), pc = abs(p-c);
- if (pa <= pb && pa <= pc) return STBIW_UCHAR(a);
- if (pb <= pc) return STBIW_UCHAR(b);
- return STBIW_UCHAR(c);
+ int p = a + b - c, pa = abs(p - a), pb = abs(p - b), pc = abs(p - c);
+ if (pa <= pb && pa <= pc) return STBIW_UCHAR(a);
+ if (pb <= pc) return STBIW_UCHAR(b);
+ return STBIW_UCHAR(c);
}
// @OPTIMIZE: provide an option that always forces left-predict or paeth predict
static void stbiw__encode_png_line(unsigned char *pixels, int stride_bytes, int width, int height, int y, int n, int filter_type, signed char *line_buffer)
{
- static int mapping[] = { 0,1,2,3,4 };
- static int firstmap[] = { 0,1,0,5,6 };
- int *mymap = (y != 0) ? mapping : firstmap;
- int i;
- int type = mymap[filter_type];
- unsigned char *z = pixels + stride_bytes * (stbi__flip_vertically_on_write ? height-1-y : y);
- int signed_stride = stbi__flip_vertically_on_write ? -stride_bytes : stride_bytes;
- for (i = 0; i < n; ++i) {
- switch (type) {
- case 0: line_buffer[i] = z[i]; break;
- case 1: line_buffer[i] = z[i]; break;
- case 2: line_buffer[i] = z[i] - z[i-signed_stride]; break;
- case 3: line_buffer[i] = z[i] - (z[i-signed_stride]>>1); break;
- case 4: line_buffer[i] = (signed char) (z[i] - stbiw__paeth(0,z[i-signed_stride],0)); break;
- case 5: line_buffer[i] = z[i]; break;
- case 6: line_buffer[i] = z[i]; break;
- }
- }
- for (i=n; i < width*n; ++i) {
- switch (type) {
- case 0: line_buffer[i] = z[i]; break;
- case 1: line_buffer[i] = z[i] - z[i-n]; break;
- case 2: line_buffer[i] = z[i] - z[i-signed_stride]; break;
- case 3: line_buffer[i] = z[i] - ((z[i-n] + z[i-signed_stride])>>1); break;
- case 4: line_buffer[i] = z[i] - stbiw__paeth(z[i-n], z[i-signed_stride], z[i-signed_stride-n]); break;
- case 5: line_buffer[i] = z[i] - (z[i-n]>>1); break;
- case 6: line_buffer[i] = z[i] - stbiw__paeth(z[i-n], 0,0); break;
- }
- }
+ static int mapping[] = {0, 1, 2, 3, 4};
+ static int firstmap[] = {0, 1, 0, 5, 6};
+ int *mymap = y != 0 ? mapping : firstmap;
+ int i;
+ int type = mymap[filter_type];
+ unsigned char *z = pixels + stride_bytes * (stbi__flip_vertically_on_write ? height - 1 - y : y);
+ int signed_stride = stbi__flip_vertically_on_write ? -stride_bytes : stride_bytes;
+ for (i = 0; i < n; ++i)
+ {
+ switch (type)
+ {
+ case 0:
+ line_buffer[i] = z[i];
+ break;
+ case 1:
+ line_buffer[i] = z[i];
+ break;
+ case 2:
+ line_buffer[i] = z[i] - z[i - signed_stride];
+ break;
+ case 3:
+ line_buffer[i] = z[i] - (z[i - signed_stride] >> 1);
+ break;
+ case 4:
+ line_buffer[i] = (signed char)(z[i] - stbiw__paeth(0, z[i - signed_stride], 0));
+ break;
+ case 5:
+ line_buffer[i] = z[i];
+ break;
+ case 6:
+ line_buffer[i] = z[i];
+ break;
+ }
+ }
+ for (i = n; i < width * n; ++i)
+ {
+ switch (type)
+ {
+ case 0:
+ line_buffer[i] = z[i];
+ break;
+ case 1:
+ line_buffer[i] = z[i] - z[i - n];
+ break;
+ case 2:
+ line_buffer[i] = z[i] - z[i - signed_stride];
+ break;
+ case 3:
+ line_buffer[i] = z[i] - ((z[i - n] + z[i - signed_stride]) >> 1);
+ break;
+ case 4:
+ line_buffer[i] = z[i] - stbiw__paeth(z[i - n], z[i - signed_stride], z[i - signed_stride - n]);
+ break;
+ case 5:
+ line_buffer[i] = z[i] - (z[i - n] >> 1);
+ break;
+ case 6:
+ line_buffer[i] = z[i] - stbiw__paeth(z[i - n], 0, 0);
+ break;
+ }
+ }
}
unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, int x, int y, int n, int *out_len)
{
- int force_filter = stbi_write_force_png_filter;
- int ctype[5] = { -1, 0, 4, 2, 6 };
- unsigned char sig[8] = { 137,80,78,71,13,10,26,10 };
- unsigned char *out,*o, *filt, *zlib;
- signed char *line_buffer;
- int j,zlen;
+ int force_filter = stbi_write_force_png_filter;
+ int ctype[5] = {-1, 0, 4, 2, 6};
+ unsigned char sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
+ unsigned char *out, *o, *filt, *zlib;
+ signed char *line_buffer;
+ int j, zlen;
- if (stride_bytes == 0)
- stride_bytes = x * n;
+ if (stride_bytes == 0)
+ stride_bytes = x * n;
- if (force_filter >= 5) {
- force_filter = -1;
- }
+ if (force_filter >= 5)
+ {
+ force_filter = -1;
+ }
- filt = (unsigned char *) STBIW_MALLOC((x*n+1) * y); if (!filt) return 0;
- line_buffer = (signed char *) STBIW_MALLOC(x * n); if (!line_buffer) { STBIW_FREE(filt); return 0; }
- for (j=0; j < y; ++j) {
- int filter_type;
- if (force_filter > -1) {
- filter_type = force_filter;
- stbiw__encode_png_line(pixels, stride_bytes, x, y, j, n, force_filter, line_buffer);
- } else { // Estimate the best filter by running through all of them:
- int best_filter = 0, best_filter_val = 0x7fffffff, est, i;
- for (filter_type = 0; filter_type < 5; filter_type++) {
- stbiw__encode_png_line(pixels, stride_bytes, x, y, j, n, filter_type, line_buffer);
+ filt = (unsigned char *)STBIW_MALLOC((x * n + 1) * y);
+ if (!filt) return 0;
+ line_buffer = (signed char *)STBIW_MALLOC(x * n);
+ if (!line_buffer)
+ {
+ STBIW_FREE(filt);
+ return 0;
+ }
+ for (j = 0; j < y; ++j)
+ {
+ int filter_type;
+ if (force_filter > -1)
+ {
+ filter_type = force_filter;
+ stbiw__encode_png_line(pixels, stride_bytes, x, y, j, n, force_filter, line_buffer);
+ }
+ else
+ { // Estimate the best filter by running through all of them:
+ int best_filter = 0, best_filter_val = 0x7fffffff, est, i;
+ for (filter_type = 0; filter_type < 5; filter_type++)
+ {
+ stbiw__encode_png_line(pixels, stride_bytes, x, y, j, n, filter_type, line_buffer);
- // Estimate the entropy of the line using this filter; the less, the better.
- est = 0;
- for (i = 0; i < x*n; ++i) {
- est += abs((signed char) line_buffer[i]);
+ // Estimate the entropy of the line using this filter; the less, the better.
+ est = 0;
+ for (i = 0; i < x * n; ++i)
+ {
+ est += abs(line_buffer[i]);
+ }
+ if (est < best_filter_val)
+ {
+ best_filter_val = est;
+ best_filter = filter_type;
+ }
}
- if (est < best_filter_val) {
- best_filter_val = est;
- best_filter = filter_type;
+ if (filter_type != best_filter)
+ { // If the last iteration already got us the best filter, don't redo it
+ stbiw__encode_png_line(pixels, stride_bytes, x, y, j, n, best_filter, line_buffer);
+ filter_type = best_filter;
}
- }
- if (filter_type != best_filter) { // If the last iteration already got us the best filter, don't redo it
- stbiw__encode_png_line(pixels, stride_bytes, x, y, j, n, best_filter, line_buffer);
- filter_type = best_filter;
- }
- }
- // when we get here, filter_type contains the filter type, and line_buffer contains the data
- filt[j*(x*n+1)] = (unsigned char) filter_type;
- STBIW_MEMMOVE(filt+j*(x*n+1)+1, line_buffer, x*n);
- }
- STBIW_FREE(line_buffer);
- zlib = stbi_zlib_compress(filt, y*( x*n+1), &zlen, stbi_write_png_compression_level);
- STBIW_FREE(filt);
- if (!zlib) return 0;
+ }
+ // when we get here, filter_type contains the filter type, and line_buffer contains the data
+ filt[j * (x * n + 1)] = (unsigned char)filter_type;
+ STBIW_MEMMOVE(filt + j * (x * n + 1) + 1, line_buffer, x * n);
+ }
+ STBIW_FREE(line_buffer);
+ zlib = stbi_zlib_compress(filt, y * (x * n + 1), &zlen, stbi_write_png_compression_level);
+ STBIW_FREE(filt);
+ if (!zlib) return 0;
- // each tag requires 12 bytes of overhead
- out = (unsigned char *) STBIW_MALLOC(8 + 12+13 + 12+zlen + 12);
- if (!out) return 0;
- *out_len = 8 + 12+13 + 12+zlen + 12;
+ // each tag requires 12 bytes of overhead
+ out = (unsigned char *)STBIW_MALLOC(8 + 12 + 13 + 12 + zlen + 12);
+ if (!out) return 0;
+ *out_len = 8 + 12 + 13 + 12 + zlen + 12;
- o=out;
- STBIW_MEMMOVE(o,sig,8); o+= 8;
- stbiw__wp32(o, 13); // header length
- stbiw__wptag(o, "IHDR");
- stbiw__wp32(o, x);
- stbiw__wp32(o, y);
- *o++ = 8;
- *o++ = STBIW_UCHAR(ctype[n]);
- *o++ = 0;
- *o++ = 0;
- *o++ = 0;
- stbiw__wpcrc(&o,13);
+ o = out;
+ STBIW_MEMMOVE(o, sig, 8);
+ o += 8;
+ stbiw__wp32(o, 13); // header length
+ stbiw__wptag(o, "IHDR");
+ stbiw__wp32(o, x);
+ stbiw__wp32(o, y);
+ *o++ = 8;
+ *o++ = STBIW_UCHAR(ctype[n]);
+ *o++ = 0;
+ *o++ = 0;
+ *o++ = 0;
+ stbiw__wpcrc(&o, 13);
- stbiw__wp32(o, zlen);
- stbiw__wptag(o, "IDAT");
- STBIW_MEMMOVE(o, zlib, zlen);
- o += zlen;
- STBIW_FREE(zlib);
- stbiw__wpcrc(&o, zlen);
+ stbiw__wp32(o, zlen);
+ stbiw__wptag(o, "IDAT");
+ STBIW_MEMMOVE(o, zlib, zlen);
+ o += zlen;
+ STBIW_FREE(zlib);
+ stbiw__wpcrc(&o, zlen);
- stbiw__wp32(o,0);
- stbiw__wptag(o, "IEND");
- stbiw__wpcrc(&o,0);
+ stbiw__wp32(o, 0);
+ stbiw__wptag(o, "IEND");
+ stbiw__wpcrc(&o, 0);
- STBIW_ASSERT(o == out + *out_len);
+ STBIW_ASSERT(o == out + *out_len);
- return out;
+ return out;
}
#ifndef STBI_WRITE_NO_STDIO
STBIWDEF int stbi_write_png(char const *filename, int x, int y, int comp, const void *data, int stride_bytes)
{
- FILE *f;
- int len;
- unsigned char *png = stbi_write_png_to_mem((unsigned char *) data, stride_bytes, x, y, comp, &len);
- if (png == NULL) return 0;
+ FILE *f;
+ int len;
+ unsigned char *png = stbi_write_png_to_mem((unsigned char *)data, stride_bytes, x, y, comp, &len);
+ if (png == NULL) return 0;
#ifdef STBI_MSC_SECURE_CRT
- if (fopen_s(&f, filename, "wb"))
- f = NULL;
+if (fopen_s(&f, filename, "wb"))
+f=NULL;
#else
- f = fopen(filename, "wb");
+f= fopen(filename, "wb");
#endif
- if (!f) { STBIW_FREE(png); return 0; }
- fwrite(png, 1, len, f);
- fclose(f);
- STBIW_FREE(png);
+if (!f) { STBIW_FREE(png); return 0; }
+fwrite(png, 1, len, f);
+fclose (f);
+STBIW_FREE (png);
return 1;
}
#endif
STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int stride_bytes)
{
- int len;
- unsigned char *png = stbi_write_png_to_mem((unsigned char *) data, stride_bytes, x, y, comp, &len);
- if (png == NULL) return 0;
- func(context, png, len);
- STBIW_FREE(png);
- return 1;
+ int len;
+ unsigned char *png = stbi_write_png_to_mem((unsigned char *)data, stride_bytes, x, y, comp, &len);
+ if (png == NULL) return 0;
+ func(context, png, len);
+ STBIW_FREE(png);
+ return 1;
}
@@ -1144,339 +1285,384 @@ STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int x,
* public domain Simple, Minimalistic JPEG writer - http://www.jonolick.com/code.html
*/
-static const unsigned char stbiw__jpg_ZigZag[] = { 0,1,5,6,14,15,27,28,2,4,7,13,16,26,29,42,3,8,12,17,25,30,41,43,9,11,18,
- 24,31,40,44,53,10,19,23,32,39,45,52,54,20,22,33,38,46,51,55,60,21,34,37,47,50,56,59,61,35,36,48,49,57,58,62,63 };
+static const unsigned char stbiw__jpg_ZigZag[] = {
+ 0, 1, 5, 6, 14, 15, 27, 28, 2, 4, 7, 13, 16, 26, 29, 42, 3, 8, 12, 17, 25, 30, 41, 43, 9, 11, 18,
+ 24, 31, 40, 44, 53, 10, 19, 23, 32, 39, 45, 52, 54, 20, 22, 33, 38, 46, 51, 55, 60, 21, 34, 37, 47, 50, 56, 59, 61, 35, 36, 48, 49, 57, 58, 62, 63
+};
-static void stbiw__jpg_writeBits(stbi__write_context *s, int *bitBufP, int *bitCntP, const unsigned short *bs) {
- int bitBuf = *bitBufP, bitCnt = *bitCntP;
- bitCnt += bs[1];
- bitBuf |= bs[0] << (24 - bitCnt);
- while(bitCnt >= 8) {
- unsigned char c = (bitBuf >> 16) & 255;
- stbiw__putc(s, c);
- if(c == 255) {
- stbiw__putc(s, 0);
- }
- bitBuf <<= 8;
- bitCnt -= 8;
- }
- *bitBufP = bitBuf;
- *bitCntP = bitCnt;
+static void stbiw__jpg_writeBits(stbi__write_context *s, int *bitBufP, int *bitCntP, const unsigned short *bs)
+{
+ int bitBuf = *bitBufP, bitCnt = *bitCntP;
+ bitCnt += bs[1];
+ bitBuf |= bs[0] << (24 - bitCnt);
+ while (bitCnt >= 8)
+ {
+ unsigned char c = bitBuf >> 16 & 255;
+ stbiw__putc(s, c);
+ if (c == 255)
+ {
+ stbiw__putc(s, 0);
+ }
+ bitBuf <<= 8;
+ bitCnt -= 8;
+ }
+ *bitBufP = bitBuf;
+ *bitCntP = bitCnt;
}
-static void stbiw__jpg_DCT(float *d0p, float *d1p, float *d2p, float *d3p, float *d4p, float *d5p, float *d6p, float *d7p) {
- float d0 = *d0p, d1 = *d1p, d2 = *d2p, d3 = *d3p, d4 = *d4p, d5 = *d5p, d6 = *d6p, d7 = *d7p;
- float z1, z2, z3, z4, z5, z11, z13;
+static void stbiw__jpg_DCT(float *d0p, float *d1p, float *d2p, float *d3p, float *d4p, float *d5p, float *d6p, float *d7p)
+{
+ float d0 = *d0p, d1 = *d1p, d2 = *d2p, d3 = *d3p, d4 = *d4p, d5 = *d5p, d6 = *d6p, d7 = *d7p;
+ float z1, z2, z3, z4, z5, z11, z13;
- float tmp0 = d0 + d7;
- float tmp7 = d0 - d7;
- float tmp1 = d1 + d6;
- float tmp6 = d1 - d6;
- float tmp2 = d2 + d5;
- float tmp5 = d2 - d5;
- float tmp3 = d3 + d4;
- float tmp4 = d3 - d4;
+ float tmp0 = d0 + d7;
+ float tmp7 = d0 - d7;
+ float tmp1 = d1 + d6;
+ float tmp6 = d1 - d6;
+ float tmp2 = d2 + d5;
+ float tmp5 = d2 - d5;
+ float tmp3 = d3 + d4;
+ float tmp4 = d3 - d4;
- // Even part
- float tmp10 = tmp0 + tmp3; // phase 2
- float tmp13 = tmp0 - tmp3;
- float tmp11 = tmp1 + tmp2;
- float tmp12 = tmp1 - tmp2;
+ // Even part
+ float tmp10 = tmp0 + tmp3; // phase 2
+ float tmp13 = tmp0 - tmp3;
+ float tmp11 = tmp1 + tmp2;
+ float tmp12 = tmp1 - tmp2;
- d0 = tmp10 + tmp11; // phase 3
- d4 = tmp10 - tmp11;
+ d0 = tmp10 + tmp11; // phase 3
+ d4 = tmp10 - tmp11;
- z1 = (tmp12 + tmp13) * 0.707106781f; // c4
- d2 = tmp13 + z1; // phase 5
- d6 = tmp13 - z1;
+ z1 = (tmp12 + tmp13) * 0.707106781f; // c4
+ d2 = tmp13 + z1; // phase 5
+ d6 = tmp13 - z1;
- // Odd part
- tmp10 = tmp4 + tmp5; // phase 2
- tmp11 = tmp5 + tmp6;
- tmp12 = tmp6 + tmp7;
+ // Odd part
+ tmp10 = tmp4 + tmp5; // phase 2
+ tmp11 = tmp5 + tmp6;
+ tmp12 = tmp6 + tmp7;
- // The rotator is modified from fig 4-8 to avoid extra negations.
- z5 = (tmp10 - tmp12) * 0.382683433f; // c6
- z2 = tmp10 * 0.541196100f + z5; // c2-c6
- z4 = tmp12 * 1.306562965f + z5; // c2+c6
- z3 = tmp11 * 0.707106781f; // c4
+ // The rotator is modified from fig 4-8 to avoid extra negations.
+ z5 = (tmp10 - tmp12) * 0.382683433f; // c6
+ z2 = tmp10 * 0.541196100f + z5; // c2-c6
+ z4 = tmp12 * 1.306562965f + z5; // c2+c6
+ z3 = tmp11 * 0.707106781f; // c4
- z11 = tmp7 + z3; // phase 5
- z13 = tmp7 - z3;
+ z11 = tmp7 + z3; // phase 5
+ z13 = tmp7 - z3;
- *d5p = z13 + z2; // phase 6
- *d3p = z13 - z2;
- *d1p = z11 + z4;
- *d7p = z11 - z4;
+ *d5p = z13 + z2; // phase 6
+ *d3p = z13 - z2;
+ *d1p = z11 + z4;
+ *d7p = z11 - z4;
- *d0p = d0; *d2p = d2; *d4p = d4; *d6p = d6;
+ *d0p = d0;
+ *d2p = d2;
+ *d4p = d4;
+ *d6p = d6;
}
-static void stbiw__jpg_calcBits(int val, unsigned short bits[2]) {
- int tmp1 = val < 0 ? -val : val;
- val = val < 0 ? val-1 : val;
- bits[1] = 1;
- while(tmp1 >>= 1) {
- ++bits[1];
- }
- bits[0] = val & ((1<>= 1)
+ {
+ ++bits[1];
+ }
+ bits[0] = val & (1 << bits[1]) - 1;
}
-static int stbiw__jpg_processDU(stbi__write_context *s, int *bitBuf, int *bitCnt, float *CDU, float *fdtbl, int DC, const unsigned short HTDC[256][2], const unsigned short HTAC[256][2]) {
- const unsigned short EOB[2] = { HTAC[0x00][0], HTAC[0x00][1] };
- const unsigned short M16zeroes[2] = { HTAC[0xF0][0], HTAC[0xF0][1] };
- int dataOff, i, diff, end0pos;
- int DU[64];
+static int stbiw__jpg_processDU(stbi__write_context *s, int *bitBuf, int *bitCnt, float *CDU, float *fdtbl, int DC, const unsigned short HTDC[256][2], const unsigned short HTAC[256][2])
+{
+ const unsigned short EOB[2] = {HTAC[0x00][0], HTAC[0x00][1]};
+ const unsigned short M16zeroes[2] = {HTAC[0xF0][0], HTAC[0xF0][1]};
+ int dataOff, i, diff, end0pos;
+ int DU[64];
- // DCT rows
- for(dataOff=0; dataOff<64; dataOff+=8) {
- stbiw__jpg_DCT(&CDU[dataOff], &CDU[dataOff+1], &CDU[dataOff+2], &CDU[dataOff+3], &CDU[dataOff+4], &CDU[dataOff+5], &CDU[dataOff+6], &CDU[dataOff+7]);
- }
- // DCT columns
- for(dataOff=0; dataOff<8; ++dataOff) {
- stbiw__jpg_DCT(&CDU[dataOff], &CDU[dataOff+8], &CDU[dataOff+16], &CDU[dataOff+24], &CDU[dataOff+32], &CDU[dataOff+40], &CDU[dataOff+48], &CDU[dataOff+56]);
- }
- // Quantize/descale/zigzag the coefficients
- for(i=0; i<64; ++i) {
- float v = CDU[i]*fdtbl[i];
- // DU[stbiw__jpg_ZigZag[i]] = (int)(v < 0 ? ceilf(v - 0.5f) : floorf(v + 0.5f));
- // ceilf() and floorf() are C99, not C89, but I /think/ they're not needed here anyway?
- DU[stbiw__jpg_ZigZag[i]] = (int)(v < 0 ? v - 0.5f : v + 0.5f);
- }
+ // DCT rows
+ for (dataOff = 0; dataOff < 64; dataOff += 8)
+ {
+ stbiw__jpg_DCT(&CDU[dataOff], &CDU[dataOff + 1], &CDU[dataOff + 2], &CDU[dataOff + 3], &CDU[dataOff + 4], &CDU[dataOff + 5], &CDU[dataOff + 6], &CDU[dataOff + 7]);
+ }
+ // DCT columns
+ for (dataOff = 0; dataOff < 8; ++dataOff)
+ {
+ stbiw__jpg_DCT(&CDU[dataOff], &CDU[dataOff + 8], &CDU[dataOff + 16], &CDU[dataOff + 24], &CDU[dataOff + 32], &CDU[dataOff + 40], &CDU[dataOff + 48], &CDU[dataOff + 56]);
+ }
+ // Quantize/descale/zigzag the coefficients
+ for (i = 0; i < 64; ++i)
+ {
+ float v = CDU[i] * fdtbl[i];
+ // DU[stbiw__jpg_ZigZag[i]] = (int)(v < 0 ? ceilf(v - 0.5f) : floorf(v + 0.5f));
+ // ceilf() and floorf() are C99, not C89, but I /think/ they're not needed here anyway?
+ DU[stbiw__jpg_ZigZag[i]] = (int)(v < 0 ? v - 0.5f : v + 0.5f);
+ }
- // Encode DC
- diff = DU[0] - DC;
- if (diff == 0) {
- stbiw__jpg_writeBits(s, bitBuf, bitCnt, HTDC[0]);
- } else {
- unsigned short bits[2];
- stbiw__jpg_calcBits(diff, bits);
- stbiw__jpg_writeBits(s, bitBuf, bitCnt, HTDC[bits[1]]);
- stbiw__jpg_writeBits(s, bitBuf, bitCnt, bits);
- }
- // Encode ACs
- end0pos = 63;
- for(; (end0pos>0)&&(DU[end0pos]==0); --end0pos) {
- }
- // end0pos = first element in reverse order !=0
- if(end0pos == 0) {
- stbiw__jpg_writeBits(s, bitBuf, bitCnt, EOB);
- return DU[0];
- }
- for(i = 1; i <= end0pos; ++i) {
- int startpos = i;
- int nrzeroes;
- unsigned short bits[2];
- for (; DU[i]==0 && i<=end0pos; ++i) {
- }
- nrzeroes = i-startpos;
- if ( nrzeroes >= 16 ) {
- int lng = nrzeroes>>4;
- int nrmarker;
- for (nrmarker=1; nrmarker <= lng; ++nrmarker)
- stbiw__jpg_writeBits(s, bitBuf, bitCnt, M16zeroes);
- nrzeroes &= 15;
- }
- stbiw__jpg_calcBits(DU[i], bits);
- stbiw__jpg_writeBits(s, bitBuf, bitCnt, HTAC[(nrzeroes<<4)+bits[1]]);
- stbiw__jpg_writeBits(s, bitBuf, bitCnt, bits);
- }
- if(end0pos != 63) {
- stbiw__jpg_writeBits(s, bitBuf, bitCnt, EOB);
- }
- return DU[0];
+ // Encode DC
+ diff = DU[0] - DC;
+ if (diff == 0)
+ {
+ stbiw__jpg_writeBits(s, bitBuf, bitCnt, HTDC[0]);
+ }
+ else
+ {
+ unsigned short bits[2];
+ stbiw__jpg_calcBits(diff, bits);
+ stbiw__jpg_writeBits(s, bitBuf, bitCnt, HTDC[bits[1]]);
+ stbiw__jpg_writeBits(s, bitBuf, bitCnt, bits);
+ }
+ // Encode ACs
+ end0pos = 63;
+ for (; end0pos > 0 && DU[end0pos] == 0; --end0pos)
+ {
+ }
+ // end0pos = first element in reverse order !=0
+ if (end0pos == 0)
+ {
+ stbiw__jpg_writeBits(s, bitBuf, bitCnt, EOB);
+ return DU[0];
+ }
+ for (i = 1; i <= end0pos; ++i)
+ {
+ int startpos = i;
+ int nrzeroes;
+ unsigned short bits[2];
+ for (; DU[i] == 0 && i <= end0pos; ++i)
+ {
+ }
+ nrzeroes = i - startpos;
+ if (nrzeroes >= 16)
+ {
+ int lng = nrzeroes >> 4;
+ int nrmarker;
+ for (nrmarker = 1; nrmarker <= lng; ++nrmarker)
+ stbiw__jpg_writeBits(s, bitBuf, bitCnt, M16zeroes);
+ nrzeroes &= 15;
+ }
+ stbiw__jpg_calcBits(DU[i], bits);
+ stbiw__jpg_writeBits(s, bitBuf, bitCnt, HTAC[(nrzeroes << 4) + bits[1]]);
+ stbiw__jpg_writeBits(s, bitBuf, bitCnt, bits);
+ }
+ if (end0pos != 63)
+ {
+ stbiw__jpg_writeBits(s, bitBuf, bitCnt, EOB);
+ }
+ return DU[0];
}
-static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, int comp, const void* data, int quality) {
- // Constants that don't pollute global namespace
- static const unsigned char std_dc_luminance_nrcodes[] = {0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0};
- static const unsigned char std_dc_luminance_values[] = {0,1,2,3,4,5,6,7,8,9,10,11};
- static const unsigned char std_ac_luminance_nrcodes[] = {0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,0x7d};
- static const unsigned char std_ac_luminance_values[] = {
- 0x01,0x02,0x03,0x00,0x04,0x11,0x05,0x12,0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07,0x22,0x71,0x14,0x32,0x81,0x91,0xa1,0x08,
- 0x23,0x42,0xb1,0xc1,0x15,0x52,0xd1,0xf0,0x24,0x33,0x62,0x72,0x82,0x09,0x0a,0x16,0x17,0x18,0x19,0x1a,0x25,0x26,0x27,0x28,
- 0x29,0x2a,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59,
- 0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x83,0x84,0x85,0x86,0x87,0x88,0x89,
- 0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6,
- 0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe1,0xe2,
- 0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa
- };
- static const unsigned char std_dc_chrominance_nrcodes[] = {0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0};
- static const unsigned char std_dc_chrominance_values[] = {0,1,2,3,4,5,6,7,8,9,10,11};
- static const unsigned char std_ac_chrominance_nrcodes[] = {0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,0x77};
- static const unsigned char std_ac_chrominance_values[] = {
- 0x00,0x01,0x02,0x03,0x11,0x04,0x05,0x21,0x31,0x06,0x12,0x41,0x51,0x07,0x61,0x71,0x13,0x22,0x32,0x81,0x08,0x14,0x42,0x91,
- 0xa1,0xb1,0xc1,0x09,0x23,0x33,0x52,0xf0,0x15,0x62,0x72,0xd1,0x0a,0x16,0x24,0x34,0xe1,0x25,0xf1,0x17,0x18,0x19,0x1a,0x26,
- 0x27,0x28,0x29,0x2a,0x35,0x36,0x37,0x38,0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,
- 0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x82,0x83,0x84,0x85,0x86,0x87,
- 0x88,0x89,0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,
- 0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,
- 0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa
- };
- // Huffman tables
- static const unsigned short YDC_HT[256][2] = { {0,2},{2,3},{3,3},{4,3},{5,3},{6,3},{14,4},{30,5},{62,6},{126,7},{254,8},{510,9}};
- static const unsigned short UVDC_HT[256][2] = { {0,2},{1,2},{2,2},{6,3},{14,4},{30,5},{62,6},{126,7},{254,8},{510,9},{1022,10},{2046,11}};
- static const unsigned short YAC_HT[256][2] = {
- {10,4},{0,2},{1,2},{4,3},{11,4},{26,5},{120,7},{248,8},{1014,10},{65410,16},{65411,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {12,4},{27,5},{121,7},{502,9},{2038,11},{65412,16},{65413,16},{65414,16},{65415,16},{65416,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {28,5},{249,8},{1015,10},{4084,12},{65417,16},{65418,16},{65419,16},{65420,16},{65421,16},{65422,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {58,6},{503,9},{4085,12},{65423,16},{65424,16},{65425,16},{65426,16},{65427,16},{65428,16},{65429,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {59,6},{1016,10},{65430,16},{65431,16},{65432,16},{65433,16},{65434,16},{65435,16},{65436,16},{65437,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {122,7},{2039,11},{65438,16},{65439,16},{65440,16},{65441,16},{65442,16},{65443,16},{65444,16},{65445,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {123,7},{4086,12},{65446,16},{65447,16},{65448,16},{65449,16},{65450,16},{65451,16},{65452,16},{65453,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {250,8},{4087,12},{65454,16},{65455,16},{65456,16},{65457,16},{65458,16},{65459,16},{65460,16},{65461,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {504,9},{32704,15},{65462,16},{65463,16},{65464,16},{65465,16},{65466,16},{65467,16},{65468,16},{65469,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {505,9},{65470,16},{65471,16},{65472,16},{65473,16},{65474,16},{65475,16},{65476,16},{65477,16},{65478,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {506,9},{65479,16},{65480,16},{65481,16},{65482,16},{65483,16},{65484,16},{65485,16},{65486,16},{65487,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {1017,10},{65488,16},{65489,16},{65490,16},{65491,16},{65492,16},{65493,16},{65494,16},{65495,16},{65496,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {1018,10},{65497,16},{65498,16},{65499,16},{65500,16},{65501,16},{65502,16},{65503,16},{65504,16},{65505,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {2040,11},{65506,16},{65507,16},{65508,16},{65509,16},{65510,16},{65511,16},{65512,16},{65513,16},{65514,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {65515,16},{65516,16},{65517,16},{65518,16},{65519,16},{65520,16},{65521,16},{65522,16},{65523,16},{65524,16},{0,0},{0,0},{0,0},{0,0},{0,0},
- {2041,11},{65525,16},{65526,16},{65527,16},{65528,16},{65529,16},{65530,16},{65531,16},{65532,16},{65533,16},{65534,16},{0,0},{0,0},{0,0},{0,0},{0,0}
- };
- static const unsigned short UVAC_HT[256][2] = {
- {0,2},{1,2},{4,3},{10,4},{24,5},{25,5},{56,6},{120,7},{500,9},{1014,10},{4084,12},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {11,4},{57,6},{246,8},{501,9},{2038,11},{4085,12},{65416,16},{65417,16},{65418,16},{65419,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {26,5},{247,8},{1015,10},{4086,12},{32706,15},{65420,16},{65421,16},{65422,16},{65423,16},{65424,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {27,5},{248,8},{1016,10},{4087,12},{65425,16},{65426,16},{65427,16},{65428,16},{65429,16},{65430,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {58,6},{502,9},{65431,16},{65432,16},{65433,16},{65434,16},{65435,16},{65436,16},{65437,16},{65438,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {59,6},{1017,10},{65439,16},{65440,16},{65441,16},{65442,16},{65443,16},{65444,16},{65445,16},{65446,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {121,7},{2039,11},{65447,16},{65448,16},{65449,16},{65450,16},{65451,16},{65452,16},{65453,16},{65454,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {122,7},{2040,11},{65455,16},{65456,16},{65457,16},{65458,16},{65459,16},{65460,16},{65461,16},{65462,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {249,8},{65463,16},{65464,16},{65465,16},{65466,16},{65467,16},{65468,16},{65469,16},{65470,16},{65471,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {503,9},{65472,16},{65473,16},{65474,16},{65475,16},{65476,16},{65477,16},{65478,16},{65479,16},{65480,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {504,9},{65481,16},{65482,16},{65483,16},{65484,16},{65485,16},{65486,16},{65487,16},{65488,16},{65489,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {505,9},{65490,16},{65491,16},{65492,16},{65493,16},{65494,16},{65495,16},{65496,16},{65497,16},{65498,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {506,9},{65499,16},{65500,16},{65501,16},{65502,16},{65503,16},{65504,16},{65505,16},{65506,16},{65507,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {2041,11},{65508,16},{65509,16},{65510,16},{65511,16},{65512,16},{65513,16},{65514,16},{65515,16},{65516,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {16352,14},{65517,16},{65518,16},{65519,16},{65520,16},{65521,16},{65522,16},{65523,16},{65524,16},{65525,16},{0,0},{0,0},{0,0},{0,0},{0,0},
- {1018,10},{32707,15},{65526,16},{65527,16},{65528,16},{65529,16},{65530,16},{65531,16},{65532,16},{65533,16},{65534,16},{0,0},{0,0},{0,0},{0,0},{0,0}
- };
- static const int YQT[] = {16,11,10,16,24,40,51,61,12,12,14,19,26,58,60,55,14,13,16,24,40,57,69,56,14,17,22,29,51,87,80,62,18,22,
- 37,56,68,109,103,77,24,35,55,64,81,104,113,92,49,64,78,87,103,121,120,101,72,92,95,98,112,100,103,99};
- static const int UVQT[] = {17,18,24,47,99,99,99,99,18,21,26,66,99,99,99,99,24,26,56,99,99,99,99,99,47,66,99,99,99,99,99,99,
- 99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99};
- static const float aasf[] = { 1.0f * 2.828427125f, 1.387039845f * 2.828427125f, 1.306562965f * 2.828427125f, 1.175875602f * 2.828427125f,
- 1.0f * 2.828427125f, 0.785694958f * 2.828427125f, 0.541196100f * 2.828427125f, 0.275899379f * 2.828427125f };
+static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, int comp, const void *data, int quality)
+{
+ // Constants that don't pollute global namespace
+ static const unsigned char std_dc_luminance_nrcodes[] = {0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0};
+ static const unsigned char std_dc_luminance_values[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
+ static const unsigned char std_ac_luminance_nrcodes[] = {0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d};
+ static const unsigned char std_ac_luminance_values[] = {
+ 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
+ 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
+ 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
+ 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
+ 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
+ 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
+ 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa
+ };
+ static const unsigned char std_dc_chrominance_nrcodes[] = {0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0};
+ static const unsigned char std_dc_chrominance_values[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
+ static const unsigned char std_ac_chrominance_nrcodes[] = {0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77};
+ static const unsigned char std_ac_chrominance_values[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
+ 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
+ 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
+ 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+ 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
+ 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
+ 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa
+ };
+ // Huffman tables
+ static const unsigned short YDC_HT[256][2] = {{0, 2}, {2, 3}, {3, 3}, {4, 3}, {5, 3}, {6, 3}, {14, 4}, {30, 5}, {62, 6}, {126, 7}, {254, 8}, {510, 9}};
+ static const unsigned short UVDC_HT[256][2] = {{0, 2}, {1, 2}, {2, 2}, {6, 3}, {14, 4}, {30, 5}, {62, 6}, {126, 7}, {254, 8}, {510, 9}, {1022, 10}, {2046, 11}};
+ static const unsigned short YAC_HT[256][2] = {
+ {10, 4}, {0, 2}, {1, 2}, {4, 3}, {11, 4}, {26, 5}, {120, 7}, {248, 8}, {1014, 10}, {65410, 16}, {65411, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {12, 4}, {27, 5}, {121, 7}, {502, 9}, {2038, 11}, {65412, 16}, {65413, 16}, {65414, 16}, {65415, 16}, {65416, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {28, 5}, {249, 8}, {1015, 10}, {4084, 12}, {65417, 16}, {65418, 16}, {65419, 16}, {65420, 16}, {65421, 16}, {65422, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {58, 6}, {503, 9}, {4085, 12}, {65423, 16}, {65424, 16}, {65425, 16}, {65426, 16}, {65427, 16}, {65428, 16}, {65429, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {59, 6}, {1016, 10}, {65430, 16}, {65431, 16}, {65432, 16}, {65433, 16}, {65434, 16}, {65435, 16}, {65436, 16}, {65437, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {122, 7}, {2039, 11}, {65438, 16}, {65439, 16}, {65440, 16}, {65441, 16}, {65442, 16}, {65443, 16}, {65444, 16}, {65445, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {123, 7}, {4086, 12}, {65446, 16}, {65447, 16}, {65448, 16}, {65449, 16}, {65450, 16}, {65451, 16}, {65452, 16}, {65453, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {250, 8}, {4087, 12}, {65454, 16}, {65455, 16}, {65456, 16}, {65457, 16}, {65458, 16}, {65459, 16}, {65460, 16}, {65461, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {504, 9}, {32704, 15}, {65462, 16}, {65463, 16}, {65464, 16}, {65465, 16}, {65466, 16}, {65467, 16}, {65468, 16}, {65469, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {505, 9}, {65470, 16}, {65471, 16}, {65472, 16}, {65473, 16}, {65474, 16}, {65475, 16}, {65476, 16}, {65477, 16}, {65478, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {506, 9}, {65479, 16}, {65480, 16}, {65481, 16}, {65482, 16}, {65483, 16}, {65484, 16}, {65485, 16}, {65486, 16}, {65487, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {1017, 10}, {65488, 16}, {65489, 16}, {65490, 16}, {65491, 16}, {65492, 16}, {65493, 16}, {65494, 16}, {65495, 16}, {65496, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {1018, 10}, {65497, 16}, {65498, 16}, {65499, 16}, {65500, 16}, {65501, 16}, {65502, 16}, {65503, 16}, {65504, 16}, {65505, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {2040, 11}, {65506, 16}, {65507, 16}, {65508, 16}, {65509, 16}, {65510, 16}, {65511, 16}, {65512, 16}, {65513, 16}, {65514, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {65515, 16}, {65516, 16}, {65517, 16}, {65518, 16}, {65519, 16}, {65520, 16}, {65521, 16}, {65522, 16}, {65523, 16}, {65524, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {2041, 11}, {65525, 16}, {65526, 16}, {65527, 16}, {65528, 16}, {65529, 16}, {65530, 16}, {65531, 16}, {65532, 16}, {65533, 16}, {65534, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}
+ };
+ static const unsigned short UVAC_HT[256][2] = {
+ {0, 2}, {1, 2}, {4, 3}, {10, 4}, {24, 5}, {25, 5}, {56, 6}, {120, 7}, {500, 9}, {1014, 10}, {4084, 12}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {11, 4}, {57, 6}, {246, 8}, {501, 9}, {2038, 11}, {4085, 12}, {65416, 16}, {65417, 16}, {65418, 16}, {65419, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {26, 5}, {247, 8}, {1015, 10}, {4086, 12}, {32706, 15}, {65420, 16}, {65421, 16}, {65422, 16}, {65423, 16}, {65424, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {27, 5}, {248, 8}, {1016, 10}, {4087, 12}, {65425, 16}, {65426, 16}, {65427, 16}, {65428, 16}, {65429, 16}, {65430, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {58, 6}, {502, 9}, {65431, 16}, {65432, 16}, {65433, 16}, {65434, 16}, {65435, 16}, {65436, 16}, {65437, 16}, {65438, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {59, 6}, {1017, 10}, {65439, 16}, {65440, 16}, {65441, 16}, {65442, 16}, {65443, 16}, {65444, 16}, {65445, 16}, {65446, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {121, 7}, {2039, 11}, {65447, 16}, {65448, 16}, {65449, 16}, {65450, 16}, {65451, 16}, {65452, 16}, {65453, 16}, {65454, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {122, 7}, {2040, 11}, {65455, 16}, {65456, 16}, {65457, 16}, {65458, 16}, {65459, 16}, {65460, 16}, {65461, 16}, {65462, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {249, 8}, {65463, 16}, {65464, 16}, {65465, 16}, {65466, 16}, {65467, 16}, {65468, 16}, {65469, 16}, {65470, 16}, {65471, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {503, 9}, {65472, 16}, {65473, 16}, {65474, 16}, {65475, 16}, {65476, 16}, {65477, 16}, {65478, 16}, {65479, 16}, {65480, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {504, 9}, {65481, 16}, {65482, 16}, {65483, 16}, {65484, 16}, {65485, 16}, {65486, 16}, {65487, 16}, {65488, 16}, {65489, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {505, 9}, {65490, 16}, {65491, 16}, {65492, 16}, {65493, 16}, {65494, 16}, {65495, 16}, {65496, 16}, {65497, 16}, {65498, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {506, 9}, {65499, 16}, {65500, 16}, {65501, 16}, {65502, 16}, {65503, 16}, {65504, 16}, {65505, 16}, {65506, 16}, {65507, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {2041, 11}, {65508, 16}, {65509, 16}, {65510, 16}, {65511, 16}, {65512, 16}, {65513, 16}, {65514, 16}, {65515, 16}, {65516, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {16352, 14}, {65517, 16}, {65518, 16}, {65519, 16}, {65520, 16}, {65521, 16}, {65522, 16}, {65523, 16}, {65524, 16}, {65525, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
+ {1018, 10}, {32707, 15}, {65526, 16}, {65527, 16}, {65528, 16}, {65529, 16}, {65530, 16}, {65531, 16}, {65532, 16}, {65533, 16}, {65534, 16}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}
+ };
+ static const int YQT[] = {
+ 16, 11, 10, 16, 24, 40, 51, 61, 12, 12, 14, 19, 26, 58, 60, 55, 14, 13, 16, 24, 40, 57, 69, 56, 14, 17, 22, 29, 51, 87, 80, 62, 18, 22,
+ 37, 56, 68, 109, 103, 77, 24, 35, 55, 64, 81, 104, 113, 92, 49, 64, 78, 87, 103, 121, 120, 101, 72, 92, 95, 98, 112, 100, 103, 99
+ };
+ static const int UVQT[] = {
+ 17, 18, 24, 47, 99, 99, 99, 99, 18, 21, 26, 66, 99, 99, 99, 99, 24, 26, 56, 99, 99, 99, 99, 99, 47, 66, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99
+ };
+ static const float aasf[] = {
+ 1.0f * 2.828427125f, 1.387039845f * 2.828427125f, 1.306562965f * 2.828427125f, 1.175875602f * 2.828427125f,
+ 1.0f * 2.828427125f, 0.785694958f * 2.828427125f, 0.541196100f * 2.828427125f, 0.275899379f * 2.828427125f
+ };
- int row, col, i, k;
- float fdtbl_Y[64], fdtbl_UV[64];
- unsigned char YTable[64], UVTable[64];
+ int row, col, i, k;
+ float fdtbl_Y[64], fdtbl_UV[64];
+ unsigned char YTable[64], UVTable[64];
- if(!data || !width || !height || comp > 4 || comp < 1) {
- return 0;
- }
+ if (!data || !width || !height || comp > 4 || comp < 1)
+ {
+ return 0;
+ }
- quality = quality ? quality : 90;
- quality = quality < 1 ? 1 : quality > 100 ? 100 : quality;
- quality = quality < 50 ? 5000 / quality : 200 - quality * 2;
+ quality = quality ? quality : 90;
+ quality = quality < 1 ? 1 : quality > 100 ? 100 : quality;
+ quality = quality < 50 ? 5000 / quality : 200 - quality * 2;
- for(i = 0; i < 64; ++i) {
- int uvti, yti = (YQT[i]*quality+50)/100;
- YTable[stbiw__jpg_ZigZag[i]] = (unsigned char) (yti < 1 ? 1 : yti > 255 ? 255 : yti);
- uvti = (UVQT[i]*quality+50)/100;
- UVTable[stbiw__jpg_ZigZag[i]] = (unsigned char) (uvti < 1 ? 1 : uvti > 255 ? 255 : uvti);
- }
+ for (i = 0; i < 64; ++i)
+ {
+ int uvti, yti = (YQT[i] * quality + 50) / 100;
+ YTable[stbiw__jpg_ZigZag[i]] = (unsigned char)(yti < 1 ? 1 : yti > 255 ? 255 : yti);
+ uvti = (UVQT[i] * quality + 50) / 100;
+ UVTable[stbiw__jpg_ZigZag[i]] = (unsigned char)(uvti < 1 ? 1 : uvti > 255 ? 255 : uvti);
+ }
- for(row = 0, k = 0; row < 8; ++row) {
- for(col = 0; col < 8; ++col, ++k) {
- fdtbl_Y[k] = 1 / (YTable [stbiw__jpg_ZigZag[k]] * aasf[row] * aasf[col]);
- fdtbl_UV[k] = 1 / (UVTable[stbiw__jpg_ZigZag[k]] * aasf[row] * aasf[col]);
- }
- }
+ for (row = 0, k = 0; row < 8; ++row)
+ {
+ for (col = 0; col < 8; ++col, ++k)
+ {
+ fdtbl_Y[k] = 1 / (YTable[stbiw__jpg_ZigZag[k]] * aasf[row] * aasf[col]);
+ fdtbl_UV[k] = 1 / (UVTable[stbiw__jpg_ZigZag[k]] * aasf[row] * aasf[col]);
+ }
+ }
- // Write Headers
- {
- static const unsigned char head0[] = { 0xFF,0xD8,0xFF,0xE0,0,0x10,'J','F','I','F',0,1,1,0,0,1,0,1,0,0,0xFF,0xDB,0,0x84,0 };
- static const unsigned char head2[] = { 0xFF,0xDA,0,0xC,3,1,0,2,0x11,3,0x11,0,0x3F,0 };
- const unsigned char head1[] = { 0xFF,0xC0,0,0x11,8,(unsigned char)(height>>8),STBIW_UCHAR(height),(unsigned char)(width>>8),STBIW_UCHAR(width),
- 3,1,0x11,0,2,0x11,1,3,0x11,1,0xFF,0xC4,0x01,0xA2,0 };
- s->func(s->context, (void*)head0, sizeof(head0));
- s->func(s->context, (void*)YTable, sizeof(YTable));
- stbiw__putc(s, 1);
- s->func(s->context, UVTable, sizeof(UVTable));
- s->func(s->context, (void*)head1, sizeof(head1));
- s->func(s->context, (void*)(std_dc_luminance_nrcodes+1), sizeof(std_dc_luminance_nrcodes)-1);
- s->func(s->context, (void*)std_dc_luminance_values, sizeof(std_dc_luminance_values));
- stbiw__putc(s, 0x10); // HTYACinfo
- s->func(s->context, (void*)(std_ac_luminance_nrcodes+1), sizeof(std_ac_luminance_nrcodes)-1);
- s->func(s->context, (void*)std_ac_luminance_values, sizeof(std_ac_luminance_values));
- stbiw__putc(s, 1); // HTUDCinfo
- s->func(s->context, (void*)(std_dc_chrominance_nrcodes+1), sizeof(std_dc_chrominance_nrcodes)-1);
- s->func(s->context, (void*)std_dc_chrominance_values, sizeof(std_dc_chrominance_values));
- stbiw__putc(s, 0x11); // HTUACinfo
- s->func(s->context, (void*)(std_ac_chrominance_nrcodes+1), sizeof(std_ac_chrominance_nrcodes)-1);
- s->func(s->context, (void*)std_ac_chrominance_values, sizeof(std_ac_chrominance_values));
- s->func(s->context, (void*)head2, sizeof(head2));
- }
+ // Write Headers
+ {
+ static const unsigned char head0[] = {0xFF, 0xD8, 0xFF, 0xE0, 0, 0x10, 'J', 'F', 'I', 'F', 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0xFF, 0xDB, 0, 0x84, 0};
+ static const unsigned char head2[] = {0xFF, 0xDA, 0, 0xC, 3, 1, 0, 2, 0x11, 3, 0x11, 0, 0x3F, 0};
+ const unsigned char head1[] = {
+ 0xFF, 0xC0, 0, 0x11, 8, (unsigned char)(height >> 8), STBIW_UCHAR(height), (unsigned char)(width >> 8), STBIW_UCHAR(width),
+ 3, 1, 0x11, 0, 2, 0x11, 1, 3, 0x11, 1, 0xFF, 0xC4, 0x01, 0xA2, 0
+ };
+ s->func(s->context, (void *)head0, sizeof(head0));
+ s->func(s->context, (void *)YTable, sizeof(YTable));
+ stbiw__putc(s, 1);
+ s->func(s->context, UVTable, sizeof(UVTable));
+ s->func(s->context, (void *)head1, sizeof(head1));
+ s->func(s->context, (void *)(std_dc_luminance_nrcodes + 1), sizeof(std_dc_luminance_nrcodes) - 1);
+ s->func(s->context, (void *)std_dc_luminance_values, sizeof(std_dc_luminance_values));
+ stbiw__putc(s, 0x10); // HTYACinfo
+ s->func(s->context, (void *)(std_ac_luminance_nrcodes + 1), sizeof(std_ac_luminance_nrcodes) - 1);
+ s->func(s->context, (void *)std_ac_luminance_values, sizeof(std_ac_luminance_values));
+ stbiw__putc(s, 1); // HTUDCinfo
+ s->func(s->context, (void *)(std_dc_chrominance_nrcodes + 1), sizeof(std_dc_chrominance_nrcodes) - 1);
+ s->func(s->context, (void *)std_dc_chrominance_values, sizeof(std_dc_chrominance_values));
+ stbiw__putc(s, 0x11); // HTUACinfo
+ s->func(s->context, (void *)(std_ac_chrominance_nrcodes + 1), sizeof(std_ac_chrominance_nrcodes) - 1);
+ s->func(s->context, (void *)std_ac_chrominance_values, sizeof(std_ac_chrominance_values));
+ s->func(s->context, (void *)head2, sizeof(head2));
+ }
- // Encode 8x8 macroblocks
- {
- static const unsigned short fillBits[] = {0x7F, 7};
- const unsigned char *imageData = (const unsigned char *)data;
- int DCY=0, DCU=0, DCV=0;
- int bitBuf=0, bitCnt=0;
- // comp == 2 is grey+alpha (alpha is ignored)
- int ofsG = comp > 2 ? 1 : 0, ofsB = comp > 2 ? 2 : 0;
- int x, y, pos;
- for(y = 0; y < height; y += 8) {
- for(x = 0; x < width; x += 8) {
- float YDU[64], UDU[64], VDU[64];
- for(row = y, pos = 0; row < y+8; ++row) {
- for(col = x; col < x+8; ++col, ++pos) {
- int p = (stbi__flip_vertically_on_write ? height-1-row : row)*width*comp + col*comp;
- float r, g, b;
- if(row >= height) {
- p -= width*comp*(row+1 - height);
- }
- if(col >= width) {
- p -= comp*(col+1 - width);
- }
+ // Encode 8x8 macroblocks
+ {
+ static const unsigned short fillBits[] = {0x7F, 7};
+ const unsigned char *imageData = data;
+ int DCY = 0, DCU = 0, DCV = 0;
+ int bitBuf = 0, bitCnt = 0;
+ // comp == 2 is grey+alpha (alpha is ignored)
+ int ofsG = comp > 2 ? 1 : 0, ofsB = comp > 2 ? 2 : 0;
+ int x, y, pos;
+ for (y = 0; y < height; y += 8)
+ {
+ for (x = 0; x < width; x += 8)
+ {
+ float YDU[64], UDU[64], VDU[64];
+ for (row = y, pos = 0; row < y + 8; ++row)
+ {
+ for (col = x; col < x + 8; ++col, ++pos)
+ {
+ int p = (stbi__flip_vertically_on_write ? height - 1 - row : row) * width * comp + col * comp;
+ float r, g, b;
+ if (row >= height)
+ {
+ p -= width * comp * (row + 1 - height);
+ }
+ if (col >= width)
+ {
+ p -= comp * (col + 1 - width);
+ }
- r = imageData[p+0];
- g = imageData[p+ofsG];
- b = imageData[p+ofsB];
- YDU[pos]=+0.29900f*r+0.58700f*g+0.11400f*b-128;
- UDU[pos]=-0.16874f*r-0.33126f*g+0.50000f*b;
- VDU[pos]=+0.50000f*r-0.41869f*g-0.08131f*b;
- }
+ r = imageData[p + 0];
+ g = imageData[p + ofsG];
+ b = imageData[p + ofsB];
+ YDU[pos] = +0.29900f * r + 0.58700f * g + 0.11400f * b - 128;
+ UDU[pos] = -0.16874f * r - 0.33126f * g + 0.50000f * b;
+ VDU[pos] = +0.50000f * r - 0.41869f * g - 0.08131f * b;
+ }
+ }
+
+ DCY = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, YDU, fdtbl_Y, DCY, YDC_HT, YAC_HT);
+ DCU = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, UDU, fdtbl_UV, DCU, UVDC_HT, UVAC_HT);
+ DCV = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, VDU, fdtbl_UV, DCV, UVDC_HT, UVAC_HT);
}
+ }
- DCY = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, YDU, fdtbl_Y, DCY, YDC_HT, YAC_HT);
- DCU = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, UDU, fdtbl_UV, DCU, UVDC_HT, UVAC_HT);
- DCV = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, VDU, fdtbl_UV, DCV, UVDC_HT, UVAC_HT);
- }
- }
+ // Do the bit alignment of the EOI marker
+ stbiw__jpg_writeBits(s, &bitBuf, &bitCnt, fillBits);
+ }
- // Do the bit alignment of the EOI marker
- stbiw__jpg_writeBits(s, &bitBuf, &bitCnt, fillBits);
- }
+ // EOI
+ stbiw__putc(s, 0xFF);
+ stbiw__putc(s, 0xD9);
- // EOI
- stbiw__putc(s, 0xFF);
- stbiw__putc(s, 0xD9);
-
- return 1;
+ return 1;
}
STBIWDEF int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality)
{
- stbi__write_context s;
- stbi__start_write_callbacks(&s, func, context);
- return stbi_write_jpg_core(&s, x, y, comp, (void *) data, quality);
+ stbi__write_context s;
+ stbi__start_write_callbacks(&s, func, context);
+ return stbi_write_jpg_core(&s, x, y, comp, (void *)data, quality);
}
#ifndef STBI_WRITE_NO_STDIO
STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality)
{
- stbi__write_context s;
- if (stbi__start_write_file(&s,filename)) {
- int r = stbi_write_jpg_core(&s, x, y, comp, data, quality);
- stbi__end_write_file(&s);
- return r;
- } else
- return 0;
+ stbi__write_context s;
+ if (stbi__start_write_file(&s, filename))
+ {
+ int r = stbi_write_jpg_core(&s, x, y, comp, data, quality);
+ stbi__end_write_file(&s);
+ return r;
+ }
+ else
+ return 0;
}
#endif
diff --git a/src/decomp/tools/utils.c b/src/decomp/tools/utils.c
index 3ba6e3e..8c35e5b 100644
--- a/src/decomp/tools/utils.c
+++ b/src/decomp/tools/utils.c
@@ -6,11 +6,11 @@
#include
#include
#if defined(_MSC_VER) || defined(__MINGW32__)
- #include
- #include
+#include
+#include
#else
- #include
- #include
+#include
+#include
#endif
#include "utils.h"
@@ -20,257 +20,289 @@ int g_verbosity = 0;
int read_s16_be(unsigned char *buf)
{
- unsigned tmp = read_u16_be(buf);
- int ret;
- if (tmp > 0x7FFF) {
- ret = -((int)0x10000 - (int)tmp);
- } else {
- ret = (int)tmp;
- }
- return ret;
+ unsigned tmp = read_u16_be(buf);
+ int ret;
+ if (tmp > 0x7FFF)
+ {
+ ret = -(0x10000 - (int)tmp);
+ }
+ else
+ {
+ ret = (int)tmp;
+ }
+ return ret;
}
float read_f32_be(unsigned char *buf)
{
- union {uint32_t i; float f;} ret;
- ret.i = read_u32_be(buf);
- return ret.f;
+ union
+ {
+ uint32_t i;
+ float f;
+ } ret;
+ ret.i = read_u32_be(buf);
+ return ret.f;
}
int is_power2(unsigned int val)
{
- while (((val & 1) == 0) && (val > 1)) {
- val >>= 1;
- }
- return (val == 1);
+ while ((val & 1) == 0 && val > 1)
+ {
+ val >>= 1;
+ }
+ return val == 1;
}
void fprint_hex(FILE *fp, const unsigned char *buf, int length)
{
- int i;
- for (i = 0; i < length; i++) {
- fprint_byte(fp, buf[i]);
- fputc(' ', fp);
- }
+ int i;
+ for (i = 0; i < length; i++)
+ {
+ fprint_byte(fp, buf[i]);
+ fputc(' ', fp);
+ }
}
void fprint_hex_source(FILE *fp, const unsigned char *buf, int length)
{
- int i;
- for (i = 0; i < length; i++) {
- if (i > 0) fputs(", ", fp);
- fputs("0x", fp);
- fprint_byte(fp, buf[i]);
- }
+ int i;
+ for (i = 0; i < length; i++)
+ {
+ if (i > 0) fputs(", ", fp);
+ fputs("0x", fp);
+ fprint_byte(fp, buf[i]);
+ }
}
void print_hex(const unsigned char *buf, int length)
{
- fprint_hex(stdout, buf, length);
+ fprint_hex(stdout, buf, length);
}
void swap_bytes(unsigned char *data, long length)
{
- long i;
- unsigned char tmp;
- for (i = 0; i < length; i += 2) {
- tmp = data[i];
- data[i] = data[i+1];
- data[i+1] = tmp;
- }
+ long i;
+ unsigned char tmp;
+ for (i = 0; i < length; i += 2)
+ {
+ tmp = data[i];
+ data[i] = data[i + 1];
+ data[i + 1] = tmp;
+ }
}
void reverse_endian(unsigned char *data, long length)
{
- long i;
- unsigned char tmp;
- for (i = 0; i < length; i += 4) {
- tmp = data[i];
- data[i] = data[i+3];
- data[i+3] = tmp;
- tmp = data[i+1];
- data[i+1] = data[i+2];
- data[i+2] = tmp;
- }
+ long i;
+ unsigned char tmp;
+ for (i = 0; i < length; i += 4)
+ {
+ tmp = data[i];
+ data[i] = data[i + 3];
+ data[i + 3] = tmp;
+ tmp = data[i + 1];
+ data[i + 1] = data[i + 2];
+ data[i + 2] = tmp;
+ }
}
long filesize(const char *filename)
{
- struct stat st;
+ struct stat st;
- if (stat(filename, &st) == 0) {
- return st.st_size;
- }
+ if (stat(filename, &st) == 0)
+ {
+ return st.st_size;
+ }
- return -1;
+ return -1;
}
void touch_file(const char *filename)
{
- int fd;
- //fd = open(filename, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666);
- fd = open(filename, O_WRONLY|O_CREAT, 0666);
- if (fd >= 0) {
- utime(filename, NULL);
- close(fd);
- }
+ int fd;
+ //fd = open(filename, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666);
+ fd = open(filename, O_WRONLY | O_CREAT, 0666);
+ if (fd >= 0)
+ {
+ utime(filename, NULL);
+ close(fd);
+ }
}
long read_file(const char *file_name, unsigned char **data)
{
- FILE *in;
- unsigned char *in_buf = NULL;
- long file_size;
- long bytes_read;
- in = fopen(file_name, "rb");
- if (in == NULL) {
- return -1;
- }
+ FILE *in;
+ unsigned char *in_buf = NULL;
+ long file_size;
+ long bytes_read;
+ in = fopen(file_name, "rb");
+ if (in == NULL)
+ {
+ return -1;
+ }
- // allocate buffer to read from offset to end of file
- fseek(in, 0, SEEK_END);
- file_size = ftell(in);
+ // allocate buffer to read from offset to end of file
+ fseek(in, 0, SEEK_END);
+ file_size = ftell(in);
- // sanity check
- if (file_size > 256*MB) {
- return -2;
- }
+ // sanity check
+ if (file_size > 256 * MB)
+ {
+ return -2;
+ }
- in_buf = malloc(file_size);
- fseek(in, 0, SEEK_SET);
+ in_buf = malloc(file_size);
+ fseek(in, 0, SEEK_SET);
- // read bytes
- bytes_read = fread(in_buf, 1, file_size, in);
- if (bytes_read != file_size) {
- return -3;
- }
+ // read bytes
+ bytes_read = fread(in_buf, 1, file_size, in);
+ if (bytes_read != file_size)
+ {
+ return -3;
+ }
- fclose(in);
- *data = in_buf;
- return bytes_read;
+ fclose(in);
+ *data = in_buf;
+ return bytes_read;
}
long write_file(const char *file_name, unsigned char *data, long length)
{
- FILE *out;
- long bytes_written;
- // open output file
- out = fopen(file_name, "wb");
- if (out == NULL) {
- perror(file_name);
- return -1;
- }
- bytes_written = fwrite(data, 1, length, out);
- fclose(out);
- return bytes_written;
+ FILE *out;
+ long bytes_written;
+ // open output file
+ out = fopen(file_name, "wb");
+ if (out == NULL)
+ {
+ perror(file_name);
+ return -1;
+ }
+ bytes_written = fwrite(data, 1, length, out);
+ fclose(out);
+ return bytes_written;
}
void generate_filename(const char *in_name, char *out_name, char *extension)
{
- char tmp_name[FILENAME_MAX];
- int len;
- int i;
- strcpy(tmp_name, in_name);
- len = strlen(tmp_name);
- for (i = len - 1; i > 0; i--) {
- if (tmp_name[i] == '.') {
- break;
- }
- }
- if (i <= 0) {
- i = len;
- }
- tmp_name[i] = '\0';
- sprintf(out_name, "%s.%s", tmp_name, extension);
+ char tmp_name[FILENAME_MAX];
+ int len;
+ int i;
+ strcpy(tmp_name, in_name);
+ len = strlen(tmp_name);
+ for (i = len - 1; i > 0; i--)
+ {
+ if (tmp_name[i] == '.')
+ {
+ break;
+ }
+ }
+ if (i <= 0)
+ {
+ i = len;
+ }
+ tmp_name[i] = '\0';
+ sprintf(out_name, "%s.%s", tmp_name, extension);
}
char *basename(const char *name)
{
- const char *base = name;
- while (*name) {
- if (*name++ == '/') {
- base = name;
- }
- }
- return (char *)base;
+ const char *base = name;
+ while (*name)
+ {
+ if (*name++ == '/')
+ {
+ base = name;
+ }
+ }
+ return (char *)base;
}
void make_dir(const char *dir_name)
{
- struct stat st = {0};
- if (stat(dir_name, &st) == -1) {
- mkdir(dir_name, 0755);
- }
+ struct stat st = {0};
+ if (stat(dir_name, &st) == -1)
+ {
+ mkdir(dir_name, 0755);
+ }
}
long copy_file(const char *src_name, const char *dst_name)
{
- unsigned char *buf;
- long bytes_written;
- long bytes_read;
+ unsigned char *buf;
+ long bytes_written;
+ long bytes_read;
- bytes_read = read_file(src_name, &buf);
+ bytes_read = read_file(src_name, &buf);
- if (bytes_read > 0) {
- bytes_written = write_file(dst_name, buf, bytes_read);
- if (bytes_written != bytes_read) {
- bytes_read = -1;
- }
- free(buf);
- }
+ if (bytes_read > 0)
+ {
+ bytes_written = write_file(dst_name, buf, bytes_read);
+ if (bytes_written != bytes_read)
+ {
+ bytes_read = -1;
+ }
+ free(buf);
+ }
- return bytes_read;
+ return bytes_read;
}
void dir_list_ext(const char *dir, const char *extension, dir_list *list)
{
- char *pool;
- char *pool_ptr;
- struct dirent *entry;
- DIR *dfd;
- int idx;
+ char *pool;
+ char *pool_ptr;
+ struct dirent *entry;
+ DIR *dfd;
+ int idx;
- dfd = opendir(dir);
- if (dfd == NULL) {
- ERROR("Can't open '%s'\n", dir);
- exit(1);
- }
+ dfd = opendir(dir);
+ if (dfd == NULL)
+ {
+ ERROR("Can't open '%s'\n", dir);
+ exit(1);
+ }
- pool = malloc(FILENAME_MAX * MAX_DIR_FILES);
- pool_ptr = pool;
+ pool = malloc(FILENAME_MAX * MAX_DIR_FILES);
+ pool_ptr = pool;
- idx = 0;
- while ((entry = readdir(dfd)) != NULL && idx < MAX_DIR_FILES) {
- if (!extension || str_ends_with(entry->d_name, extension)) {
- sprintf(pool_ptr, "%s/%s", dir, entry->d_name);
- list->files[idx] = pool_ptr;
- pool_ptr += strlen(pool_ptr) + 1;
- idx++;
- }
- }
- list->count = idx;
+ idx = 0;
+ while ((entry = readdir(dfd)) != NULL && idx < MAX_DIR_FILES)
+ {
+ if (!extension || str_ends_with(entry->d_name, extension))
+ {
+ sprintf(pool_ptr, "%s/%s", dir, entry->d_name);
+ list->files[idx] = pool_ptr;
+ pool_ptr += strlen(pool_ptr) + 1;
+ idx++;
+ }
+ }
+ list->count = idx;
- closedir(dfd);
+ closedir(dfd);
}
void dir_list_free(dir_list *list)
{
- // assume first entry in array is allocated
- if (list->files[0]) {
- free(list->files[0]);
- list->files[0] = NULL;
- }
+ // assume first entry in array is allocated
+ if (list->files[0])
+ {
+ free(list->files[0]);
+ list->files[0] = NULL;
+ }
}
int str_ends_with(const char *str, const char *suffix)
{
- if (!str || !suffix) {
- return 0;
- }
- size_t len_str = strlen(str);
- size_t len_suffix = strlen(suffix);
- if (len_suffix > len_str) {
- return 0;
- }
- return (0 == strncmp(str + len_str - len_suffix, suffix, len_suffix));
+ if (!str || !suffix)
+ {
+ return 0;
+ }
+ size_t len_str = strlen(str);
+ size_t len_suffix = strlen(suffix);
+ if (len_suffix > len_str)
+ {
+ return 0;
+ }
+ return 0 == strncmp(str + len_str - len_suffix, suffix, len_suffix);
}
diff --git a/src/decomp/tools/utils.h b/src/decomp/tools/utils.h
index f038653..9101a37 100644
--- a/src/decomp/tools/utils.h
+++ b/src/decomp/tools/utils.h
@@ -7,9 +7,9 @@
// printing size_t varies by compiler
#if defined(_MSC_VER) || defined(__MINGW32__)
- #define SIZE_T_FORMAT "%Iu"
+#define SIZE_T_FORMAT "%Iu"
#else
- #define SIZE_T_FORMAT "%zu"
+#define SIZE_T_FORMAT "%zu"
#endif
#define KB 1024
@@ -50,20 +50,21 @@
// Windows compatibility
#if defined(_MSC_VER) || defined(__MINGW32__)
- #include
- #define mkdir(DIR_, PERM_) _mkdir(DIR_)
- #ifndef strcasecmp
- #define strcasecmp(A, B) stricmp(A, B)
- #endif
+#include
+#define mkdir(DIR_, PERM_) _mkdir(DIR_)
+#ifndef strcasecmp
+#define strcasecmp(A, B) stricmp(A, B)
+#endif
#endif
// typedefs
#define MAX_DIR_FILES 128
+
typedef struct
{
- char *files[MAX_DIR_FILES];
- int count;
+ char *files[MAX_DIR_FILES];
+ int count;
} dir_list;
// global verbosity setting
@@ -90,7 +91,9 @@ int is_power2(unsigned int val);
// buf: buffer to read bytes from
// length: length of buffer to print
void fprint_hex(FILE *fp, const unsigned char *buf, int length);
+
void fprint_hex_source(FILE *fp, const unsigned char *buf, int length);
+
void print_hex(const unsigned char *buf, int length);
// perform byteswapping to convert from v64 to z64 ordering
diff --git a/src/fake_interaction.c b/src/fake_interaction.c
index 606d990..26992f4 100644
--- a/src/fake_interaction.c
+++ b/src/fake_interaction.c
@@ -39,108 +39,126 @@
#define sInvulnerable (g_state->msInvulnerable)
static u32 sForwardKnockbackActions[][3] = {
- { ACT_SOFT_FORWARD_GROUND_KB, ACT_FORWARD_GROUND_KB, ACT_HARD_FORWARD_GROUND_KB },
- { ACT_FORWARD_AIR_KB, ACT_FORWARD_AIR_KB, ACT_HARD_FORWARD_AIR_KB },
- { ACT_FORWARD_WATER_KB, ACT_FORWARD_WATER_KB, ACT_FORWARD_WATER_KB },
+ {ACT_SOFT_FORWARD_GROUND_KB, ACT_FORWARD_GROUND_KB, ACT_HARD_FORWARD_GROUND_KB},
+ {ACT_FORWARD_AIR_KB, ACT_FORWARD_AIR_KB, ACT_HARD_FORWARD_AIR_KB},
+ {ACT_FORWARD_WATER_KB, ACT_FORWARD_WATER_KB, ACT_FORWARD_WATER_KB},
};
static u32 sBackwardKnockbackActions[][3] = {
- { ACT_SOFT_BACKWARD_GROUND_KB, ACT_BACKWARD_GROUND_KB, ACT_HARD_BACKWARD_GROUND_KB },
- { ACT_BACKWARD_AIR_KB, ACT_BACKWARD_AIR_KB, ACT_HARD_BACKWARD_AIR_KB },
- { ACT_BACKWARD_WATER_KB, ACT_BACKWARD_WATER_KB, ACT_BACKWARD_WATER_KB },
+ {ACT_SOFT_BACKWARD_GROUND_KB, ACT_BACKWARD_GROUND_KB, ACT_HARD_BACKWARD_GROUND_KB},
+ {ACT_BACKWARD_AIR_KB, ACT_BACKWARD_AIR_KB, ACT_HARD_BACKWARD_AIR_KB},
+ {ACT_BACKWARD_WATER_KB, ACT_BACKWARD_WATER_KB, ACT_BACKWARD_WATER_KB},
};
-uint32_t fake_damage_knock_back(struct MarioState *m, uint32_t damage,uint32_t interactionSubtype,float xSrc,float ySrc,float zSrc) {
-
- if (!sInvulnerable && !(m->flags & MARIO_VANISH_CAP)
- && !(interactionSubtype & INT_SUBTYPE_DELAY_INVINCIBILITY)) {
+uint32_t fake_damage_knock_back(struct MarioState *m, uint32_t damage, uint32_t interactionSubtype, float xSrc, float ySrc, float zSrc)
+{
+ if (!sInvulnerable && !(m->flags & MARIO_VANISH_CAP) && !(interactionSubtype & INT_SUBTYPE_DELAY_INVINCIBILITY))
+ {
//o->oInteractStatus = INT_STATUS_INTERACTED | INT_STATUS_ATTACKED_MARIO;
//m->interactObj = o;
// calculate damage, substitute for take_damage_from_interact_object
- if (!(m->flags & MARIO_CAP_ON_HEAD)) {
+ if (!(m->flags & MARIO_CAP_ON_HEAD))
+ {
damage += (damage + 1) / 2;
}
- if (m->flags & MARIO_METAL_CAP) {
+ if (m->flags & MARIO_METAL_CAP)
+ {
damage = 0;
}
m->hurtCounter += 4 * damage; // apply hurt counter
- if (interactionSubtype & INT_SUBTYPE_BIG_KNOCKBACK) {
+ if (interactionSubtype & INT_SUBTYPE_BIG_KNOCKBACK)
+ {
m->forwardVel = 40.0f;
}
- if (damage > 0) {
+ if (damage > 0)
+ {
play_sound(SOUND_MARIO_ATTACKED, m->marioObj->header.gfx.cameraToObject);
}
//update_mario_sound_and_camera(m);
- return drop_and_set_mario_action(m, fake_determine_knockback_action(m, damage,xSrc,ySrc,zSrc),
- damage);
+ return drop_and_set_mario_action(m, fake_determine_knockback_action(m, damage, xSrc, ySrc, zSrc), damage);
}
return FALSE;
}
-s16 fake_mario_obj_angle_to_object(struct MarioState *m, float xSrc,float zSrc) {
+s16 fake_mario_obj_angle_to_object(struct MarioState *m, float xSrc, float zSrc)
+{
f32 dx = xSrc - m->pos[0];
f32 dz = zSrc - m->pos[2];
return atan2s(dz, dx);
}
-u32 fake_determine_knockback_action(struct MarioState *m, s32 damage,float xSrc,float ySrc,float zSrc) {
+u32 fake_determine_knockback_action(struct MarioState *m, s32 damage, float xSrc, float ySrc, float zSrc)
+{
u32 bonkAction;
s16 terrainIndex = 0; // 1 = air, 2 = water, 0 = default
s16 strengthIndex = 0;
- s16 angleToObject = fake_mario_obj_angle_to_object(m, xSrc,zSrc);
+ s16 angleToObject = fake_mario_obj_angle_to_object(m, xSrc, zSrc);
s16 facingDYaw = angleToObject - m->faceAngle[1];
s16 remainingHealth = m->health - 0x40 * m->hurtCounter;
- if (m->action & (ACT_FLAG_SWIMMING | ACT_FLAG_METAL_WATER)) {
+ if (m->action & (ACT_FLAG_SWIMMING | ACT_FLAG_METAL_WATER))
+ {
terrainIndex = 2;
- } else if (m->action & (ACT_FLAG_AIR | ACT_FLAG_ON_POLE | ACT_FLAG_HANGING)) {
+ }
+ else if (m->action & (ACT_FLAG_AIR | ACT_FLAG_ON_POLE | ACT_FLAG_HANGING))
+ {
terrainIndex = 1;
}
- if (remainingHealth < 0x100) {
+ if (remainingHealth < 0x100 || damage >= 2)
+ {
strengthIndex = 2;
- } else if (damage >= 4) {
- strengthIndex = 2;
- } else if (damage >= 2) {
- strengthIndex = 1;
}
m->faceAngle[1] = angleToObject;
- if (terrainIndex == 2) {
- if (m->forwardVel < 28.0f) {
+ if (terrainIndex == 2)
+ {
+ if (m->forwardVel < 28.0f)
+ {
mario_set_forward_vel(m, 28.0f);
}
- if (m->pos[1] >= ySrc) {
- if (m->vel[1] < 20.0f) {
+ if (m->pos[1] >= ySrc)
+ {
+ if (m->vel[1] < 20.0f)
+ {
m->vel[1] = 20.0f;
}
- } else {
- if (m->vel[1] > 0.0f) {
+ }
+ else
+ {
+ if (m->vel[1] > 0.0f)
+ {
m->vel[1] = 0.0f;
}
}
- } else {
- if (m->forwardVel < 16.0f) {
+ }
+ else
+ {
+ if (m->forwardVel < 16.0f)
+ {
mario_set_forward_vel(m, 16.0f);
}
}
- if (-0x4000 <= facingDYaw && facingDYaw <= 0x4000) {
+ if (-0x4000 <= facingDYaw && facingDYaw <= 0x4000)
+ {
m->forwardVel *= -1.0f;
bonkAction = sBackwardKnockbackActions[terrainIndex][strengthIndex];
- } else {
+ }
+ else
+ {
m->faceAngle[1] += 0x8000;
bonkAction = sForwardKnockbackActions[terrainIndex][strengthIndex];
}
@@ -148,22 +166,29 @@ u32 fake_determine_knockback_action(struct MarioState *m, s32 damage,float xSrc,
return bonkAction;
}
-s16 fake_mario_obj_angle_to_pos(struct MarioState *m, float x, float z) {
+s16 fake_mario_obj_angle_to_pos(struct MarioState *m, float x, float z)
+{
f32 dx = x - m->pos[0];
f32 dz = z - m->pos[2];
return atan2s(dz, dx);
}
-void fake_bounce_back_from_attack(struct MarioState *m, u32 interaction) {
- if (interaction & (INT_PUNCH | INT_KICK | INT_TRIP)) {
- if (m->action == ACT_PUNCHING) {
+void fake_bounce_back_from_attack(struct MarioState *m, u32 interaction)
+{
+ if (interaction & (INT_PUNCH | INT_KICK | INT_TRIP))
+ {
+ if (m->action == ACT_PUNCHING)
+ {
m->action = ACT_MOVE_PUNCHING;
}
- if (m->action & ACT_FLAG_AIR) {
+ if (m->action & ACT_FLAG_AIR)
+ {
mario_set_forward_vel(m, -16.0f);
- } else {
+ }
+ else
+ {
mario_set_forward_vel(m, -48.0f);
}
@@ -171,55 +196,71 @@ void fake_bounce_back_from_attack(struct MarioState *m, u32 interaction) {
m->particleFlags |= PARTICLE_TRIANGLE;
}
- if (interaction & (INT_PUNCH | INT_KICK | INT_TRIP | INT_FAST_ATTACK_OR_SHELL)) {
+ if (interaction & (INT_PUNCH | INT_KICK | INT_TRIP | INT_FAST_ATTACK_OR_SHELL))
+ {
play_sound(SOUND_ACTION_HIT_2, m->marioObj->header.gfx.cameraToObject);
}
}
-u32 fake_determine_interaction(struct MarioState *m, float x, float y, float z) {
+u32 fake_determine_interaction(struct MarioState *m, float x, float y, float z)
+{
u32 interaction = 0;
u32 action = m->action;
s16 dYawToObject = fake_mario_obj_angle_to_pos(m, x, z) - m->faceAngle[1];
- if (action & ACT_FLAG_ATTACKING) {
- if (action == ACT_PUNCHING || action == ACT_MOVE_PUNCHING || action == ACT_JUMP_KICK) {
-
-
- if (m->flags & MARIO_PUNCHING) {
+ if (action & ACT_FLAG_ATTACKING)
+ {
+ if (action == ACT_PUNCHING || action == ACT_MOVE_PUNCHING || action == ACT_JUMP_KICK)
+ {
+ if (m->flags & MARIO_PUNCHING)
+ {
// 120 degrees total, or 60 each way
- if (-0x2AAA <= dYawToObject && dYawToObject <= 0x2AAA) {
+ if (-0x2AAA <= dYawToObject && dYawToObject <= 0x2AAA)
+ {
interaction = INT_PUNCH;
}
}
- if (m->flags & MARIO_KICKING) {
+ if (m->flags & MARIO_KICKING)
+ {
// 120 degrees total, or 60 each way
- if (-0x2AAA <= dYawToObject && dYawToObject <= 0x2AAA) {
+ if (-0x2AAA <= dYawToObject && dYawToObject <= 0x2AAA)
+ {
interaction = INT_KICK;
}
}
- if (m->flags & MARIO_TRIPPING) {
+ if (m->flags & MARIO_TRIPPING)
+ {
// 180 degrees total, or 90 each way
- if (-0x4000 <= dYawToObject && dYawToObject <= 0x4000) {
+ if (-0x4000 <= dYawToObject && dYawToObject <= 0x4000)
+ {
interaction = INT_TRIP;
}
}
- } else if (action == ACT_GROUND_POUND || action == ACT_TWIRLING) {
- if (m->vel[1] < 0.0f) {
+ }
+ else if (action == ACT_GROUND_POUND || action == ACT_TWIRLING)
+ {
+ if (m->vel[1] < 0.0f)
+ {
interaction = INT_GROUND_POUND_OR_TWIRL;
}
- } else if (action == ACT_GROUND_POUND_LAND || action == ACT_TWIRL_LAND) {
+ }
+ else if (action == ACT_GROUND_POUND_LAND || action == ACT_TWIRL_LAND)
+ {
// Neither ground pounding nor twirling change Mario's vertical speed on landing.,
// so the speed check is nearly always true (perhaps not if you land while going upwards?)
// Additionally, actionState it set on each first thing in their action, so this is
// only true prior to the very first frame (i.e. active 1 frame prior to it run).
- if (m->vel[1] < 0.0f && m->actionState == 0) {
+ if (m->vel[1] < 0.0f && m->actionState == 0)
+ {
interaction = INT_GROUND_POUND_OR_TWIRL;
}
- } else if (action == ACT_SLIDE_KICK || action == ACT_SLIDE_KICK_SLIDE) {
+ }
+ else if (action == ACT_SLIDE_KICK || action == ACT_SLIDE_KICK_SLIDE)
+ {
interaction = INT_SLIDE_KICK;
- } else if (action & ACT_FLAG_RIDING_SHELL) {
- interaction = INT_FAST_ATTACK_OR_SHELL;
- } else if (m->forwardVel <= -26.0f || 26.0f <= m->forwardVel) {
+ }
+ else if (action & ACT_FLAG_RIDING_SHELL || m->forwardVel <= -26.0f || 26.0f <= m->forwardVel)
+ {
interaction = INT_FAST_ATTACK_OR_SHELL;
}
}
@@ -227,13 +268,19 @@ u32 fake_determine_interaction(struct MarioState *m, float x, float y, float z)
// Prior to this, the interaction type could be overwritten. This requires, however,
// that the interaction not be set prior. This specifically overrides turning a ground
// pound into just a bounce.
- if (interaction == 0 && (action & ACT_FLAG_AIR)) {
- if (m->vel[1] < 0.0f) {
- if (m->pos[1] > y) {
+ if (interaction == 0 && action & ACT_FLAG_AIR)
+ {
+ if (m->vel[1] < 0.0f)
+ {
+ if (m->pos[1] > y)
+ {
interaction = INT_HIT_FROM_ABOVE;
}
- } else {
- if (m->pos[1] < y) {
+ }
+ else
+ {
+ if (m->pos[1] < y)
+ {
interaction = INT_HIT_FROM_BELOW;
}
}
@@ -242,7 +289,8 @@ u32 fake_determine_interaction(struct MarioState *m, float x, float y, float z)
return interaction;
}
-void fake_bounce_off_object(struct MarioState *m, float x, float y, float z, float hitboxHeight, f32 velY) {
+void fake_bounce_off_object(struct MarioState *m, float x, float y, float z, float hitboxHeight, f32 velY)
+{
//m->pos[1] = y + hitboxHeight;
m->vel[1] = velY;
@@ -251,51 +299,67 @@ void fake_bounce_off_object(struct MarioState *m, float x, float y, float z, flo
play_sound(SOUND_ACTION_BOUNCE_OFF_OBJECT, m->marioObj->header.gfx.cameraToObject);
}
-u32 fake_interact_hit_from_below(struct MarioState *m, float x, float y, float z, float hitboxHeight) {
-
+u32 fake_interact_hit_from_below(struct MarioState *m, float x, float y, float z, float hitboxHeight)
+{
u32 interaction;
- if (m->flags & MARIO_METAL_CAP) {
+ if (m->flags & MARIO_METAL_CAP)
+ {
interaction = INT_FAST_ATTACK_OR_SHELL;
- } else {
+ }
+ else
+ {
interaction = fake_determine_interaction(m, x, y, z);
}
- if (interaction & INT_ANY_ATTACK) {
+ if (interaction & INT_ANY_ATTACK)
+ {
fake_bounce_back_from_attack(m, interaction);
- if (interaction & INT_HIT_FROM_BELOW) {
+ if (interaction & INT_HIT_FROM_BELOW)
+ {
m->vel[1] = 0.0f;
}
- if (interaction & INT_HIT_FROM_ABOVE) {
+ if (interaction & INT_HIT_FROM_ABOVE)
+ {
fake_bounce_off_object(m, x, y, z, hitboxHeight, 30.0f);
}
return TRUE;
- } else/* if (fake_damage_knock_back(m, 0, 0, x, y, z))*/ {
+ }
+ else /* if (fake_damage_knock_back(m, 0, 0, x, y, z))*/
+ {
return FALSE;
}
return FALSE;
}
-u32 fake_interact_bounce_top(struct MarioState *m, float x, float y, float z, float hitboxHeight) {
+u32 fake_interact_bounce_top(struct MarioState *m, float x, float y, float z, float hitboxHeight)
+{
u32 interaction;
- if (m->flags & MARIO_METAL_CAP) {
+ if (m->flags & MARIO_METAL_CAP)
+ {
interaction = INT_FAST_ATTACK_OR_SHELL;
- } else {
+ }
+ else
+ {
interaction = fake_determine_interaction(m, x, y, z);
}
- if (interaction & INT_ATTACK_NOT_FROM_BELOW) {
+ if (interaction & INT_ATTACK_NOT_FROM_BELOW)
+ {
fake_bounce_back_from_attack(m, interaction);
- if (interaction & INT_HIT_FROM_ABOVE) {
+ if (interaction & INT_HIT_FROM_ABOVE)
+ {
fake_bounce_off_object(m, x, y, z, hitboxHeight, 30.0f);
}
return TRUE;
- } else/* if (fake_damage_knock_back(m, 0, 0, x, y, z))*/ {
+ }
+ else /* if (fake_damage_knock_back(m, 0, 0, x, y, z))*/
+ {
return FALSE;
}
return FALSE;
-}
\ No newline at end of file
+}
diff --git a/src/fake_interaction.h b/src/fake_interaction.h
index a6277ee..ae80b64 100644
--- a/src/fake_interaction.h
+++ b/src/fake_interaction.h
@@ -1,8 +1,12 @@
#pragma once
#include "decomp/include/types.h"
-u32 fake_determine_knockback_action(struct MarioState *m, s32 damage,float xSrc,float ySrc,float zSrc);
-s16 fake_mario_obj_angle_to_object(struct MarioState *m, float xSrc,float zSrc);
-uint32_t fake_damage_knock_back(struct MarioState *m, uint32_t damage,uint32_t interactionSubtype,float xSrc,float ySrc,float zSrc);
+u32 fake_determine_knockback_action(struct MarioState *m, s32 damage, float xSrc, float ySrc, float zSrc);
+
+s16 fake_mario_obj_angle_to_object(struct MarioState *m, float xSrc, float zSrc);
+
+uint32_t fake_damage_knock_back(struct MarioState *m, uint32_t damage, uint32_t interactionSubtype, float xSrc, float ySrc, float zSrc);
+
u32 fake_interact_hit_from_below(struct MarioState *m, float x, float y, float z, float hitboxHeight);
+
u32 fake_interact_bounce_top(struct MarioState *m, float x, float y, float z, float hitboxHeight);
\ No newline at end of file
diff --git a/src/gfx_adapter.c b/src/gfx_adapter.c
index ba7fc1d..9cce678 100644
--- a/src/gfx_adapter.c
+++ b/src/gfx_adapter.c
@@ -30,33 +30,32 @@ static void mtxf_mul_vec3f_x(Mat4 mtx, Vec3f b, float w, Vec3f out)
out[2] = b[0] * mtx[0][2] + b[1] * mtx[1][2] + b[2] * mtx[2][2] + w * mtx[3][2];
}
-static void convert_uv_to_atlas( float *atlas_uv_out, short tc[] )
+static void convert_uv_to_atlas(float *atlas_uv_out, short tc[])
{
- float u = (float)((tc[0] * s_scaleS >> 16) - 8*s_uls) / 32.0f / s_texWidth;
- float v = (float)((tc[1] * s_scaleT >> 16) - 8*s_ult) / 32.0f / s_texHeight;
+ float u = (float)((tc[0] * s_scaleS >> 16) - 8 * s_uls) / 32.0f / s_texWidth;
+ float v = (float)((tc[1] * s_scaleT >> 16) - 8 * s_ult) / 32.0f / s_texHeight;
atlas_uv_out[0] = u * s_texWidth / 64.0f / (float)NUM_USED_TEXTURES + (float)s_textureIndex / (float)NUM_USED_TEXTURES;
atlas_uv_out[1] = v * s_texHeight / 64.0f;
}
-static void process_display_list( void *dl )
+static void process_display_list(void *dl)
{
- intptr_t *ptr = (intptr_t *)dl;
+ intptr_t *ptr = dl;
Vtx *vdata = NULL;
- for( ;; )
+ for (;;)
{
- switch( *ptr++ )
+ switch (*ptr++)
{
- case GFXCMD_VertexData:
+ case GFXCMD_VertexData:
{
UNUSED intptr_t v = *ptr++;
UNUSED intptr_t n = *ptr++;
UNUSED intptr_t v0 = *ptr++;
- vdata = (Vtx*)v;
+ vdata = (Vtx *)v;
break;
}
-
case GFXCMD_Triangle:
{
intptr_t v00 = *ptr++;
@@ -67,33 +66,33 @@ static void process_display_list( void *dl )
float x0 = vdata[v00].v.ob[0], y0 = vdata[v00].v.ob[1], z0 = vdata[v00].v.ob[2];
float x1 = vdata[v01].v.ob[0], y1 = vdata[v01].v.ob[1], z1 = vdata[v01].v.ob[2];
float x2 = vdata[v02].v.ob[0], y2 = vdata[v02].v.ob[1], z2 = vdata[v02].v.ob[2];
- Vec3f p0 = { (float)x0, (float)y0, (float)z0 };
- Vec3f p1 = { (float)x1, (float)y1, (float)z1 };
- Vec3f p2 = { (float)x2, (float)y2, (float)z2 };
+ Vec3f p0 = {x0, y0, z0};
+ Vec3f p1 = {x1, y1, z1};
+ Vec3f p2 = {x2, y2, z2};
signed char nx0 = vdata[v00].n.n[0], ny0 = vdata[v00].n.n[1], nz0 = vdata[v00].n.n[2];
signed char nx1 = vdata[v01].n.n[0], ny1 = vdata[v01].n.n[1], nz1 = vdata[v01].n.n[2];
signed char nx2 = vdata[v02].n.n[0], ny2 = vdata[v02].n.n[1], nz2 = vdata[v02].n.n[2];
- Vec3f n0 = { ((float)nx0) / 128.0f, ((float)ny0) / 128.0f, ((float)nz0) / 128.0f };
- Vec3f n1 = { ((float)nx1) / 128.0f, ((float)ny1) / 128.0f, ((float)nz1) / 128.0f };
- Vec3f n2 = { ((float)nx2) / 128.0f, ((float)ny2) / 128.0f, ((float)nz2) / 128.0f };
+ Vec3f n0 = {(float)nx0 / 128.0f, (float)ny0 / 128.0f, (float)nz0 / 128.0f};
+ Vec3f n1 = {(float)nx1 / 128.0f, (float)ny1 / 128.0f, (float)nz1 / 128.0f};
+ Vec3f n2 = {(float)nx2 / 128.0f, (float)ny2 / 128.0f, (float)nz2 / 128.0f};
- mtxf_mul_vec3f_x( s_curMatrix, p0, 1.0f, s_trianglePtr );
+ mtxf_mul_vec3f_x(s_curMatrix, p0, 1.0f, s_trianglePtr);
s_trianglePtr += 3;
- mtxf_mul_vec3f_x( s_curMatrix, p1, 1.0f, s_trianglePtr );
+ mtxf_mul_vec3f_x(s_curMatrix, p1, 1.0f, s_trianglePtr);
s_trianglePtr += 3;
- mtxf_mul_vec3f_x( s_curMatrix, p2, 1.0f, s_trianglePtr );
+ mtxf_mul_vec3f_x(s_curMatrix, p2, 1.0f, s_trianglePtr);
s_trianglePtr += 3;
// TODO normals arent correct under non-uniform scale. multiply by inverse/transpose
- mtxf_mul_vec3f_x( s_curMatrix, n0, 0.0f, s_normalPtr );
- vec3f_normalize( s_normalPtr );
+ mtxf_mul_vec3f_x(s_curMatrix, n0, 0.0f, s_normalPtr);
+ vec3f_normalize(s_normalPtr);
s_normalPtr += 3;
- mtxf_mul_vec3f_x( s_curMatrix, n1, 0.0f, s_normalPtr );
- vec3f_normalize( s_normalPtr );
+ mtxf_mul_vec3f_x(s_curMatrix, n1, 0.0f, s_normalPtr);
+ vec3f_normalize(s_normalPtr);
s_normalPtr += 3;
- mtxf_mul_vec3f_x( s_curMatrix, n2, 0.0f, s_normalPtr );
- vec3f_normalize( s_normalPtr );
+ mtxf_mul_vec3f_x(s_curMatrix, n2, 0.0f, s_normalPtr);
+ vec3f_normalize(s_normalPtr);
s_normalPtr += 3;
*s_colorPtr++ = s_curColor[0];
@@ -106,11 +105,14 @@ static void process_display_list( void *dl )
*s_colorPtr++ = s_curColor[1];
*s_colorPtr++ = s_curColor[2];
- if( s_textureOn )
+ if (s_textureOn)
{
- convert_uv_to_atlas( s_uvPtr, vdata[v00].v.tc ); s_uvPtr += 2;
- convert_uv_to_atlas( s_uvPtr, vdata[v01].v.tc ); s_uvPtr += 2;
- convert_uv_to_atlas( s_uvPtr, vdata[v02].v.tc ); s_uvPtr += 2;
+ convert_uv_to_atlas(s_uvPtr, vdata[v00].v.tc);
+ s_uvPtr += 2;
+ convert_uv_to_atlas(s_uvPtr, vdata[v01].v.tc);
+ s_uvPtr += 2;
+ convert_uv_to_atlas(s_uvPtr, vdata[v02].v.tc);
+ s_uvPtr += 2;
}
else
{
@@ -126,23 +128,21 @@ static void process_display_list( void *dl )
break;
}
-
case GFXCMD_Light:
{
intptr_t l = *ptr++;
intptr_t n = *ptr++;
- if( n == 1 )
+ if (n == 1)
{
- Light *data = (Light*)l;
+ Light *data = (Light *)l;
s_curColor[0] = (float)data->l.col[0] / 255.0f;
s_curColor[1] = (float)data->l.col[1] / 255.0f;
s_curColor[2] = (float)data->l.col[2] / 255.0f;
}
-
+
break;
}
-
case GFXCMD_Texture:
{
intptr_t s = *ptr++;
@@ -155,7 +155,6 @@ static void process_display_list( void *dl )
break;
}
-
case GFXCMD_SetTextureImage:
{
intptr_t i = *ptr++;
@@ -166,7 +165,6 @@ static void process_display_list( void *dl )
break;
}
-
case GFXCMD_SetTileSize:
{
intptr_t uls = *ptr++;
@@ -176,37 +174,36 @@ static void process_display_list( void *dl )
s_uls = (uint16_t)uls;
s_ult = (uint16_t)ult;
-
+
break;
}
-
case GFXCMD_SubDisplayList:
{
intptr_t dl = *ptr++;
- process_display_list( (void*)dl );
+ process_display_list((void *)dl);
break;
}
-
case GFXCMD_EndDisplayList:
goto break_top;
}
}
break_top:
- {}
+ {
+ }
}
-void gSPMatrix( void *pkt, Mtx *m, uint8_t flags )
+void gSPMatrix(void *pkt, Mtx *m, uint8_t flags)
{
- guMtxL2F( s_curMatrix, m );
+ guMtxL2F(s_curMatrix, m);
}
-void gSPDisplayList( void *pkt, struct DisplayListNode *dl )
+void gSPDisplayList(void *pkt, struct DisplayListNode *dl)
{
- process_display_list( (void*)dl );
+ process_display_list(dl);
}
-void gfx_adapter_bind_output_buffers( struct SM64MarioGeometryBuffers *outBuffers )
+void gfx_adapter_bind_output_buffers(struct SM64MarioGeometryBuffers *outBuffers)
{
s_outBuffers = outBuffers;
s_trianglePtr = s_outBuffers->position;
@@ -214,4 +211,4 @@ void gfx_adapter_bind_output_buffers( struct SM64MarioGeometryBuffers *outBuffer
s_normalPtr = s_outBuffers->normal;
s_uvPtr = s_outBuffers->uv;
s_outBuffers->numTrianglesUsed = 0;
-}
\ No newline at end of file
+}
diff --git a/src/gfx_adapter.h b/src/gfx_adapter.h
index 5d1ef49..47248ce 100644
--- a/src/gfx_adapter.h
+++ b/src/gfx_adapter.h
@@ -9,7 +9,9 @@
#define gSPClearGeometryMode(pkt, word) ({})
#define gDPFillRectangle(pkt, ulx, uly, lrx, lry) ({})
#define gSPViewport(pkt, v) ({})
-extern void gSPMatrix( void *pkt, Mtx *m, uint8_t flags );
-extern void gSPDisplayList( void *pkt, struct DisplayListNode *dl );
-extern void gfx_adapter_bind_output_buffers( struct SM64MarioGeometryBuffers *outBuffers );
\ No newline at end of file
+extern void gSPMatrix(void *pkt, Mtx *m, uint8_t flags);
+
+extern void gSPDisplayList(void *pkt, struct DisplayListNode *dl);
+
+extern void gfx_adapter_bind_output_buffers(struct SM64MarioGeometryBuffers *outBuffers);
\ No newline at end of file
diff --git a/src/gfx_macros.h b/src/gfx_macros.h
index 3bbe1d0..9ff6e9a 100644
--- a/src/gfx_macros.h
+++ b/src/gfx_macros.h
@@ -6,12 +6,13 @@
/*
* Vertex (set up for use with colors)
*/
-typedef struct {
-#ifndef GBI_FLOATS
+typedef struct
+{
+ #ifndef GBI_FLOATS
short ob[3]; /* x, y, z */
-#else
+ #else
float ob[3]; /* x, y, z */
-#endif
+ #endif
unsigned short flag;
short tc[2]; /* texture coord */
unsigned char cn[4]; /* color & alpha */
@@ -20,25 +21,28 @@ typedef struct {
/*
* Vertex (set up for use with normals)
*/
-typedef struct {
-#ifndef GBI_FLOATS
+typedef struct
+{
+ #ifndef GBI_FLOATS
short ob[3]; /* x, y, z */
-#else
+ #else
float ob[3]; /* x, y, z */
-#endif
+ #endif
unsigned short flag;
short tc[2]; /* texture coord */
signed char n[3]; /* normal */
unsigned char a; /* alpha */
} Vtx_tn;
-typedef union {
+typedef union
+{
Vtx_t v; /* Use this one for colors */
Vtx_tn n; /* Use this one for normals */
long long int force_structure_alignment;
} Vtx;
-typedef struct {
+typedef struct
+{
unsigned char col[3]; /* diffuse light value (rgba) */
char pad1;
unsigned char colc[3]; /* copy of diffuse light value (rgba) */
@@ -47,24 +51,28 @@ typedef struct {
char pad3;
} Light_t;
-typedef struct {
+typedef struct
+{
unsigned char col[3]; /* ambient light value (rgba) */
char pad1;
unsigned char colc[3]; /* copy of ambient light value (rgba) */
char pad2;
} Ambient_t;
-typedef union {
+typedef union
+{
Light_t l;
long long int force_structure_alignment[2];
} Light;
-typedef union {
+typedef union
+{
Ambient_t l;
long long int force_structure_alignment[1];
} Ambient;
-typedef struct {
+typedef struct
+{
Ambient a;
Light l[1];
} Lights1;
diff --git a/src/libsm64.c b/src/libsm64.c
index 74e12c2..2de6b22 100644
--- a/src/libsm64.c
+++ b/src/libsm64.c
@@ -1,5 +1,5 @@
#ifndef SM64_LIB_EXPORT
- #define SM64_LIB_EXPORT
+#define SM64_LIB_EXPORT
#endif
#include "libsm64.h"
@@ -48,15 +48,16 @@ struct MarioInstance
{
struct GlobalState *globalState;
};
-struct ObjPool s_mario_instance_pool = { 0, 0 };
-static void update_button( bool on, u16 button )
+struct ObjPool s_mario_instance_pool = {0, 0};
+
+static void update_button(bool on, u16 button)
{
gController.buttonPressed &= ~button;
- if( on )
+ if (on)
{
- if(( gController.buttonDown & button ) == 0 )
+ if ((gController.buttonDown & button) == 0)
gController.buttonPressed |= button;
gController.buttonDown |= button;
@@ -67,71 +68,73 @@ static void update_button( bool on, u16 button )
}
}
-static struct Area *allocate_area( void )
+static struct Area *allocate_area(void)
{
- struct Area *result = malloc( sizeof( struct Area ));
- memset( result, 0, sizeof( struct Area ));
+ struct Area *result = malloc(sizeof(struct Area));
+ memset(result, 0, sizeof(struct Area));
result->flags = 1;
- result->camera = malloc( sizeof( struct Camera ));
- memset( result->camera, 0, sizeof( struct Camera ));
+ result->camera = malloc(sizeof(struct Camera));
+ memset(result->camera, 0, sizeof(struct Camera));
return result;
}
-static void free_area( struct Area *area )
+static void free_area(struct Area *area)
{
- free( area->camera );
- free( area );
+ free(area->camera);
+ free(area);
}
-typedef void (*SM64DebugPrintFunctionPtr)( const char * );
-SM64_LIB_FN void sm64_register_debug_print_function( SM64DebugPrintFunctionPtr debugPrintFunction )
+typedef void (*SM64DebugPrintFunctionPtr)(const char *);
+
+SM64_LIB_FN void sm64_register_debug_print_function(SM64DebugPrintFunctionPtr debugPrintFunction)
{
g_debug_print_func = debugPrintFunction;
}
-typedef void (*SM64PlaySoundFunctionPtr)( uint32_t soundBits, float *pos );
-SM64_LIB_FN void sm64_register_play_sound_function( SM64PlaySoundFunctionPtr playSoundFunction )
+typedef void (*SM64PlaySoundFunctionPtr)(uint32_t soundBits, float *pos);
+
+SM64_LIB_FN void sm64_register_play_sound_function(SM64PlaySoundFunctionPtr playSoundFunction)
{
g_play_sound_func = playSoundFunction;
}
-SM64_LIB_FN void sm64_global_init( const uint8_t *rom, uint8_t *outTexture )
+SM64_LIB_FN void sm64_global_init(const uint8_t *rom, uint8_t *outTexture)
{
- if( s_init_global )
+ if (s_init_global)
sm64_global_terminate();
s_init_global = true;
- load_mario_textures_from_rom( rom, outTexture );
- load_mario_anims_from_rom( rom );
+ load_mario_textures_from_rom(rom, outTexture);
+ load_mario_anims_from_rom(rom);
memory_init();
}
-SM64_LIB_FN void sm64_global_terminate( void )
+SM64_LIB_FN void sm64_global_terminate(void)
{
- if( !s_init_global ) return;
+ if (!s_init_global) return;
- global_state_bind( NULL );
+ global_state_bind(NULL);
- if( s_init_one_mario )
+ if (s_init_one_mario)
{
- for( int i = 0; i < s_mario_instance_pool.size; ++i )
- if( s_mario_instance_pool.objects[i] != NULL )
- sm64_mario_delete( i );
+ for (int i = 0; i < s_mario_instance_pool.size; ++i)
+ if (s_mario_instance_pool.objects[i] != NULL)
+ sm64_mario_delete(i);
- obj_pool_free_all( &s_mario_instance_pool );
+ obj_pool_free_all(&s_mario_instance_pool);
}
s_init_global = false;
s_init_one_mario = false;
- if( s_mario_geo_pool )
+ if (s_mario_geo_pool)
{
- alloc_only_pool_free( s_mario_geo_pool );
+ alloc_only_pool_free(s_mario_geo_pool);
s_mario_geo_pool = NULL;
}
@@ -140,15 +143,18 @@ SM64_LIB_FN void sm64_global_terminate( void )
memory_terminate();
}
-SM64_LIB_FN void sm64_audio_init( const uint8_t *rom ) {
- load_audio_banks( rom );
+SM64_LIB_FN void sm64_audio_init(const uint8_t *rom)
+{
+ load_audio_banks(rom);
}
#define SAMPLES_HIGH 544
#define SAMPLES_LOW 528
-SM64_LIB_FN uint32_t sm64_audio_tick( uint32_t numQueuedSamples, uint32_t numDesiredSamples, int16_t *audio_buffer ) {
- if ( !g_is_audio_initialized ) {
+SM64_LIB_FN uint32_t sm64_audio_tick(uint32_t numQueuedSamples, uint32_t numDesiredSamples, int16_t *audio_buffer)
+{
+ if (!g_is_audio_initialized)
+ {
DEBUG_PRINT("Attempted to tick audio, but sm64_audio_init() has not been called yet.");
return 0;
}
@@ -158,30 +164,30 @@ SM64_LIB_FN uint32_t sm64_audio_tick( uint32_t numQueuedSamples, uint32_t numDes
u32 num_audio_samples = numQueuedSamples < numDesiredSamples ? SAMPLES_HIGH : SAMPLES_LOW;
for (int i = 0; i < 2; i++)
{
- create_next_audio_buffer( audio_buffer + i * ( 2 * num_audio_samples ), num_audio_samples );
+ create_next_audio_buffer(audio_buffer + i * (2 * num_audio_samples), num_audio_samples);
}
return num_audio_samples;
}
-SM64_LIB_FN void sm64_static_surfaces_load( const struct SM64Surface *surfaceArray, uint32_t numSurfaces )
+SM64_LIB_FN void sm64_static_surfaces_load(const struct SM64Surface *surfaceArray, uint32_t numSurfaces)
{
- surfaces_load_static( surfaceArray, numSurfaces );
+ surfaces_load_static(surfaceArray, numSurfaces);
}
-SM64_LIB_FN int32_t sm64_mario_create( float x, float y, float z )
+SM64_LIB_FN int32_t sm64_mario_create(float x, float y, float z)
{
- int32_t marioIndex = obj_pool_alloc_index( &s_mario_instance_pool, sizeof( struct MarioInstance ));
+ int32_t marioIndex = obj_pool_alloc_index(&s_mario_instance_pool, sizeof(struct MarioInstance));
struct MarioInstance *newInstance = s_mario_instance_pool.objects[marioIndex];
newInstance->globalState = global_state_create();
- global_state_bind( newInstance->globalState );
+ global_state_bind(newInstance->globalState);
- if( !s_init_one_mario )
+ if (!s_init_one_mario)
{
s_init_one_mario = true;
s_mario_geo_pool = alloc_only_pool_init();
- s_mario_graph_node = process_geo_layout( s_mario_geo_pool, mario_geo_ptr );
+ s_mario_graph_node = process_geo_layout(s_mario_geo_pool, mario_geo_ptr);
}
gCurrSaveFileNum = 1;
@@ -206,55 +212,55 @@ SM64_LIB_FN int32_t sm64_mario_create( float x, float y, float z )
init_mario_from_save_file();
- if( init_mario() < 0 )
+ if (init_mario() < 0)
{
- sm64_mario_delete( marioIndex );
+ sm64_mario_delete(marioIndex);
return -1;
}
- set_mario_action( gMarioState, ACT_SPAWN_SPIN_AIRBORNE, 0);
- find_floor( x, y, z, &gMarioState->floor );
+ set_mario_action(gMarioState, ACT_SPAWN_SPIN_AIRBORNE, 0);
+ find_floor(x, y, z, &gMarioState->floor);
return marioIndex;
}
-SM64_LIB_FN void sm64_mario_tick( int32_t marioId, const struct SM64MarioInputs *inputs, struct SM64MarioState *outState, struct SM64MarioGeometryBuffers *outBuffers )
+SM64_LIB_FN void sm64_mario_tick(int32_t marioId, const struct SM64MarioInputs *inputs, struct SM64MarioState *outState, struct SM64MarioGeometryBuffers *outBuffers)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to tick non-existant Mario with ID: %u", marioId);
return;
}
- global_state_bind( ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState );
+ global_state_bind(((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState);
- update_button( inputs->buttonA, A_BUTTON );
- update_button( inputs->buttonB, B_BUTTON );
- update_button( inputs->buttonZ, Z_TRIG );
+ update_button(inputs->buttonA, A_BUTTON);
+ update_button(inputs->buttonB, B_BUTTON);
+ update_button(inputs->buttonZ, Z_TRIG);
gMarioState->marioObj->header.gfx.cameraToObject[0] = 0;
gMarioState->marioObj->header.gfx.cameraToObject[1] = 0;
gMarioState->marioObj->header.gfx.cameraToObject[2] = 0;
- gMarioState->area->camera->yaw = atan2s( inputs->camLookZ, inputs->camLookX );
+ gMarioState->area->camera->yaw = atan2s(inputs->camLookZ, inputs->camLookX);
gController.stickX = -64.0f * inputs->stickX;
gController.stickY = 64.0f * inputs->stickY;
- gController.stickMag = sqrtf( gController.stickX*gController.stickX + gController.stickY*gController.stickY );
+ gController.stickMag = sqrtf(gController.stickX * gController.stickX + gController.stickY * gController.stickY);
apply_mario_platform_displacement();
bhv_mario_update();
update_mario_platform(); // TODO platform grabbed here and used next tick could be a use-after-free
- gfx_adapter_bind_output_buffers( outBuffers );
+ gfx_adapter_bind_output_buffers(outBuffers);
- geo_process_root_hack_single_node( s_mario_graph_node );
+ geo_process_root_hack_single_node(s_mario_graph_node);
gAreaUpdateCounter++;
outState->health = gMarioState->health;
- vec3f_copy( outState->position, gMarioState->pos );
- vec3f_copy( outState->velocity, gMarioState->vel );
+ vec3f_copy(outState->position, gMarioState->pos);
+ vec3f_copy(outState->velocity, gMarioState->vel);
outState->faceAngle = (float)gMarioState->faceAngle[1] / 32768.0f * 3.14159f;
outState->forwardVelocity = gMarioState->forwardVel;
outState->action = gMarioState->action;
@@ -266,108 +272,109 @@ SM64_LIB_FN void sm64_mario_tick( int32_t marioId, const struct SM64MarioInputs
outState->invincTimer = gMarioState->invincTimer;
}
-SM64_LIB_FN void sm64_mario_delete( int32_t marioId )
+SM64_LIB_FN void sm64_mario_delete(int32_t marioId)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to delete non-existant Mario with ID: %u", marioId);
return;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
- if ( g_is_audio_initialized ) {
+ if (g_is_audio_initialized)
+ {
stop_sound(SOUND_MARIO_SNORING3, gMarioState->marioObj->header.gfx.cameraToObject);
}
- free( gMarioObject );
- free_area( gCurrentArea );
+ free(gMarioObject);
+ free_area(gCurrentArea);
- global_state_delete( globalState );
- obj_pool_free_index( &s_mario_instance_pool, marioId );
+ global_state_delete(globalState);
+ obj_pool_free_index(&s_mario_instance_pool, marioId);
}
SM64_LIB_FN void sm64_set_mario_action(int32_t marioId, uint32_t action)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
set_mario_action(gMarioState, action, 0);
}
SM64_LIB_FN void sm64_set_mario_action_arg(int32_t marioId, uint32_t action, uint32_t actionArg)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
set_mario_action(gMarioState, action, actionArg);
}
SM64_LIB_FN void sm64_set_mario_animation(int32_t marioId, int32_t animID)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
set_mario_animation(gMarioState, animID);
}
SM64_LIB_FN void sm64_set_mario_anim_frame(int32_t marioId, int16_t animFrame)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
gMarioState->marioObj->header.gfx.animInfo.animFrame = animFrame;
}
SM64_LIB_FN void sm64_set_mario_state(int32_t marioId, uint32_t flags)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
gMarioState->flags = flags;
}
SM64_LIB_FN void sm64_set_mario_position(int32_t marioId, float x, float y, float z)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
gMarioState->pos[0] = x;
gMarioState->pos[1] = y;
@@ -377,14 +384,14 @@ SM64_LIB_FN void sm64_set_mario_position(int32_t marioId, float x, float y, floa
SM64_LIB_FN void sm64_set_mario_angle(int32_t marioId, float x, float y, float z)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
vec3s_set(gMarioState->faceAngle, (int16_t)(x / 3.14159f * 32768.f), (int16_t)(y / 3.14159f * 32768.f), (int16_t)(z / 3.14159f * 32768.f));
vec3s_copy(gMarioState->marioObj->header.gfx.angle, gMarioState->faceAngle);
@@ -392,14 +399,14 @@ SM64_LIB_FN void sm64_set_mario_angle(int32_t marioId, float x, float y, float z
SM64_LIB_FN void sm64_set_mario_faceangle(int32_t marioId, float y)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
gMarioState->faceAngle[1] = (int16_t)(y / 3.14159f * 32768.f);
vec3s_set(gMarioState->marioObj->header.gfx.angle, 0, gMarioState->faceAngle[1], 0);
@@ -407,14 +414,14 @@ SM64_LIB_FN void sm64_set_mario_faceangle(int32_t marioId, float y)
SM64_LIB_FN void sm64_set_mario_velocity(int32_t marioId, float x, float y, float z)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
gMarioState->vel[0] = x;
gMarioState->vel[1] = y;
@@ -423,70 +430,70 @@ SM64_LIB_FN void sm64_set_mario_velocity(int32_t marioId, float x, float y, floa
SM64_LIB_FN void sm64_set_mario_forward_velocity(int32_t marioId, float vel)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
gMarioState->forwardVel = vel;
}
SM64_LIB_FN void sm64_set_mario_invincibility(int32_t marioId, int16_t timer)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
gMarioState->invincTimer = timer;
}
SM64_LIB_FN void sm64_set_mario_water_level(int32_t marioId, signed int level)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
gMarioState->waterLevel = level;
}
SM64_LIB_FN void sm64_set_mario_gas_level(int32_t marioId, signed int level)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
gMarioState->gasLevel = level;
}
SM64_LIB_FN void sm64_set_mario_health(int32_t marioId, uint16_t health)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
gMarioState->health = health;
gMarioState->hurtCounter = 0;
@@ -495,94 +502,99 @@ SM64_LIB_FN void sm64_set_mario_health(int32_t marioId, uint16_t health)
SM64_LIB_FN void sm64_mario_take_damage(int32_t marioId, uint32_t damage, uint32_t subtype, float x, float y, float z)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
fake_damage_knock_back(gMarioState, damage, subtype, x, y, z);
}
SM64_LIB_FN void sm64_mario_heal(int32_t marioId, uint8_t healCounter)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
gMarioState->healCounter += healCounter;
}
SM64_LIB_FN void sm64_mario_kill(int32_t marioId)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
gMarioState->health = 0xff;
}
SM64_LIB_FN void sm64_mario_interact_cap(int32_t marioId, uint32_t capFlag, uint16_t capTime, uint8_t playMusic)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
uint16_t capMusic = 0;
- if(gMarioState->action != ACT_GETTING_BLOWN && capFlag != 0)
+ if (gMarioState->action != ACT_GETTING_BLOWN && capFlag != 0)
{
gMarioState->flags &= ~MARIO_CAP_ON_HEAD & ~MARIO_CAP_IN_HAND;
gMarioState->flags |= capFlag;
- switch(capFlag)
+ switch (capFlag)
{
case MARIO_VANISH_CAP:
- if(capTime == 0) capTime = 600;
+ if (capTime == 0) capTime = 600;
capMusic = SEQUENCE_ARGS(4, SEQ_EVENT_POWERUP);
break;
case MARIO_METAL_CAP:
- if(capTime == 0) capTime = 600;
+ if (capTime == 0) capTime = 600;
capMusic = SEQUENCE_ARGS(4, SEQ_EVENT_METAL_CAP);
break;
case MARIO_WING_CAP:
- if(capTime == 0) capTime = 1800;
+ if (capTime == 0) capTime = 1800;
capMusic = SEQUENCE_ARGS(4, SEQ_EVENT_POWERUP);
break;
}
- if (capTime > gMarioState->capTimer) {
+ if (capTime > gMarioState->capTimer)
+ {
gMarioState->capTimer = capTime;
}
- if ((gMarioState->action & ACT_FLAG_IDLE) || gMarioState->action == ACT_WALKING) {
+ if (gMarioState->action & ACT_FLAG_IDLE || gMarioState->action == ACT_WALKING)
+ {
gMarioState->flags |= MARIO_CAP_IN_HAND;
set_mario_action(gMarioState, ACT_PUTTING_ON_CAP, 0);
- } else {
+ }
+ else
+ {
gMarioState->flags |= MARIO_CAP_ON_HEAD;
}
play_sound(SOUND_MENU_STAR_SOUND, gMarioState->marioObj->header.gfx.cameraToObject);
play_sound(SOUND_MARIO_HERE_WE_GO, gMarioState->marioObj->header.gfx.cameraToObject);
- if (playMusic != 0 && capMusic != 0) {
+ if (playMusic != 0 && capMusic != 0)
+ {
play_cap_music(capMusic);
}
}
@@ -590,108 +602,108 @@ SM64_LIB_FN void sm64_mario_interact_cap(int32_t marioId, uint32_t capFlag, uint
SM64_LIB_FN void sm64_mario_extend_cap(int32_t marioId, uint16_t capTime)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
gMarioState->capTimer += capTime;
}
SM64_LIB_FN bool sm64_mario_attack(int32_t marioId, float x, float y, float z, float hitboxHeight)
{
- if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
+ if (marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL)
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return false;
}
- struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
- global_state_bind( globalState );
+ struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[marioId])->globalState;
+ global_state_bind(globalState);
return fake_interact_bounce_top(gMarioState, x, y, z, hitboxHeight);
}
-SM64_LIB_FN uint32_t sm64_surface_object_create( const struct SM64SurfaceObject *surfaceObject )
+SM64_LIB_FN uint32_t sm64_surface_object_create(const struct SM64SurfaceObject *surfaceObject)
{
- uint32_t id = surfaces_load_object( surfaceObject );
+ uint32_t id = surfaces_load_object(surfaceObject);
return id;
}
-SM64_LIB_FN void sm64_surface_object_move( uint32_t objectId, const struct SM64ObjectTransform *transform )
+SM64_LIB_FN void sm64_surface_object_move(uint32_t objectId, const struct SM64ObjectTransform *transform)
{
- surface_object_update_transform( objectId, transform );
+ surface_object_update_transform(objectId, transform);
}
-SM64_LIB_FN void sm64_surface_object_delete( uint32_t objectId )
+SM64_LIB_FN void sm64_surface_object_delete(uint32_t objectId)
{
// A mario standing on the platform that is being destroyed will have a pointer to freed memory if we don't clear it.
- for( int i = 0; i < s_mario_instance_pool.size; ++i )
+ for (int i = 0; i < s_mario_instance_pool.size; ++i)
{
- if( s_mario_instance_pool.objects[i] == NULL )
+ if (s_mario_instance_pool.objects[i] == NULL)
continue;
- struct GlobalState *state = ((struct MarioInstance *)s_mario_instance_pool.objects[ i ])->globalState;
- if( state->mgMarioObject->platform == surfaces_object_get_transform_ptr( objectId ))
+ struct GlobalState *state = ((struct MarioInstance *)s_mario_instance_pool.objects[i])->globalState;
+ if (state->mgMarioObject->platform == surfaces_object_get_transform_ptr(objectId))
state->mgMarioObject->platform = NULL;
}
- surfaces_unload_object( objectId );
+ surfaces_unload_object(objectId);
}
-SM64_LIB_FN int32_t sm64_surface_find_wall_collision( float *xPtr, float *yPtr, float *zPtr, float offsetY, float radius )
+SM64_LIB_FN int32_t sm64_surface_find_wall_collision(float *xPtr, float *yPtr, float *zPtr, float offsetY, float radius)
{
- return f32_find_wall_collision( xPtr, yPtr, zPtr, offsetY, radius );
+ return f32_find_wall_collision(xPtr, yPtr, zPtr, offsetY, radius);
}
-SM64_LIB_FN int32_t sm64_surface_find_wall_collisions( struct SM64WallCollisionData *colData )
+SM64_LIB_FN int32_t sm64_surface_find_wall_collisions(struct SM64WallCollisionData *colData)
{
- return find_wall_collisions( colData );
+ return find_wall_collisions(colData);
}
-SM64_LIB_FN float sm64_surface_find_ceil( float posX, float posY, float posZ, struct SM64SurfaceCollisionData **pceil )
+SM64_LIB_FN float sm64_surface_find_ceil(float posX, float posY, float posZ, struct SM64SurfaceCollisionData **pceil)
{
- return find_ceil( posX, posY, posZ, pceil );
+ return find_ceil(posX, posY, posZ, pceil);
}
-SM64_LIB_FN float sm64_surface_find_floor_height_and_data( float xPos, float yPos, float zPos, struct SM64FloorCollisionData **floorGeo )
+SM64_LIB_FN float sm64_surface_find_floor_height_and_data(float xPos, float yPos, float zPos, struct SM64FloorCollisionData **floorGeo)
{
- return find_floor_height_and_data( xPos, yPos, zPos, floorGeo );
+ return find_floor_height_and_data(xPos, yPos, zPos, floorGeo);
}
-SM64_LIB_FN float sm64_surface_find_floor_height( float x, float y, float z )
+SM64_LIB_FN float sm64_surface_find_floor_height(float x, float y, float z)
{
- return find_floor_height( x, y, z );
+ return find_floor_height(x, y, z);
}
-SM64_LIB_FN float sm64_surface_find_floor( float xPos, float yPos, float zPos, struct SM64SurfaceCollisionData **pfloor )
+SM64_LIB_FN float sm64_surface_find_floor(float xPos, float yPos, float zPos, struct SM64SurfaceCollisionData **pfloor)
{
- return find_floor( xPos, yPos, zPos, pfloor );
+ return find_floor(xPos, yPos, zPos, pfloor);
}
-SM64_LIB_FN float sm64_surface_find_water_level( float x, float z )
+SM64_LIB_FN float sm64_surface_find_water_level(float x, float z)
{
- return find_water_level( x, z );
+ return find_water_level(x, z);
}
-SM64_LIB_FN float sm64_surface_find_poison_gas_level( float x, float z )
+SM64_LIB_FN float sm64_surface_find_poison_gas_level(float x, float z)
{
- return find_poison_gas_level( x, z );
+ return find_poison_gas_level(x, z);
}
SM64_LIB_FN void sm64_seq_player_play_sequence(uint8_t player, uint8_t seqId, uint16_t arg2)
{
- seq_player_play_sequence(player,seqId,arg2);
+ seq_player_play_sequence(player, seqId, arg2);
}
SM64_LIB_FN void sm64_play_music(uint8_t player, uint16_t seqArgs, uint16_t fadeTimer)
{
- play_music(player,seqArgs,fadeTimer);
+ play_music(player, seqArgs, fadeTimer);
}
SM64_LIB_FN void sm64_stop_background_music(uint16_t seqId)
@@ -701,7 +713,7 @@ SM64_LIB_FN void sm64_stop_background_music(uint16_t seqId)
SM64_LIB_FN void sm64_fadeout_background_music(uint16_t arg0, uint16_t fadeOut)
{
- fadeout_background_music(arg0,fadeOut);
+ fadeout_background_music(arg0, fadeOut);
}
SM64_LIB_FN uint16_t sm64_get_current_background_music()
@@ -711,12 +723,12 @@ SM64_LIB_FN uint16_t sm64_get_current_background_music()
SM64_LIB_FN void sm64_play_sound(int32_t soundBits, float *pos)
{
- play_sound(soundBits,pos);
+ play_sound(soundBits, pos);
}
SM64_LIB_FN void sm64_play_sound_global(int32_t soundBits)
{
- play_sound(soundBits,gGlobalSoundSource);
+ play_sound(soundBits, gGlobalSoundSource);
}
SM64_LIB_FN void sm64_set_sound_volume(float vol)
diff --git a/src/libsm64.h b/src/libsm64.h
index 54ff200..59af8a7 100644
--- a/src/libsm64.h
+++ b/src/libsm64.h
@@ -6,23 +6,25 @@
#include
#if defined(_WIN32)
- #ifdef SM64_LIB_EXPORT
- #define SM64_LIB_FN __declspec(dllexport)
- #else
- #define SM64_LIB_FN __declspec(dllimport)
- #endif
-#elif defined(__GNUC__) && __GNUC__ >= 4
- #ifdef SM64_LIB_EXPORT
- #define SM64_LIB_FN __attribute__ ((visibility("default")))
- #else
- #define SM64_LIB_FN
- #endif
+#ifdef SM64_LIB_EXPORT
+#define SM64_LIB_FN __declspec(dllexport)
#else
- #define SM64_LIB_FN
+#define SM64_LIB_FN __declspec(dllimport)
+#endif
+#elif defined(__GNUC__) && __GNUC__ >= 4
+#ifdef SM64_LIB_EXPORT
+#define SM64_LIB_FN __attribute__ ((visibility("default")))
+#else
+#define SM64_LIB_FN
+#endif
+#else
+#define SM64_LIB_FN
#endif
#ifdef __cplusplus
-extern "C" {
+extern "C"
+{
+
#endif
struct SM64Surface
@@ -61,7 +63,7 @@ struct SM64MarioState
float forwardVelocity;
int16_t health;
uint32_t action;
- struct AnimInfo* animInfo;
+ struct AnimInfo *animInfo;
uint32_t flags;
uint32_t particleFlags;
int16_t invincTimer;
@@ -78,12 +80,18 @@ struct SM64MarioGeometryBuffers
struct SM64WallCollisionData
{
- /*0x00*/ float x, y, z;
- /*0x0C*/ float offsetY;
- /*0x10*/ float radius;
- /*0x14*/ int16_t unk14;
- /*0x16*/ int16_t numWalls;
- /*0x18*/ struct SM64SurfaceCollisionData *walls[4];
+ /*0x00*/
+ float x, y, z;
+ /*0x0C*/
+ float offsetY;
+ /*0x10*/
+ float radius;
+ /*0x14*/
+ int16_t unk14;
+ /*0x16*/
+ int16_t numWalls;
+ /*0x18*/
+ struct SM64SurfaceCollisionData *walls[4];
};
struct SM64FloorCollisionData
@@ -120,11 +128,14 @@ struct SM64SurfaceCollisionData
float vertex1[3];
float vertex2[3];
float vertex3[3];
- struct {
+
+ struct
+ {
float x;
float y;
float z;
} normal;
+
float originOffset;
uint8_t isValid; // libsm64: added field
@@ -134,71 +145,110 @@ struct SM64SurfaceCollisionData
enum
{
- SM64_TEXTURE_WIDTH = 64 * 11,
- SM64_TEXTURE_HEIGHT = 64,
- SM64_GEO_MAX_TRIANGLES = 1024,
+ SM64_TEXTURE_WIDTH = 64 * 11, SM64_TEXTURE_HEIGHT = 64, SM64_GEO_MAX_TRIANGLES = 1024,
};
-typedef void (*SM64DebugPrintFunctionPtr)( const char * );
-extern SM64_LIB_FN void sm64_register_debug_print_function( SM64DebugPrintFunctionPtr debugPrintFunction );
+typedef void (*SM64DebugPrintFunctionPtr)(const char *);
-typedef void (*SM64PlaySoundFunctionPtr)( uint32_t soundBits, float *pos );
-extern SM64_LIB_FN void sm64_register_play_sound_function( SM64PlaySoundFunctionPtr playSoundFunction );
+extern SM64_LIB_FN void sm64_register_debug_print_function(SM64DebugPrintFunctionPtr debugPrintFunction);
-extern SM64_LIB_FN void sm64_global_init( const uint8_t *rom, uint8_t *outTexture );
-extern SM64_LIB_FN void sm64_global_terminate( void );
+typedef void (*SM64PlaySoundFunctionPtr)(uint32_t soundBits, float *pos);
-extern SM64_LIB_FN void sm64_audio_init( const uint8_t *rom );
-extern SM64_LIB_FN uint32_t sm64_audio_tick( uint32_t numQueuedSamples, uint32_t numDesiredSamples, int16_t *audio_buffer );
+extern SM64_LIB_FN void sm64_register_play_sound_function(SM64PlaySoundFunctionPtr playSoundFunction);
-extern SM64_LIB_FN void sm64_static_surfaces_load( const struct SM64Surface *surfaceArray, uint32_t numSurfaces );
+extern SM64_LIB_FN void sm64_global_init(const uint8_t *rom, uint8_t *outTexture);
-extern SM64_LIB_FN int32_t sm64_mario_create( float x, float y, float z );
-extern SM64_LIB_FN void sm64_mario_tick( int32_t marioId, const struct SM64MarioInputs *inputs, struct SM64MarioState *outState, struct SM64MarioGeometryBuffers *outBuffers );
-extern SM64_LIB_FN void sm64_mario_delete( int32_t marioId );
+extern SM64_LIB_FN void sm64_global_terminate(void);
+
+extern SM64_LIB_FN void sm64_audio_init(const uint8_t *rom);
+
+extern SM64_LIB_FN uint32_t sm64_audio_tick(uint32_t numQueuedSamples, uint32_t numDesiredSamples, int16_t *audio_buffer);
+
+extern SM64_LIB_FN void sm64_static_surfaces_load(const struct SM64Surface *surfaceArray, uint32_t numSurfaces);
+
+extern SM64_LIB_FN int32_t sm64_mario_create(float x, float y, float z);
+
+extern SM64_LIB_FN void sm64_mario_tick(int32_t marioId, const struct SM64MarioInputs *inputs, struct SM64MarioState *outState, struct SM64MarioGeometryBuffers *outBuffers);
+
+extern SM64_LIB_FN void sm64_mario_delete(int32_t marioId);
extern SM64_LIB_FN void sm64_set_mario_action(int32_t marioId, uint32_t action);
+
extern SM64_LIB_FN void sm64_set_mario_action_arg(int32_t marioId, uint32_t action, uint32_t actionArg);
+
extern SM64_LIB_FN void sm64_set_mario_animation(int32_t marioId, int32_t animID);
+
extern SM64_LIB_FN void sm64_set_mario_anim_frame(int32_t marioId, int16_t animFrame);
+
extern SM64_LIB_FN void sm64_set_mario_state(int32_t marioId, uint32_t flags);
+
extern SM64_LIB_FN void sm64_set_mario_position(int32_t marioId, float x, float y, float z);
+
extern SM64_LIB_FN void sm64_set_mario_angle(int32_t marioId, float x, float y, float z);
+
extern SM64_LIB_FN void sm64_set_mario_faceangle(int32_t marioId, float y);
+
extern SM64_LIB_FN void sm64_set_mario_velocity(int32_t marioId, float x, float y, float z);
+
extern SM64_LIB_FN void sm64_set_mario_forward_velocity(int32_t marioId, float vel);
+
extern SM64_LIB_FN void sm64_set_mario_invincibility(int32_t marioId, int16_t timer);
+
extern SM64_LIB_FN void sm64_set_mario_water_level(int32_t marioId, signed int level);
+
extern SM64_LIB_FN void sm64_set_mario_gas_level(int32_t marioId, signed int level);
+
extern SM64_LIB_FN void sm64_set_mario_health(int32_t marioId, uint16_t health);
+
extern SM64_LIB_FN void sm64_mario_take_damage(int32_t marioId, uint32_t damage, uint32_t subtype, float x, float y, float z);
+
extern SM64_LIB_FN void sm64_mario_heal(int32_t marioId, uint8_t healCounter);
+
extern SM64_LIB_FN void sm64_mario_kill(int32_t marioId);
+
extern SM64_LIB_FN void sm64_mario_interact_cap(int32_t marioId, uint32_t capFlag, uint16_t capTime, uint8_t playMusic);
+
extern SM64_LIB_FN void sm64_mario_extend_cap(int32_t marioId, uint16_t capTime);
+
extern SM64_LIB_FN bool sm64_mario_attack(int32_t marioId, float x, float y, float z, float hitboxHeight);
-extern SM64_LIB_FN uint32_t sm64_surface_object_create( const struct SM64SurfaceObject *surfaceObject );
-extern SM64_LIB_FN void sm64_surface_object_move( uint32_t objectId, const struct SM64ObjectTransform *transform );
-extern SM64_LIB_FN void sm64_surface_object_delete( uint32_t objectId );
+extern SM64_LIB_FN uint32_t sm64_surface_object_create(const struct SM64SurfaceObject *surfaceObject);
-extern SM64_LIB_FN int32_t sm64_surface_find_wall_collision( float *xPtr, float *yPtr, float *zPtr, float offsetY, float radius );
-extern SM64_LIB_FN int32_t sm64_surface_find_wall_collisions( struct SM64WallCollisionData *colData );
-extern SM64_LIB_FN float sm64_surface_find_ceil( float posX, float posY, float posZ, struct SM64SurfaceCollisionData **pceil );
-extern SM64_LIB_FN float sm64_surface_find_floor_height_and_data( float xPos, float yPos, float zPos, struct SM64FloorCollisionData **floorGeo );
-extern SM64_LIB_FN float sm64_surface_find_floor_height( float x, float y, float z );
-extern SM64_LIB_FN float sm64_surface_find_floor( float xPos, float yPos, float zPos, struct SM64SurfaceCollisionData **pfloor );
-extern SM64_LIB_FN float sm64_surface_find_water_level( float x, float z );
-extern SM64_LIB_FN float sm64_surface_find_poison_gas_level( float x, float z );
+extern SM64_LIB_FN void sm64_surface_object_move(uint32_t objectId, const struct SM64ObjectTransform *transform);
+
+extern SM64_LIB_FN void sm64_surface_object_delete(uint32_t objectId);
+
+extern SM64_LIB_FN int32_t sm64_surface_find_wall_collision(float *xPtr, float *yPtr, float *zPtr, float offsetY, float radius);
+
+extern SM64_LIB_FN int32_t sm64_surface_find_wall_collisions(struct SM64WallCollisionData *colData);
+
+extern SM64_LIB_FN float sm64_surface_find_ceil(float posX, float posY, float posZ, struct SM64SurfaceCollisionData **pceil);
+
+extern SM64_LIB_FN float sm64_surface_find_floor_height_and_data(float xPos, float yPos, float zPos, struct SM64FloorCollisionData **floorGeo);
+
+extern SM64_LIB_FN float sm64_surface_find_floor_height(float x, float y, float z);
+
+extern SM64_LIB_FN float sm64_surface_find_floor(float xPos, float yPos, float zPos, struct SM64SurfaceCollisionData **pfloor);
+
+extern SM64_LIB_FN float sm64_surface_find_water_level(float x, float z);
+
+extern SM64_LIB_FN float sm64_surface_find_poison_gas_level(float x, float z);
extern SM64_LIB_FN void sm64_seq_player_play_sequence(uint8_t player, uint8_t seqId, uint16_t arg2);
+
extern SM64_LIB_FN void sm64_play_music(uint8_t player, uint16_t seqArgs, uint16_t fadeTimer);
+
extern SM64_LIB_FN void sm64_stop_background_music(uint16_t seqId);
+
extern SM64_LIB_FN void sm64_fadeout_background_music(uint16_t arg0, uint16_t fadeOut);
+
extern SM64_LIB_FN uint16_t sm64_get_current_background_music();
+
extern SM64_LIB_FN void sm64_play_sound(int32_t soundBits, float *pos);
+
extern SM64_LIB_FN void sm64_play_sound_global(int32_t soundBits);
+
extern SM64_LIB_FN void sm64_set_sound_volume(float vol);
#ifdef __cplusplus
diff --git a/src/load_anim_data.c b/src/load_anim_data.c
index ec19ce3..c6833de 100644
--- a/src/load_anim_data.c
+++ b/src/load_anim_data.c
@@ -7,71 +7,78 @@ static struct Animation *s_libsm64_mario_animations = NULL;
#define ANIM_DATA_ADDRESS 0x004EC000
-static uint16_t read_u16_be( const uint8_t *p )
+static uint16_t read_u16_be(const uint8_t *p)
{
return
- (uint32_t)p[0] << 8 |
- (uint32_t)p[1];
-
+ (uint32_t)p[0] << 8 |
+ (uint32_t)p[1];
}
-static uint16_t read_s16_be( const uint8_t *p )
+static uint16_t read_s16_be(const uint8_t *p)
{
- return (int16_t)read_u16_be( p );
+ return (int16_t)read_u16_be(p);
}
-static uint32_t read_u32_be( const uint8_t *p )
+static uint32_t read_u32_be(const uint8_t *p)
{
return
- (uint32_t)p[0] << 24 |
- (uint32_t)p[1] << 16 |
- (uint32_t)p[2] << 8 |
- (uint32_t)p[3];
+ (uint32_t)p[0] << 24 |
+ (uint32_t)p[1] << 16 |
+ (uint32_t)p[2] << 8 |
+ (uint32_t)p[3];
}
-void load_mario_anims_from_rom( const uint8_t *rom )
+void load_mario_anims_from_rom(const uint8_t *rom)
{
#define GET_OFFSET( n ) (read_u32_be((uint8_t*)&((struct OffsetSizePair*)( rom + ANIM_DATA_ADDRESS + 8 + (n)*8 ))->offset))
#define GET_SIZE( n ) (read_u32_be((uint8_t*)&((struct OffsetSizePair*)( rom + ANIM_DATA_ADDRESS + 8 + (n)*8 ))->size ))
const uint8_t *read_ptr = rom + ANIM_DATA_ADDRESS;
- s_num_entries = read_u32_be( read_ptr );
+ s_num_entries = read_u32_be(read_ptr);
- s_libsm64_mario_animations = malloc( s_num_entries * sizeof( struct Animation ));
+ s_libsm64_mario_animations = malloc(s_num_entries * sizeof(struct Animation));
struct Animation *anims = s_libsm64_mario_animations;
- for( int i = 0; i < s_num_entries; ++i )
+ for (int i = 0; i < s_num_entries; ++i)
{
read_ptr = rom + ANIM_DATA_ADDRESS + GET_OFFSET(i);
- anims[i].flags = read_s16_be( read_ptr ); read_ptr += 2;
- anims[i].animYTransDivisor = read_s16_be( read_ptr ); read_ptr += 2;
- anims[i].startFrame = read_s16_be( read_ptr ); read_ptr += 2;
- anims[i].loopStart = read_s16_be( read_ptr ); read_ptr += 2;
- anims[i].loopEnd = read_s16_be( read_ptr ); read_ptr += 2;
- anims[i].unusedBoneCount = read_s16_be( read_ptr ); read_ptr += 2;
- uint32_t values_offset = read_u32_be( read_ptr ); read_ptr += 4;
- uint32_t index_offset = read_u32_be( read_ptr ); read_ptr += 4;
- uint32_t end_offset = read_u32_be( read_ptr );
+ anims[i].flags = read_s16_be(read_ptr);
+ read_ptr += 2;
+ anims[i].animYTransDivisor = read_s16_be(read_ptr);
+ read_ptr += 2;
+ anims[i].startFrame = read_s16_be(read_ptr);
+ read_ptr += 2;
+ anims[i].loopStart = read_s16_be(read_ptr);
+ read_ptr += 2;
+ anims[i].loopEnd = read_s16_be(read_ptr);
+ read_ptr += 2;
+ anims[i].unusedBoneCount = read_s16_be(read_ptr);
+ read_ptr += 2;
+ uint32_t values_offset = read_u32_be(read_ptr);
+ read_ptr += 4;
+ uint32_t index_offset = read_u32_be(read_ptr);
+ read_ptr += 4;
+ uint32_t end_offset = read_u32_be(read_ptr);
- read_ptr = rom + ANIM_DATA_ADDRESS + GET_OFFSET(i) + index_offset;
+ read_ptr = rom + ANIM_DATA_ADDRESS + GET_OFFSET(i) + index_offset;
const uint8_t *values_ptr = rom + ANIM_DATA_ADDRESS + GET_OFFSET(i) + values_offset;
- const uint8_t *end_ptr = rom + ANIM_DATA_ADDRESS + GET_OFFSET(i) + end_offset;
+ const uint8_t *end_ptr = rom + ANIM_DATA_ADDRESS + GET_OFFSET(i) + end_offset;
- anims[i].index = malloc( values_offset - index_offset );
- anims[i].values = malloc( end_offset - values_offset );
+ anims[i].index = malloc(values_offset - index_offset);
+ anims[i].values = malloc(end_offset - values_offset);
int j = 0;
- while( read_ptr < values_ptr )
+ while (read_ptr < values_ptr)
{
- anims[i].index[j++] = read_u16_be( read_ptr );
+ anims[i].index[j++] = read_u16_be(read_ptr);
read_ptr += 2;
}
j = 0;
- while( read_ptr < end_ptr )
+ while (read_ptr < end_ptr)
{
- anims[i].values[j++] = read_u16_be( read_ptr );
+ anims[i].values[j++] = read_u16_be(read_ptr);
read_ptr += 2;
}
}
@@ -82,21 +89,22 @@ void load_mario_anims_from_rom( const uint8_t *rom )
void load_mario_animation(struct MarioAnimation *a, u32 index)
{
- if (a->currentAnimAddr != 1 + index) {
+ if (a->currentAnimAddr != 1 + index)
+ {
a->currentAnimAddr = 1 + index;
a->targetAnim = &s_libsm64_mario_animations[index];
}
}
-void unload_mario_anims( void )
+void unload_mario_anims(void)
{
- for( int i = 0; i < s_num_entries; ++i )
+ for (int i = 0; i < s_num_entries; ++i)
{
- free( s_libsm64_mario_animations[i].index );
- free( s_libsm64_mario_animations[i].values );
+ free(s_libsm64_mario_animations[i].index);
+ free(s_libsm64_mario_animations[i].values);
}
- free( s_libsm64_mario_animations );
+ free(s_libsm64_mario_animations);
s_libsm64_mario_animations = NULL;
s_num_entries = 0;
}
\ No newline at end of file
diff --git a/src/load_anim_data.h b/src/load_anim_data.h
index a0869ce..ee636d9 100644
--- a/src/load_anim_data.h
+++ b/src/load_anim_data.h
@@ -6,5 +6,7 @@
#include "decomp/include/types.h"
extern void load_mario_animation(struct MarioAnimation *a, u32 index);
-extern void load_mario_anims_from_rom( const uint8_t *rom );
-extern void unload_mario_anims( void );
\ No newline at end of file
+
+extern void load_mario_anims_from_rom(const uint8_t *rom);
+
+extern void unload_mario_anims(void);
\ No newline at end of file
diff --git a/src/load_audio_data.c b/src/load_audio_data.c
index ef88a7b..6a342e3 100644
--- a/src/load_audio_data.c
+++ b/src/load_audio_data.c
@@ -9,23 +9,24 @@
bool g_is_audio_initialized = false;
-extern void load_audio_banks( const uint8_t *rom ) {
+extern void load_audio_banks(const uint8_t *rom)
+{
// FIXME: rom_copy purposfully leaks here
- uint8_t *rom_copy = malloc( 0x800000 );
+ uint8_t *rom_copy = malloc(0x800000);
- memcpy( rom_copy, rom, 0x800000 );
+ memcpy(rom_copy, rom, 0x800000);
- gSoundDataADSR = parse_seqfile( rom_copy+0x57B720 ); //ctl
- gSoundDataRaw = parse_seqfile( rom_copy+0x593560 ); //tbl
- gMusicData = parse_seqfile( rom_copy+0x7B0860 );
- gBankSetsData = rom_copy+0x7CC621;
- memmove( gBankSetsData+0x45,gBankSetsData+0x45-1,0x5B );
- gBankSetsData[0x45]=0x00;
- ptrs_to_offsets( gSoundDataADSR );
+ gSoundDataADSR = parse_seqfile(rom_copy + 0x57B720); //ctl
+ gSoundDataRaw = parse_seqfile(rom_copy + 0x593560); //tbl
+ gMusicData = parse_seqfile(rom_copy + 0x7B0860);
+ gBankSetsData = rom_copy + 0x7CC621;
+ memmove(gBankSetsData + 0x45, gBankSetsData + 0x45 - 1, 0x5B);
+ gBankSetsData[0x45] = 0x00;
+ ptrs_to_offsets(gSoundDataADSR);
audio_init();
sound_init();
- sound_reset( 0 );
+ sound_reset(0);
g_is_audio_initialized = true;
}
diff --git a/src/load_audio_data.h b/src/load_audio_data.h
index 1e2fb35..512e5b3 100644
--- a/src/load_audio_data.h
+++ b/src/load_audio_data.h
@@ -5,4 +5,4 @@
extern bool g_is_audio_initialized;
-extern void load_audio_banks( const uint8_t *rom );
\ No newline at end of file
+extern void load_audio_banks(const uint8_t *rom);
\ No newline at end of file
diff --git a/src/load_surfaces.c b/src/load_surfaces.c
index 1a77e21..4409c2b 100644
--- a/src/load_surfaces.c
+++ b/src/load_surfaces.c
@@ -27,7 +27,7 @@ static struct LoadedSurfaceObject *s_surface_object_list = NULL;
#define CONVERT_ANGLE( x ) ((s16)( -(x) / 180.0f * 32768.0f ))
-static void init_transform( struct SM64SurfaceObjectTransform *out, const struct SM64ObjectTransform *in )
+static void init_transform(struct SM64SurfaceObjectTransform *out, const struct SM64ObjectTransform *in)
{
out->aVelX = 0.0f;
out->aVelY = 0.0f;
@@ -37,14 +37,14 @@ static void init_transform( struct SM64SurfaceObjectTransform *out, const struct
out->aPosZ = in->position[2];
out->aAngleVelPitch = 0.0f;
- out->aAngleVelYaw = 0.0f;
- out->aAngleVelRoll = 0.0f;
+ out->aAngleVelYaw = 0.0f;
+ out->aAngleVelRoll = 0.0f;
out->aFaceAnglePitch = CONVERT_ANGLE(in->eulerRotation[0]);
- out->aFaceAngleYaw = CONVERT_ANGLE(in->eulerRotation[1]);
- out->aFaceAngleRoll = CONVERT_ANGLE(in->eulerRotation[2]);
+ out->aFaceAngleYaw = CONVERT_ANGLE(in->eulerRotation[1]);
+ out->aFaceAngleRoll = CONVERT_ANGLE(in->eulerRotation[2]);
}
-static void update_transform( struct SM64SurfaceObjectTransform *out, const struct SM64ObjectTransform *in )
+static void update_transform(struct SM64SurfaceObjectTransform *out, const struct SM64ObjectTransform *in)
{
out->aVelX = in->position[0] - out->aPosX;
out->aVelY = in->position[1] - out->aPosY;
@@ -58,21 +58,23 @@ static void update_transform( struct SM64SurfaceObjectTransform *out, const stru
s16 inZ = CONVERT_ANGLE(in->eulerRotation[2]);
out->aAngleVelPitch = inX - out->aFaceAnglePitch;
- out->aAngleVelYaw = inY - out->aFaceAngleYaw;
- out->aAngleVelRoll = inZ - out->aFaceAngleRoll;
+ out->aAngleVelYaw = inY - out->aFaceAngleYaw;
+ out->aAngleVelRoll = inZ - out->aFaceAngleRoll;
out->aFaceAnglePitch = inX;
- out->aFaceAngleYaw = inY;
- out->aFaceAngleRoll = inZ;
+ out->aFaceAngleYaw = inY;
+ out->aFaceAngleRoll = inZ;
}
/**
* Returns whether a surface has exertion/moves Mario
* based on the surface type.
*/
-static s32 surface_has_force(s16 surfaceType) {
+static s32 surface_has_force(s16 surfaceType)
+{
s32 hasForce = FALSE;
- switch (surfaceType) {
+ switch (surfaceType)
+ {
case SURFACE_0004: // Unused
case SURFACE_FLOWING_WATER:
case SURFACE_DEEP_MOVING_QUICKSAND:
@@ -89,7 +91,7 @@ static s32 surface_has_force(s16 surfaceType) {
return hasForce;
}
-static void engine_surface_from_lib_surface( struct SM64SurfaceCollisionData *surface, const struct SM64Surface *libSurf, struct SM64SurfaceObjectTransform *transform )
+static void engine_surface_from_lib_surface(struct SM64SurfaceCollisionData *surface, const struct SM64Surface *libSurf, struct SM64SurfaceObjectTransform *transform)
{
int16_t type = libSurf->type;
int16_t force = libSurf->force;
@@ -107,24 +109,30 @@ static void engine_surface_from_lib_surface( struct SM64SurfaceCollisionData *su
f32 nx, ny, nz;
f32 mag;
- if( transform != NULL )
+ if (transform != NULL)
{
Mat4 m;
- Vec3s rotation = { transform->aFaceAnglePitch, transform->aFaceAngleYaw, transform->aFaceAngleRoll };
- Vec3f position = { transform->aPosX, transform->aPosY, transform->aPosZ };
+ Vec3s rotation = {transform->aFaceAnglePitch, transform->aFaceAngleYaw, transform->aFaceAngleRoll};
+ Vec3f position = {transform->aPosX, transform->aPosY, transform->aPosZ};
mtxf_rotate_zxy_and_translate(m, position, rotation);
- Vec3f v1 = { x1, y1, z1 };
- Vec3f v2 = { x2, y2, z2 };
- Vec3f v3 = { x3, y3, z3 };
+ Vec3f v1 = {x1, y1, z1};
+ Vec3f v2 = {x2, y2, z2};
+ Vec3f v3 = {x3, y3, z3};
- mtxf_mul_vec3f( m, v1 );
- mtxf_mul_vec3f( m, v2 );
- mtxf_mul_vec3f( m, v3 );
+ mtxf_mul_vec3f(m, v1);
+ mtxf_mul_vec3f(m, v2);
+ mtxf_mul_vec3f(m, v3);
- x1 = v1[0]; y1 = v1[1]; z1 = v1[2];
- x2 = v2[0]; y2 = v2[1]; z2 = v2[2];
- x3 = v3[0]; y3 = v3[1]; z3 = v3[2];
+ x1 = v1[0];
+ y1 = v1[1];
+ z1 = v1[2];
+ x2 = v2[0];
+ y2 = v2[1];
+ z2 = v2[2];
+ x3 = v3[0];
+ y3 = v3[1];
+ z3 = v3[2];
surface->transform = transform;
}
@@ -141,26 +149,31 @@ static void engine_surface_from_lib_surface( struct SM64SurfaceCollisionData *su
// Could have used min_3 and max_3 for this...
minY = y1;
- if (y2 < minY) {
+ if (y2 < minY)
+ {
minY = y2;
}
- if (y3 < minY) {
+ if (y3 < minY)
+ {
minY = y3;
}
maxY = y1;
- if (y2 > maxY) {
+ if (y2 > maxY)
+ {
maxY = y2;
}
- if (y3 > maxY) {
+ if (y3 > maxY)
+ {
maxY = y3;
}
- if (mag < 0.0001) {
+ if (mag < 0.0001)
+ {
DEBUG_PRINT("ERROR: normal magnitude is very close to zero:");
- DEBUG_PRINT("v1 %f %f %f", x1, y1, z1 );
- DEBUG_PRINT("v2 %f %f %f", x2, y2, z2 );
- DEBUG_PRINT("v3 %f %f %f", x3, y3, z3 );
+ DEBUG_PRINT("v1 %f %f %f", x1, y1, z1);
+ DEBUG_PRINT("v2 %f %f %f", x2, y2, z2);
+ DEBUG_PRINT("v3 %f %f %f", x3, y3, z3);
surface->isValid = 0;
return;
}
@@ -196,59 +209,62 @@ static void engine_surface_from_lib_surface( struct SM64SurfaceCollisionData *su
surface->room = 0;
surface->type = type;
- surface->flags = (s8) flags;
+ surface->flags = (s8)flags;
surface->terrain = libSurf->terrain;
- if (hasForce) {
+ if (hasForce)
+ {
surface->force = force;
- } else {
+ }
+ else
+ {
surface->force = 0;
}
surface->isValid = 1;
}
-uint32_t loaded_surface_iter_group_count( void )
+uint32_t loaded_surface_iter_group_count(void)
{
return 1 + s_surface_object_count;
}
-uint32_t loaded_surface_iter_group_size( uint32_t groupIndex )
+uint32_t loaded_surface_iter_group_size(uint32_t groupIndex)
{
- if( groupIndex == 0 )
+ if (groupIndex == 0)
return s_static_surface_count;
- return s_surface_object_list[ groupIndex - 1 ].surfaceCount;
+ return s_surface_object_list[groupIndex - 1].surfaceCount;
}
-struct SM64SurfaceCollisionData *loaded_surface_iter_get_at_index( uint32_t groupIndex, uint32_t surfaceIndex )
+struct SM64SurfaceCollisionData *loaded_surface_iter_get_at_index(uint32_t groupIndex, uint32_t surfaceIndex)
{
- if( groupIndex == 0 )
- return &s_static_surface_list[ surfaceIndex ];
+ if (groupIndex == 0)
+ return &s_static_surface_list[surfaceIndex];
- return &s_surface_object_list[ groupIndex - 1 ].engineSurfaces[ surfaceIndex ];
+ return &s_surface_object_list[groupIndex - 1].engineSurfaces[surfaceIndex];
}
-void surfaces_load_static( const struct SM64Surface *surfaceArray, uint32_t numSurfaces )
+void surfaces_load_static(const struct SM64Surface *surfaceArray, uint32_t numSurfaces)
{
- if( s_static_surface_list != NULL )
- free( s_static_surface_list );
+ if (s_static_surface_list != NULL)
+ free(s_static_surface_list);
s_static_surface_count = numSurfaces;
- s_static_surface_list = malloc( sizeof( struct SM64SurfaceCollisionData ) * numSurfaces );
+ s_static_surface_list = malloc(sizeof(struct SM64SurfaceCollisionData) * numSurfaces);
- for( int i = 0; i < numSurfaces; ++i )
- engine_surface_from_lib_surface( &s_static_surface_list[i], &surfaceArray[i], NULL );
+ for (int i = 0; i < numSurfaces; ++i)
+ engine_surface_from_lib_surface(&s_static_surface_list[i], &surfaceArray[i], NULL);
}
-uint32_t surfaces_load_object( const struct SM64SurfaceObject *surfaceObject )
+uint32_t surfaces_load_object(const struct SM64SurfaceObject *surfaceObject)
{
bool pickedOldIndex = false;
uint32_t idx = s_surface_object_count;
- for( int i = 0; i < s_surface_object_count; ++i )
+ for (int i = 0; i < s_surface_object_count; ++i)
{
- if( s_surface_object_list[i].surfaceCount == 0 )
+ if (s_surface_object_list[i].surfaceCount == 0)
{
pickedOldIndex = true;
idx = i;
@@ -256,41 +272,41 @@ uint32_t surfaces_load_object( const struct SM64SurfaceObject *surfaceObject )
}
}
- if( !pickedOldIndex )
+ if (!pickedOldIndex)
{
idx = s_surface_object_count;
s_surface_object_count++;
- s_surface_object_list = realloc( s_surface_object_list, s_surface_object_count * sizeof( struct LoadedSurfaceObject ));
+ s_surface_object_list = realloc(s_surface_object_list, s_surface_object_count * sizeof(struct LoadedSurfaceObject));
}
struct LoadedSurfaceObject *obj = &s_surface_object_list[idx];
obj->surfaceCount = surfaceObject->surfaceCount;
- obj->transform = malloc( sizeof( struct SM64SurfaceObjectTransform ));
- init_transform( obj->transform, &surfaceObject->transform );
+ obj->transform = malloc(sizeof(struct SM64SurfaceObjectTransform));
+ init_transform(obj->transform, &surfaceObject->transform);
- obj->libSurfaces = malloc( obj->surfaceCount * sizeof( struct SM64Surface ));
- memcpy( obj->libSurfaces, surfaceObject->surfaces, obj->surfaceCount * sizeof( struct SM64Surface ));
+ obj->libSurfaces = malloc(obj->surfaceCount * sizeof(struct SM64Surface));
+ memcpy(obj->libSurfaces, surfaceObject->surfaces, obj->surfaceCount * sizeof(struct SM64Surface));
- obj->engineSurfaces = malloc( obj->surfaceCount * sizeof( struct SM64SurfaceCollisionData ));
- for( int i = 0; i < obj->surfaceCount; ++i )
- engine_surface_from_lib_surface( &obj->engineSurfaces[i], &obj->libSurfaces[i], obj->transform );
+ obj->engineSurfaces = malloc(obj->surfaceCount * sizeof(struct SM64SurfaceCollisionData));
+ for (int i = 0; i < obj->surfaceCount; ++i)
+ engine_surface_from_lib_surface(&obj->engineSurfaces[i], &obj->libSurfaces[i], obj->transform);
return idx;
}
-void surfaces_unload_object( uint32_t objId )
+void surfaces_unload_object(uint32_t objId)
{
- if( objId >= s_surface_object_count || s_surface_object_list[objId].surfaceCount == 0 )
+ if (objId >= s_surface_object_count || s_surface_object_list[objId].surfaceCount == 0)
{
DEBUG_PRINT("Tried to unload non-existant surface object with ID: %u", objId);
return;
}
- free( s_surface_object_list[objId].transform );
- free( s_surface_object_list[objId].libSurfaces );
- free( s_surface_object_list[objId].engineSurfaces );
+ free(s_surface_object_list[objId].transform);
+ free(s_surface_object_list[objId].libSurfaces);
+ free(s_surface_object_list[objId].engineSurfaces);
s_surface_object_list[objId].surfaceCount = 0;
s_surface_object_list[objId].transform = NULL;
@@ -298,40 +314,40 @@ void surfaces_unload_object( uint32_t objId )
s_surface_object_list[objId].engineSurfaces = NULL;
}
-void surface_object_update_transform( uint32_t objId, const struct SM64ObjectTransform *newTransform )
+void surface_object_update_transform(uint32_t objId, const struct SM64ObjectTransform *newTransform)
{
- if( objId >= s_surface_object_count || s_surface_object_list[objId].surfaceCount == 0 )
+ if (objId >= s_surface_object_count || s_surface_object_list[objId].surfaceCount == 0)
{
DEBUG_PRINT("Tried to update non-existant surface object with ID: %u", objId);
return;
}
- update_transform( s_surface_object_list[objId].transform, newTransform );
- for( int i = 0; i < s_surface_object_list[objId].surfaceCount; ++i )
+ update_transform(s_surface_object_list[objId].transform, newTransform);
+ for (int i = 0; i < s_surface_object_list[objId].surfaceCount; ++i)
{
struct LoadedSurfaceObject *obj = &s_surface_object_list[objId];
- engine_surface_from_lib_surface( &obj->engineSurfaces[i], &obj->libSurfaces[i], obj->transform );
+ engine_surface_from_lib_surface(&obj->engineSurfaces[i], &obj->libSurfaces[i], obj->transform);
}
}
-struct SM64SurfaceObjectTransform *surfaces_object_get_transform_ptr( uint32_t objId )
+struct SM64SurfaceObjectTransform *surfaces_object_get_transform_ptr(uint32_t objId)
{
- if( objId >= s_surface_object_count || s_surface_object_list[objId].surfaceCount == 0 )
+ if (objId >= s_surface_object_count || s_surface_object_list[objId].surfaceCount == 0)
return NULL;
return s_surface_object_list[objId].transform;
}
-void surfaces_unload_all( void )
+void surfaces_unload_all(void)
{
- free( s_static_surface_list );
+ free(s_static_surface_list);
s_static_surface_count = 0;
s_static_surface_list = NULL;
- for( int i = 0; i < s_surface_object_count; ++i )
- surfaces_unload_object( i );
+ for (int i = 0; i < s_surface_object_count; ++i)
+ surfaces_unload_object(i);
- free( s_surface_object_list );
+ free(s_surface_object_list);
s_surface_object_count = 0;
s_surface_object_list = NULL;
}
diff --git a/src/load_surfaces.h b/src/load_surfaces.h
index 3e99743..5ad7863 100644
--- a/src/load_surfaces.h
+++ b/src/load_surfaces.h
@@ -3,13 +3,20 @@
#include "decomp/include/types.h"
#include "libsm64.h"
-extern uint32_t loaded_surface_iter_group_count( void );
-extern uint32_t loaded_surface_iter_group_size( uint32_t groupIndex );
-extern struct SM64SurfaceCollisionData *loaded_surface_iter_get_at_index( uint32_t groupIndex, uint32_t surfaceIndex );
+extern uint32_t loaded_surface_iter_group_count(void);
-extern void surfaces_load_static( const struct SM64Surface *surfaceArray, uint32_t numSurfaces );
-extern uint32_t surfaces_load_object( const struct SM64SurfaceObject *surfaceObject );
-extern void surface_object_update_transform( uint32_t objId, const struct SM64ObjectTransform *newTransform );
-extern struct SM64SurfaceObjectTransform *surfaces_object_get_transform_ptr( uint32_t objId );
-extern void surfaces_unload_object( uint32_t objId );
-extern void surfaces_unload_all( void );
\ No newline at end of file
+extern uint32_t loaded_surface_iter_group_size(uint32_t groupIndex);
+
+extern struct SM64SurfaceCollisionData *loaded_surface_iter_get_at_index(uint32_t groupIndex, uint32_t surfaceIndex);
+
+extern void surfaces_load_static(const struct SM64Surface *surfaceArray, uint32_t numSurfaces);
+
+extern uint32_t surfaces_load_object(const struct SM64SurfaceObject *surfaceObject);
+
+extern void surface_object_update_transform(uint32_t objId, const struct SM64ObjectTransform *newTransform);
+
+extern struct SM64SurfaceObjectTransform *surfaces_object_get_transform_ptr(uint32_t objId);
+
+extern void surfaces_unload_object(uint32_t objId);
+
+extern void surfaces_unload_all(void);
\ No newline at end of file
diff --git a/src/load_tex_data.c b/src/load_tex_data.c
index d1a25d6..0cbcabd 100644
--- a/src/load_tex_data.c
+++ b/src/load_tex_data.c
@@ -12,38 +12,38 @@
#define ATLAS_WIDTH (NUM_USED_TEXTURES * 64)
#define ATLAS_HEIGHT 64
-static void blt_image_to_atlas( rgba *img, int i, int w, int h, uint8_t *outTexture )
+static void blt_image_to_atlas(rgba *img, int i, int w, int h, uint8_t *outTexture)
{
- for( int iy = 0; iy < h; ++iy )
- for( int ix = 0; ix < w; ++ix )
- {
- int o = (ix + 64 * i) + iy * ATLAS_WIDTH;
- int q = ix + iy * w;
- outTexture[4*o + 0] = img[q].red;
- outTexture[4*o + 1] = img[q].green;
- outTexture[4*o + 2] = img[q].blue;
- outTexture[4*o + 3] = img[q].alpha;
- }
+ for (int iy = 0; iy < h; ++iy)
+ for (int ix = 0; ix < w; ++ix)
+ {
+ int o = ix + 64 * i + iy * ATLAS_WIDTH;
+ int q = ix + iy * w;
+ outTexture[4 * o + 0] = img[q].red;
+ outTexture[4 * o + 1] = img[q].green;
+ outTexture[4 * o + 2] = img[q].blue;
+ outTexture[4 * o + 3] = img[q].alpha;
+ }
}
-void load_mario_textures_from_rom( const uint8_t *rom, uint8_t *outTexture )
+void load_mario_textures_from_rom(const uint8_t *rom, uint8_t *outTexture)
{
- memset( outTexture, 0, 4 * ATLAS_WIDTH * ATLAS_HEIGHT );
+ memset(outTexture, 0, 4 * ATLAS_WIDTH * ATLAS_HEIGHT);
mio0_header_t head;
const uint8_t *in_buf = rom + MARIO_TEX_ROM_OFFSET;
- mio0_decode_header( in_buf, &head );
- uint8_t *out_buf = malloc( head.dest_size );
- mio0_decode( in_buf, out_buf, NULL );
+ mio0_decode_header(in_buf, &head);
+ uint8_t *out_buf = malloc(head.dest_size);
+ mio0_decode(in_buf, out_buf, NULL);
- for( int i = 0; i < NUM_USED_TEXTURES; ++i )
+ for (int i = 0; i < NUM_USED_TEXTURES; ++i)
{
uint8_t *raw = out_buf + mario_tex_offsets[i];
- rgba *img = raw2rgba( raw, mario_tex_widths[i], mario_tex_heights[i], 16 );
- blt_image_to_atlas( img, i, mario_tex_widths[i], mario_tex_heights[i], outTexture );
- free( img );
+ rgba *img = raw2rgba(raw, mario_tex_widths[i], mario_tex_heights[i], 16);
+ blt_image_to_atlas(img, i, mario_tex_widths[i], mario_tex_heights[i], outTexture);
+ free(img);
}
- free( out_buf );
+ free(out_buf);
}
\ No newline at end of file
diff --git a/src/load_tex_data.h b/src/load_tex_data.h
index d3f0ca5..c2bb918 100644
--- a/src/load_tex_data.h
+++ b/src/load_tex_data.h
@@ -27,8 +27,8 @@ enum MarioTextures
#define NUM_USED_TEXTURES 11
-static const int mario_tex_offsets[NUM_USED_TEXTURES] = { 144, 4240, 6288, 8336, 10384, 12432, 14480, 16528, 30864, 32912, 37008 };
-static const int mario_tex_widths [NUM_USED_TEXTURES] = { 64, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32 };
-static const int mario_tex_heights[NUM_USED_TEXTURES] = { 32, 32, 32, 32, 32, 32, 32, 32, 32, 64, 64 };
+static const int mario_tex_offsets[NUM_USED_TEXTURES] = {144, 4240, 6288, 8336, 10384, 12432, 14480, 16528, 30864, 32912, 37008};
+static const int mario_tex_widths[NUM_USED_TEXTURES] = {64, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32};
+static const int mario_tex_heights[NUM_USED_TEXTURES] = {32, 32, 32, 32, 32, 32, 32, 32, 32, 64, 64};
-extern void load_mario_textures_from_rom( const uint8_t *rom, uint8_t *outTexture );
\ No newline at end of file
+extern void load_mario_textures_from_rom(const uint8_t *rom, uint8_t *outTexture);
\ No newline at end of file
diff --git a/src/obj_pool.c b/src/obj_pool.c
index d771b26..46ba6c7 100644
--- a/src/obj_pool.c
+++ b/src/obj_pool.c
@@ -2,36 +2,36 @@
#include
-uint32_t obj_pool_alloc_index( struct ObjPool *pool, size_t size )
+uint32_t obj_pool_alloc_index(struct ObjPool *pool, size_t size)
{
- for( uint32_t i = 0; i < pool->size; ++i )
+ for (uint32_t i = 0; i < pool->size; ++i)
{
- if( pool->objects[i] == NULL )
+ if (pool->objects[i] == NULL)
{
- pool->objects[i] = malloc( size );
+ pool->objects[i] = malloc(size);
return i;
}
}
uint32_t i = pool->size;
pool->size++;
- pool->objects = realloc( pool->objects, pool->size * sizeof( void * ));
- pool->objects[i] = malloc( size );
+ pool->objects = realloc(pool->objects, pool->size * sizeof(void *));
+ pool->objects[i] = malloc(size);
return i;
}
-void obj_pool_free_index( struct ObjPool *pool, uint32_t index )
+void obj_pool_free_index(struct ObjPool *pool, uint32_t index)
{
- free( pool->objects[index] );
+ free(pool->objects[index]);
pool->objects[index] = NULL;
}
-void obj_pool_free_all( struct ObjPool *pool )
+void obj_pool_free_all(struct ObjPool *pool)
{
- for( uint32_t i = 0; i < pool->size; ++i )
- free( pool->objects[i] );
- free( pool->objects );
+ for (uint32_t i = 0; i < pool->size; ++i)
+ free(pool->objects[i]);
+ free(pool->objects);
pool->size = 0;
pool->objects = NULL;
-}
\ No newline at end of file
+}
diff --git a/src/obj_pool.h b/src/obj_pool.h
index e981791..9b6e262 100644
--- a/src/obj_pool.h
+++ b/src/obj_pool.h
@@ -9,6 +9,8 @@ struct ObjPool
void **objects;
};
-extern uint32_t obj_pool_alloc_index( struct ObjPool *pool, size_t size );
-extern void obj_pool_free_index( struct ObjPool *pool, uint32_t index );
-extern void obj_pool_free_all( struct ObjPool *pool );
\ No newline at end of file
+extern uint32_t obj_pool_alloc_index(struct ObjPool *pool, size_t size);
+
+extern void obj_pool_free_index(struct ObjPool *pool, uint32_t index);
+
+extern void obj_pool_free_all(struct ObjPool *pool);
diff --git a/src/play_sound.c b/src/play_sound.c
index 27af905..03f26dd 100644
--- a/src/play_sound.c
+++ b/src/play_sound.c
@@ -6,15 +6,18 @@
SM64PlaySoundFunctionPtr g_play_sound_func = NULL;
-extern void play_sound( uint32_t soundBits, f32 *pos ) {
- if ( g_is_audio_initialized ) {
- DEBUG_PRINT("$ play_sound(%d) request %d; pos %f %f %f\n", soundBits,sSoundRequestCount,pos[0],pos[1],pos[2]);
+extern void play_sound(uint32_t soundBits, f32 *pos)
+{
+ if (g_is_audio_initialized)
+ {
+ DEBUG_PRINT("$ play_sound(%d) request %d; pos %f %f %f\n", soundBits, sSoundRequestCount, pos[0], pos[1], pos[2]);
sSoundRequests[sSoundRequestCount].soundBits = soundBits;
sSoundRequests[sSoundRequestCount].position = pos;
sSoundRequestCount++;
}
- if ( g_play_sound_func ) {
+ if (g_play_sound_func)
+ {
g_play_sound_func(soundBits, pos);
}
}
\ No newline at end of file
diff --git a/src/play_sound.h b/src/play_sound.h
index ab486b3..609faf0 100644
--- a/src/play_sound.h
+++ b/src/play_sound.h
@@ -6,4 +6,4 @@
extern SM64PlaySoundFunctionPtr g_play_sound_func;
-extern void play_sound( uint32_t soundBits, f32 *pos );
\ No newline at end of file
+extern void play_sound(uint32_t soundBits, f32 *pos);
\ No newline at end of file
diff --git a/test/audio.cpp b/test/audio.cpp
index fae4574..49adfb0 100644
--- a/test/audio.cpp
+++ b/test/audio.cpp
@@ -5,73 +5,77 @@
#include
#include
-extern "C" {
-#include "../src/libsm64.h"
-#include "context.h"
+extern "C"
+{
+ #include "../src/libsm64.h"
+ #include "context.h"
}
static SDL_AudioDeviceID dev;
pthread_t gSoundThread;
+
long long timeInMilliseconds(void)
{
- struct timeval tv;
- gettimeofday(&tv, NULL);
+ struct timeval tv;
+ gettimeofday(&tv, nullptr);
- return(((long long)tv.tv_sec)*1000)+(tv.tv_usec/1000);
+ return (long long)tv.tv_sec * 1000 + tv.tv_usec / 1000;
}
-void* audio_thread(void* keepAlive)
+void *audio_thread(void *keepAlive)
{
- // from https://github.com/ckosmic/libsm64/blob/audio/src/libsm64.c#L535-L555
- // except keepAlive is a null pointer here, so don't use it
+ // from https://github.com/ckosmic/libsm64/blob/audio/src/libsm64.c#L535-L555
+ // except keepAlive is a null pointer here, so don't use it
- pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL);
- pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED,NULL);
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, nullptr);
+ pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, nullptr);
- long long currentTime = timeInMilliseconds();
- long long targetTime = 0;
- while(1)
- {
- //if(!*((bool*)keepAlive)) return NULL;
+ long long currentTime = timeInMilliseconds();
+ long long targetTime = 0;
+ while (1)
+ {
+ //if(!*((bool*)keepAlive)) return nullptr;
- int16_t audioBuffer[544 * 2 * 2];
- uint32_t numSamples = sm64_audio_tick(SDL_GetQueuedAudioSize(dev)/4, 1100, audioBuffer);
- if (SDL_GetQueuedAudioSize(dev)/4 < 6000)
- SDL_QueueAudio(dev, audioBuffer, numSamples * 2 * 4);
+ int16_t audioBuffer[544 * 2 * 2];
+ uint32_t numSamples = sm64_audio_tick(SDL_GetQueuedAudioSize(dev) / 4, 1100, audioBuffer);
+ if (SDL_GetQueuedAudioSize(dev) / 4 < 6000)
+ SDL_QueueAudio(dev, audioBuffer, numSamples * 2 * 4);
- targetTime = currentTime + 33;
- while (timeInMilliseconds() < targetTime)
- {
- usleep(100);
- //if(!*((bool*)keepAlive)) return NULL;
- }
- currentTime = timeInMilliseconds();
- }
+ targetTime = currentTime + 33;
+ while (timeInMilliseconds() < targetTime)
+ {
+ usleep(100);
+ //if(!*((bool*)keepAlive)) return nullptr;
+ }
+ currentTime = timeInMilliseconds();
+ }
}
void audio_init()
{
- if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
- fprintf(stderr, "SDL_InitSubSystem(SDL_INIT_AUDIO) failed: %s\n", SDL_GetError());
- return;
- }
+ if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
+ {
+ fprintf(stderr, "SDL_InitSubSystem(SDL_INIT_AUDIO) failed: %s\n", SDL_GetError());
+ return;
+ }
- SDL_AudioSpec want, have;
- SDL_zero(want);
- want.freq = 32000;
- want.format = AUDIO_S16;
- want.channels = 2;
- want.samples = 512;
- want.callback = NULL;
- dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0);
- if (dev == 0) {
- fprintf(stderr, "SDL_OpenAudio error: %s\n", SDL_GetError());
- return;
- }
- SDL_PauseAudioDevice(dev, 0);
+ SDL_AudioSpec want, have;
+ SDL_zero(want);
+ want.freq = 32000;
+ want.format = AUDIO_S16;
+ want.channels = 2;
+ want.samples = 512;
+ want.callback = nullptr;
+ dev = SDL_OpenAudioDevice(nullptr, 0, &want, &have, 0);
+ if (dev == 0)
+ {
+ fprintf(stderr, "SDL_OpenAudio error: %s\n", SDL_GetError());
+ return;
+ }
+ SDL_PauseAudioDevice(dev, 0);
- // it's best to run audio in a separate thread
- pthread_create(&gSoundThread, NULL, audio_thread, NULL);
+ // it's best to run audio in a separate thread
+ pthread_create(&gSoundThread, nullptr, audio_thread, nullptr);
}
diff --git a/test/cglm.h b/test/cglm.h
index 6bd11c9..34a37c4 100644
--- a/test/cglm.h
+++ b/test/cglm.h
@@ -12,150 +12,150 @@ typedef float vec3[3];
typedef float vec4[4];
typedef float mat4[4][4];
-static void
-glm_mat4_zero( mat4 m )
+static void glm_mat4_zero(mat4 m)
{
- memset( m, 0, sizeof(mat4) );
+ memset(m, 0, sizeof(mat4));
}
-static void
-glm_mat4_identity( mat4 m )
+static void glm_mat4_identity(mat4 m)
{
- glm_mat4_zero( m );
+ glm_mat4_zero(m);
m[0][0] = 1.0f;
m[1][1] = 1.0f;
m[2][2] = 1.0f;
m[3][3] = 1.0f;
}
-static void
-glm_vec4_scale(vec4 v, float s, vec4 dest) {
- dest[0] = v[0] * s;
- dest[1] = v[1] * s;
- dest[2] = v[2] * s;
- dest[3] = v[3] * s;
+static void glm_vec4_scale(vec4 v, float s, vec4 dest)
+{
+ dest[0] = v[0] * s;
+ dest[1] = v[1] * s;
+ dest[2] = v[2] * s;
+ dest[3] = v[3] * s;
}
-static void
-glm_vec4_add(vec4 a, vec4 b, vec4 dest) {
- dest[0] = a[0] + b[0];
- dest[1] = a[1] + b[1];
- dest[2] = a[2] + b[2];
- dest[3] = a[3] + b[3];
+static void glm_vec4_add(vec4 a, vec4 b, vec4 dest)
+{
+ dest[0] = a[0] + b[0];
+ dest[1] = a[1] + b[1];
+ dest[2] = a[2] + b[2];
+ dest[3] = a[3] + b[3];
}
-static void
-glm_vec3_scale(vec3 v, float s, vec3 dest) {
- dest[0] = v[0] * s;
- dest[1] = v[1] * s;
- dest[2] = v[2] * s;
+static void glm_vec3_scale(vec3 v, float s, vec3 dest)
+{
+ dest[0] = v[0] * s;
+ dest[1] = v[1] * s;
+ dest[2] = v[2] * s;
}
-static void
-glm_vec3_sub(vec3 a, vec3 b, vec3 dest) {
- dest[0] = a[0] - b[0];
- dest[1] = a[1] - b[1];
- dest[2] = a[2] - b[2];
+static void glm_vec3_sub(vec3 a, vec3 b, vec3 dest)
+{
+ dest[0] = a[0] - b[0];
+ dest[1] = a[1] - b[1];
+ dest[2] = a[2] - b[2];
}
-static float
-glm_vec3_dot(vec3 a, vec3 b) {
- return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
+static float glm_vec3_dot(vec3 a, vec3 b)
+{
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
}
-static float
-glm_vec3_norm2(vec3 v) {
- return glm_vec3_dot(v, v);
+static float glm_vec3_norm2(vec3 v)
+{
+ return glm_vec3_dot(v, v);
}
-static float
-glm_vec3_norm(vec3 v) {
- return sqrtf(glm_vec3_norm2(v));
+static float glm_vec3_norm(vec3 v)
+{
+ return sqrtf(glm_vec3_norm2(v));
}
-static void
-glm_vec3_normalize(vec3 v) {
- float norm;
+static void glm_vec3_normalize(vec3 v)
+{
+ float norm;
- norm = glm_vec3_norm(v);
+ norm = glm_vec3_norm(v);
- if (norm == 0.0f) {
- v[0] = v[1] = v[2] = 0.0f;
- return;
- }
+ if (norm == 0.0f)
+ {
+ v[0] = v[1] = v[2] = 0.0f;
+ return;
+ }
- glm_vec3_scale(v, 1.0f / norm, v);
+ glm_vec3_scale(v, 1.0f / norm, v);
}
-static void
-glm_vec3_cross(vec3 a, vec3 b, vec3 dest) {
- /* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */
- dest[0] = a[1] * b[2] - a[2] * b[1];
- dest[1] = a[2] * b[0] - a[0] * b[2];
- dest[2] = a[0] * b[1] - a[1] * b[0];
+static void glm_vec3_cross(vec3 a, vec3 b, vec3 dest)
+{
+ /* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */
+ dest[0] = a[1] * b[2] - a[2] * b[1];
+ dest[1] = a[2] * b[0] - a[0] * b[2];
+ dest[2] = a[0] * b[1] - a[1] * b[0];
}
-static void
-glm_vec3_crossn(vec3 a, vec3 b, vec3 dest) {
- glm_vec3_cross(a, b, dest);
- glm_vec3_normalize(dest);
+static void glm_vec3_crossn(vec3 a, vec3 b, vec3 dest)
+{
+ glm_vec3_cross(a, b, dest);
+ glm_vec3_normalize(dest);
}
-static void
-glm_perspective(float fovy,
- float aspect,
- float nearVal,
- float farVal,
- mat4 dest) {
- float f, fn;
+static void glm_perspective(
+ float fovy,
+ float aspect,
+ float nearVal,
+ float farVal,
+ mat4 dest)
+{
+ float f, fn;
- glm_mat4_zero(dest);
+ glm_mat4_zero(dest);
- f = 1.0f / tanf(fovy * 0.5f);
- fn = 1.0f / (nearVal - farVal);
+ f = 1.0f / tanf(fovy * 0.5f);
+ fn = 1.0f / (nearVal - farVal);
- dest[0][0] = f / aspect;
- dest[1][1] = f;
- dest[2][2] = (nearVal + farVal) * fn;
- dest[2][3] =-1.0f;
- dest[3][2] = 2.0f * nearVal * farVal * fn;
+ dest[0][0] = f / aspect;
+ dest[1][1] = f;
+ dest[2][2] = (nearVal + farVal) * fn;
+ dest[2][3] = -1.0f;
+ dest[3][2] = 2.0f * nearVal * farVal * fn;
}
-static void
-glm_translate(mat4 m, vec3 v) {
- vec4 v1, v2, v3;
+static void glm_translate(mat4 m, vec3 v)
+{
+ vec4 v1, v2, v3;
- glm_vec4_scale(m[0], v[0], v1);
- glm_vec4_scale(m[1], v[1], v2);
- glm_vec4_scale(m[2], v[2], v3);
+ glm_vec4_scale(m[0], v[0], v1);
+ glm_vec4_scale(m[1], v[1], v2);
+ glm_vec4_scale(m[2], v[2], v3);
- glm_vec4_add(v1, m[3], m[3]);
- glm_vec4_add(v2, m[3], m[3]);
- glm_vec4_add(v3, m[3], m[3]);
+ glm_vec4_add(v1, m[3], m[3]);
+ glm_vec4_add(v2, m[3], m[3]);
+ glm_vec4_add(v3, m[3], m[3]);
}
-static void
-glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest) {
- vec3 f, u, s;
+static void glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest)
+{
+ vec3 f, u, s;
- glm_vec3_sub(center, eye, f);
- glm_vec3_normalize(f);
+ glm_vec3_sub(center, eye, f);
+ glm_vec3_normalize(f);
- glm_vec3_crossn(f, up, s);
- glm_vec3_cross(s, f, u);
+ glm_vec3_crossn(f, up, s);
+ glm_vec3_cross(s, f, u);
- dest[0][0] = s[0];
- dest[0][1] = u[0];
- dest[0][2] =-f[0];
- dest[1][0] = s[1];
- dest[1][1] = u[1];
- dest[1][2] =-f[1];
- dest[2][0] = s[2];
- dest[2][1] = u[2];
- dest[2][2] =-f[2];
- dest[3][0] =-glm_vec3_dot(s, eye);
- dest[3][1] =-glm_vec3_dot(u, eye);
- dest[3][2] = glm_vec3_dot(f, eye);
- dest[0][3] = dest[1][3] = dest[2][3] = 0.0f;
- dest[3][3] = 1.0f;
+ dest[0][0] = s[0];
+ dest[0][1] = u[0];
+ dest[0][2] = -f[0];
+ dest[1][0] = s[1];
+ dest[1][1] = u[1];
+ dest[1][2] = -f[1];
+ dest[2][0] = s[2];
+ dest[2][1] = u[2];
+ dest[2][2] = -f[2];
+ dest[3][0] = -glm_vec3_dot(s, eye);
+ dest[3][1] = -glm_vec3_dot(u, eye);
+ dest[3][2] = glm_vec3_dot(f, eye);
+ dest[0][3] = dest[1][3] = dest[2][3] = 0.0f;
+ dest[3][3] = 1.0f;
}
\ No newline at end of file
diff --git a/test/context.c b/test/context.c
index 938114c..f0ce831 100644
--- a/test/context.c
+++ b/test/context.c
@@ -8,106 +8,105 @@ static SDL_GameController *s_controller;
int WINDOW_WIDTH;
int WINDOW_HEIGHT;
-void context_init( const char *title, int width, int height, int major, int minor )
+void context_init(const char *title, int width, int height, int major, int minor)
{
- if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK ) < 0 ) goto err;
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) goto err;
- int profile = (major < 3) ? SDL_GL_CONTEXT_PROFILE_COMPATIBILITY : SDL_GL_CONTEXT_PROFILE_CORE;
+ int profile = major < 3 ? SDL_GL_CONTEXT_PROFILE_COMPATIBILITY : SDL_GL_CONTEXT_PROFILE_CORE;
- SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, major );
- SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, minor );
- SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, profile );
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile);
WINDOW_WIDTH = width;
WINDOW_HEIGHT = height;
- s_sdlWindow = SDL_CreateWindow(
+ s_sdlWindow = SDL_CreateWindow(
title,
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
width, height,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE
);
- if( !s_sdlWindow ) goto err;
+ if (!s_sdlWindow) goto err;
- s_sdlGlContext = SDL_GL_CreateContext( s_sdlWindow );
- SDL_GL_SetSwapInterval( 1 );
+ s_sdlGlContext = SDL_GL_CreateContext(s_sdlWindow);
+ SDL_GL_SetSwapInterval(1);
- if( !s_sdlGlContext ) goto err;
+ if (!s_sdlGlContext) goto err;
#ifndef __APPLE__
- glewExperimental = GL_TRUE;
- const GLenum glewInitResult = glewInit();
- if( glewInitResult != GLEW_OK ) goto err;
+ glewExperimental = GL_TRUE;
+ const GLenum glewInitResult = glewInit();
+ if (glewInitResult != GLEW_OK) goto err;
#endif
s_controller = NULL;
- for( int i = 0; i < SDL_NumJoysticks(); ++i )
+ for (int i = 0; i < SDL_NumJoysticks(); ++i)
{
- if( ! SDL_IsGameController( i ) ) continue;
- s_controller = SDL_GameControllerOpen( i );
- printf( "Using game controller: %s", SDL_GameControllerName( s_controller ) );
- if( s_controller ) break;
+ if (!SDL_IsGameController(i)) continue;
+ s_controller = SDL_GameControllerOpen(i);
+ printf("Using game controller: %s", SDL_GameControllerName(s_controller));
+ if (s_controller) break;
}
return;
-err:
- SDL_GL_DeleteContext( s_sdlGlContext );
- SDL_DestroyWindow( s_sdlWindow );
+err: SDL_GL_DeleteContext(s_sdlGlContext);
+ SDL_DestroyWindow(s_sdlWindow);
SDL_Quit();
}
-SDL_GameController *context_get_controller( void )
+SDL_GameController *context_get_controller(void)
{
return s_controller;
}
-bool context_flip_frame_poll_events( void )
+bool context_flip_frame_poll_events(void)
{
bool still_running = true;
- SDL_GL_SwapWindow( s_sdlWindow );
+ SDL_GL_SwapWindow(s_sdlWindow);
SDL_Event event;
- while( SDL_PollEvent( &event ) )
+ while (SDL_PollEvent(&event))
{
- switch( event.type )
+ switch (event.type)
{
- case SDL_QUIT:
- still_running = false;
- break;
-
- case SDL_KEYDOWN:
- if( event.key.keysym.sym == SDLK_ESCAPE )
+ case SDL_QUIT:
still_running = false;
+ break;
- case SDL_WINDOWEVENT:
- if( event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED )
- {
- WINDOW_WIDTH = event.window.data1;
- WINDOW_HEIGHT = event.window.data2;
- glViewport( 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT );
- }
- break;
+ case SDL_KEYDOWN:
+ if (event.key.keysym.sym == SDLK_ESCAPE)
+ still_running = false;
+
+ case SDL_WINDOWEVENT:
+ if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
+ {
+ WINDOW_WIDTH = event.window.data1;
+ WINDOW_HEIGHT = event.window.data2;
+ glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
+ }
+ break;
}
}
return still_running;
}
-void context_terminate( void )
+void context_terminate(void)
{
- if( !s_sdlWindow )
+ if (!s_sdlWindow)
return;
- if( s_controller )
- SDL_GameControllerClose( s_controller );
+ if (s_controller)
+ SDL_GameControllerClose(s_controller);
- SDL_GL_DeleteContext( s_sdlGlContext );
- SDL_DestroyWindow( s_sdlWindow );
+ SDL_GL_DeleteContext(s_sdlGlContext);
+ SDL_DestroyWindow(s_sdlWindow);
SDL_Quit();
s_sdlWindow = NULL;
diff --git a/test/context.h b/test/context.h
index 588e31f..5eb281c 100644
--- a/test/context.h
+++ b/test/context.h
@@ -17,7 +17,10 @@
extern int WINDOW_WIDTH;
extern int WINDOW_HEIGHT;
-extern void context_init( const char *title, int width, int height, int major, int minor );
-extern bool context_flip_frame_poll_events( void );
-extern SDL_GameController *context_get_controller( void );
-extern void context_terminate( void );
\ No newline at end of file
+extern void context_init(const char *title, int width, int height, int major, int minor);
+
+extern bool context_flip_frame_poll_events(void);
+
+extern SDL_GameController *context_get_controller(void);
+
+extern void context_terminate(void);
\ No newline at end of file
diff --git a/test/gl20/gl20_renderer.c b/test/gl20/gl20_renderer.c
index d50da28..55ea5ee 100644
--- a/test/gl20/gl20_renderer.c
+++ b/test/gl20/gl20_renderer.c
@@ -16,213 +16,220 @@ uint8_t *worldTextureRaw;
int worldTextureSize[2] = {256, 256};
float *worldUv;
-static void load_collision_mesh( CollisionMesh *mesh )
+static void load_collision_mesh(CollisionMesh *mesh)
{
- mesh->num_vertices = 3 * surfaces_count;
- mesh->position = malloc( sizeof( float ) * surfaces_count * 9 );
- mesh->normal = malloc( sizeof( float ) * surfaces_count * 9 );
- mesh->color = malloc( sizeof( float ) * surfaces_count * 9 );
- worldUv = malloc(sizeof(float) * surfaces_count * 6);
- mesh->index = malloc( sizeof( uint16_t ) * surfaces_count * 3 );
+ mesh->num_vertices = 3 * surfaces_count;
+ mesh->position = malloc(sizeof(float) * surfaces_count * 9);
+ mesh->normal = malloc(sizeof(float) * surfaces_count * 9);
+ mesh->color = malloc(sizeof(float) * surfaces_count * 9);
+ worldUv = malloc(sizeof(float) * surfaces_count * 6);
+ mesh->index = malloc(sizeof(uint16_t) * surfaces_count * 3);
- for( size_t i = 0; i < surfaces_count; ++i )
- {
- const struct SM64Surface *surf = &surfaces[i];
+ for (size_t i = 0; i < surfaces_count; ++i)
+ {
+ const struct SM64Surface *surf = &surfaces[i];
- float x1 = mesh->position[9*i+0] = surf->vertices[0][0];
- float y1 = mesh->position[9*i+1] = surf->vertices[0][1];
- float z1 = mesh->position[9*i+2] = surf->vertices[0][2];
- float x2 = mesh->position[9*i+3] = surf->vertices[1][0];
- float y2 = mesh->position[9*i+4] = surf->vertices[1][1];
- float z2 = mesh->position[9*i+5] = surf->vertices[1][2];
- float x3 = mesh->position[9*i+6] = surf->vertices[2][0];
- float y3 = mesh->position[9*i+7] = surf->vertices[2][1];
- float z3 = mesh->position[9*i+8] = surf->vertices[2][2];
+ float x1 = mesh->position[9 * i + 0] = surf->vertices[0][0];
+ float y1 = mesh->position[9 * i + 1] = surf->vertices[0][1];
+ float z1 = mesh->position[9 * i + 2] = surf->vertices[0][2];
+ float x2 = mesh->position[9 * i + 3] = surf->vertices[1][0];
+ float y2 = mesh->position[9 * i + 4] = surf->vertices[1][1];
+ float z2 = mesh->position[9 * i + 5] = surf->vertices[1][2];
+ float x3 = mesh->position[9 * i + 6] = surf->vertices[2][0];
+ float y3 = mesh->position[9 * i + 7] = surf->vertices[2][1];
+ float z3 = mesh->position[9 * i + 8] = surf->vertices[2][2];
- float nx = (y2 - y1) * (z3 - z2) - (z2 - z1) * (y3 - y2);
- float ny = (z2 - z1) * (x3 - x2) - (x2 - x1) * (z3 - z2);
- float nz = (x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2);
- float mag = sqrtf(nx * nx + ny * ny + nz * nz);
- nx /= mag;
- ny /= mag;
- nz /= mag;
+ float nx = (y2 - y1) * (z3 - z2) - (z2 - z1) * (y3 - y2);
+ float ny = (z2 - z1) * (x3 - x2) - (x2 - x1) * (z3 - z2);
+ float nz = (x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2);
+ float mag = sqrtf(nx * nx + ny * ny + nz * nz);
+ nx /= mag;
+ ny /= mag;
+ nz /= mag;
- mesh->normal[9*i+0] = nx;
- mesh->normal[9*i+1] = ny;
- mesh->normal[9*i+2] = nz;
- mesh->normal[9*i+3] = nx;
- mesh->normal[9*i+4] = ny;
- mesh->normal[9*i+5] = nz;
- mesh->normal[9*i+6] = nx;
- mesh->normal[9*i+7] = ny;
- mesh->normal[9*i+8] = nz;
+ mesh->normal[9 * i + 0] = nx;
+ mesh->normal[9 * i + 1] = ny;
+ mesh->normal[9 * i + 2] = nz;
+ mesh->normal[9 * i + 3] = nx;
+ mesh->normal[9 * i + 4] = ny;
+ mesh->normal[9 * i + 5] = nz;
+ mesh->normal[9 * i + 6] = nx;
+ mesh->normal[9 * i + 7] = ny;
+ mesh->normal[9 * i + 8] = nz;
- for (int j=0; j<9; j++)
- mesh->color[9*i+j] = (0.5 + 0.25 * 1) * (.5+.5*mesh->normal[9*i+j]);
+ for (int j = 0; j < 9; j++)
+ mesh->color[9 * i + j] = (0.5 + 0.25 * 1) * (.5 + .5 * mesh->normal[9 * i + j]);
- mesh->index[3*i+0] = 3*i+0;
- mesh->index[3*i+1] = 3*i+1;
- mesh->index[3*i+2] = 3*i+2;
- }
+ mesh->index[3 * i + 0] = 3 * i + 0;
+ mesh->index[3 * i + 1] = 3 * i + 1;
+ mesh->index[3 * i + 2] = 3 * i + 2;
+ }
- for( size_t i = 0; i < surfaces_count/2; i++ )
- {
- worldUv[12*i+0] = 0.f;
- worldUv[12*i+1] = 0.f;
- worldUv[12*i+2] = 4.f;
- worldUv[12*i+3] = 0.f;
- worldUv[12*i+4] = 0.f;
- worldUv[12*i+5] = 4.f;
+ for (size_t i = 0; i < surfaces_count / 2; i++)
+ {
+ worldUv[12 * i + 0] = 0.f;
+ worldUv[12 * i + 1] = 0.f;
+ worldUv[12 * i + 2] = 4.f;
+ worldUv[12 * i + 3] = 0.f;
+ worldUv[12 * i + 4] = 0.f;
+ worldUv[12 * i + 5] = 4.f;
- worldUv[12*i+6] = 0.f;
- worldUv[12*i+7] = 4.f;
- worldUv[12*i+8] = 4.f;
- worldUv[12*i+9] = 0.f;
- worldUv[12*i+10] = 0.f;
- worldUv[12*i+11] = 0.f;
- }
+ worldUv[12 * i + 6] = 0.f;
+ worldUv[12 * i + 7] = 4.f;
+ worldUv[12 * i + 8] = 4.f;
+ worldUv[12 * i + 9] = 0.f;
+ worldUv[12 * i + 10] = 0.f;
+ worldUv[12 * i + 11] = 0.f;
+ }
}
-static void load_mario_mesh( MarioMesh *mesh, struct SM64MarioGeometryBuffers *marioGeo )
+static void load_mario_mesh(MarioMesh *mesh, struct SM64MarioGeometryBuffers *marioGeo)
{
- mesh->index = malloc( 3 * SM64_GEO_MAX_TRIANGLES * sizeof(uint16_t) );
- for( int i = 0; i < 3 * SM64_GEO_MAX_TRIANGLES; ++i )
- mesh->index[i] = i;
+ mesh->index = malloc(3 * SM64_GEO_MAX_TRIANGLES * sizeof(uint16_t));
+ for (int i = 0; i < 3 * SM64_GEO_MAX_TRIANGLES; ++i)
+ mesh->index[i] = i;
- mesh->num_vertices = 3 * SM64_GEO_MAX_TRIANGLES;
+ mesh->num_vertices = 3 * SM64_GEO_MAX_TRIANGLES;
}
-static void update_mario_mesh( MarioMesh *mesh, struct SM64MarioGeometryBuffers *marioGeo )
+static void update_mario_mesh(MarioMesh *mesh, struct SM64MarioGeometryBuffers *marioGeo)
{
- if( mesh->index == NULL )
- load_mario_mesh( mesh, marioGeo );
+ if (mesh->index == NULL)
+ load_mario_mesh(mesh, marioGeo);
- mesh->num_vertices = 3 * marioGeo->numTrianglesUsed;
+ mesh->num_vertices = 3 * marioGeo->numTrianglesUsed;
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_NORMAL_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_NORMAL_ARRAY);
+ glEnableClientState(GL_COLOR_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, marioGeo->position);
- glNormalPointer(GL_FLOAT, 0, marioGeo->normal);
- glColorPointer(3, GL_FLOAT, 0, marioGeo->color);
- glTexCoordPointer(2, GL_FLOAT, 0, marioGeo->uv);
+ glVertexPointer(3, GL_FLOAT, 0, marioGeo->position);
+ glNormalPointer(GL_FLOAT, 0, marioGeo->normal);
+ glColorPointer(3, GL_FLOAT, 0, marioGeo->color);
+ glTexCoordPointer(2, GL_FLOAT, 0, marioGeo->uv);
}
static void gl20_init(RenderState *renderState, uint8_t *marioTexture)
{
- load_collision_mesh( &renderState->collision );
+ load_collision_mesh(&renderState->collision);
- glEnable( GL_CULL_FACE );
- glCullFace( GL_BACK );
- glClearColor( 0.2f, 0.2f, 0.2f, 1.0f );
- glDepthMask( GL_TRUE );
- glDepthFunc( GL_LEQUAL );
- glEnable( GL_DEPTH_TEST );
- glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
- glEnable( GL_BLEND );
- glColor4f(1,1,1,1);
+ glEnable(GL_CULL_FACE);
+ glCullFace(GL_BACK);
+ glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
+ glDepthMask(GL_TRUE);
+ glDepthFunc(GL_LEQUAL);
+ glEnable(GL_DEPTH_TEST);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+ glColor4f(1, 1, 1, 1);
- glGenTextures( 1, &renderState->mario_texture );
- glBindTexture( GL_TEXTURE_2D, renderState->mario_texture );
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SM64_TEXTURE_WIDTH, SM64_TEXTURE_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, marioTexture);
+ glGenTextures(1, &renderState->mario_texture);
+ glBindTexture(GL_TEXTURE_2D, renderState->mario_texture);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SM64_TEXTURE_WIDTH, SM64_TEXTURE_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, marioTexture);
- // make a custom world texture programatically
- worldTextureRaw = (uint8_t*)malloc(worldTextureSize[0] * worldTextureSize[1] * 4);
- memset(worldTextureRaw, 255, worldTextureSize[0] * worldTextureSize[1] * 4);
+ // make a custom world texture programatically
+ worldTextureRaw = (uint8_t *)malloc(worldTextureSize[0] * worldTextureSize[1] * 4);
+ memset(worldTextureRaw, 255, worldTextureSize[0] * worldTextureSize[1] * 4);
- for (int y=0; yposition, (vec3){0,1,0}, view );
- glm_mat4_identity( model );
+ mat4 model, view, projection;
+ glm_perspective(45.0f, (float)WINDOW_WIDTH / (float)WINDOW_HEIGHT, 100.0f, 20000.0f, projection);
+ glm_translate(view, (float *)camPos);
+ glm_lookat((float *)camPos, (float *)marioState->position, (vec3)
+ {
+ 0, 1, 0
+ }
+ ,
+ view
+ )
+ ;
+ glm_mat4_identity(model);
- glMatrixMode(GL_PROJECTION);
- glLoadMatrixf((GLfloat*)projection);
+ glMatrixMode(GL_PROJECTION);
+ glLoadMatrixf((GLfloat *)projection);
- glMatrixMode(GL_MODELVIEW);
- glLoadMatrixf((GLfloat*)view);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadMatrixf((GLfloat *)view);
- glEnable(GL_TEXTURE_2D);
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+ glEnable(GL_TEXTURE_2D);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// draw world
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_NORMAL_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_NORMAL_ARRAY);
+ glEnableClientState(GL_COLOR_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, renderState->collision.position);
- glNormalPointer(GL_FLOAT, 0, renderState->collision.normal);
- glColorPointer(3, GL_FLOAT, 0, renderState->collision.color);
- glTexCoordPointer(2, GL_FLOAT, 0, worldUv);
+ glVertexPointer(3, GL_FLOAT, 0, renderState->collision.position);
+ glNormalPointer(GL_FLOAT, 0, renderState->collision.normal);
+ glColorPointer(3, GL_FLOAT, 0, renderState->collision.color);
+ glTexCoordPointer(2, GL_FLOAT, 0, worldUv);
- glBindTexture(GL_TEXTURE_2D, worldTexture);
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glDrawElements(GL_TRIANGLES, renderState->collision.num_vertices, GL_UNSIGNED_SHORT, renderState->collision.index);
+ glBindTexture(GL_TEXTURE_2D, worldTexture);
+ glMatrixMode(GL_TEXTURE);
+ glLoadIdentity();
+ glDrawElements(GL_TRIANGLES, renderState->collision.num_vertices, GL_UNSIGNED_SHORT, renderState->collision.index);
- // create lighting on the scene
- GLfloat light_position[] = { camPos[0], camPos[1], camPos[2], 1 };
- GLfloat light_diffuse[] = { 0.6f, 0.6f, 0.6f, 1 };
- GLfloat light_model[] = { 0.5f, 0.5f, 0.5f, 1 };
- glLightfv(GL_LIGHT0, GL_POSITION, light_position);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
- glLightModelfv(GL_LIGHT_MODEL_AMBIENT, light_model);
- glShadeModel(GL_SMOOTH);
- glEnable(GL_COLOR_MATERIAL);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
+ // create lighting on the scene
+ GLfloat light_position[] = {camPos[0], camPos[1], camPos[2], 1};
+ GLfloat light_diffuse[] = {0.6f, 0.6f, 0.6f, 1};
+ GLfloat light_model[] = {0.5f, 0.5f, 0.5f, 1};
+ glLightfv(GL_LIGHT0, GL_POSITION, light_position);
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, light_model);
+ glShadeModel(GL_SMOOTH);
+ glEnable(GL_COLOR_MATERIAL);
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT0);
- // first, draw geometry without Mario's texture.
- glBindTexture(GL_TEXTURE_2D, 0);
- update_mario_mesh( &renderState->mario, marioGeo );
- uint32_t triangleSize = renderState->mario.num_vertices;
+ // first, draw geometry without Mario's texture.
+ glBindTexture(GL_TEXTURE_2D, 0);
+ update_mario_mesh(&renderState->mario, marioGeo);
+ uint32_t triangleSize = renderState->mario.num_vertices;
- glDrawElements(GL_TRIANGLES, triangleSize, GL_UNSIGNED_SHORT, renderState->mario.index);
+ glDrawElements(GL_TRIANGLES, triangleSize, GL_UNSIGNED_SHORT, renderState->mario.index);
- // now disable the color array and enable the texture.
- glDisableClientState(GL_COLOR_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glBindTexture(GL_TEXTURE_2D, renderState->mario_texture);
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
+ // now disable the color array and enable the texture.
+ glDisableClientState(GL_COLOR_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glBindTexture(GL_TEXTURE_2D, renderState->mario_texture);
+ glMatrixMode(GL_TEXTURE);
+ glLoadIdentity();
- glDrawElements(GL_TRIANGLES, triangleSize, GL_UNSIGNED_SHORT, renderState->mario.index);
+ glDrawElements(GL_TRIANGLES, triangleSize, GL_UNSIGNED_SHORT, renderState->mario.index);
- glDisable(GL_TEXTURE_2D);
- glDisable(GL_LIGHTING);
+ glDisable(GL_TEXTURE_2D);
+ glDisable(GL_LIGHTING);
}
struct Renderer gl20_renderer = {
diff --git a/test/gl33core/gl33core_renderer.c b/test/gl33core/gl33core_renderer.c
index fb6d24f..a413907 100644
--- a/test/gl33core/gl33core_renderer.c
+++ b/test/gl33core/gl33core_renderer.c
@@ -9,149 +9,147 @@
#include "../level.h"
static const char *MARIO_SHADER =
-"\n uniform mat4 view;"
-"\n uniform mat4 projection;"
-"\n uniform sampler2D marioTex;"
-"\n "
-"\n v2f vec3 v_color;"
-"\n v2f vec3 v_normal;"
-"\n v2f vec3 v_light;"
-"\n v2f vec2 v_uv;"
-"\n "
-"\n #ifdef VERTEX"
-"\n "
-"\n layout(location = 0) in vec3 position;"
-"\n layout(location = 1) in vec3 normal;"
-"\n layout(location = 2) in vec3 color;"
-"\n layout(location = 3) in vec2 uv;"
-"\n "
-"\n void main()"
-"\n {"
-"\n v_color = color;"
-"\n v_normal = normal;"
-"\n v_light = transpose( mat3( view )) * normalize( vec3( 1 ));"
-"\n v_uv = uv;"
-"\n "
-"\n gl_Position = projection * view * vec4( position, 1. );"
-"\n }"
-"\n "
-"\n #endif"
-"\n #ifdef FRAGMENT"
-"\n "
-"\n out vec4 color;"
-"\n "
-"\n void main() "
-"\n {"
-"\n float light = .5 + .5 * clamp( dot( v_normal, v_light ), 0., 1. );"
-"\n vec4 texColor = texture2D( marioTex, v_uv );"
-"\n vec3 mainColor = mix( v_color, texColor.rgb, texColor.a ); // v_uv.x >= 0. ? texColor.a : 0. );"
-"\n color = vec4( mainColor * light, 1 );"
-"\n }"
-"\n "
-"\n #endif"
-;
+ "\n uniform mat4 view;"
+ "\n uniform mat4 projection;"
+ "\n uniform sampler2D marioTex;"
+ "\n "
+ "\n v2f vec3 v_color;"
+ "\n v2f vec3 v_normal;"
+ "\n v2f vec3 v_light;"
+ "\n v2f vec2 v_uv;"
+ "\n "
+ "\n #ifdef VERTEX"
+ "\n "
+ "\n layout(location = 0) in vec3 position;"
+ "\n layout(location = 1) in vec3 normal;"
+ "\n layout(location = 2) in vec3 color;"
+ "\n layout(location = 3) in vec2 uv;"
+ "\n "
+ "\n void main()"
+ "\n {"
+ "\n v_color = color;"
+ "\n v_normal = normal;"
+ "\n v_light = transpose( mat3( view )) * normalize( vec3( 1 ));"
+ "\n v_uv = uv;"
+ "\n "
+ "\n gl_Position = projection * view * vec4( position, 1. );"
+ "\n }"
+ "\n "
+ "\n #endif"
+ "\n #ifdef FRAGMENT"
+ "\n "
+ "\n out vec4 color;"
+ "\n "
+ "\n void main() "
+ "\n {"
+ "\n float light = .5 + .5 * clamp( dot( v_normal, v_light ), 0., 1. );"
+ "\n vec4 texColor = texture2D( marioTex, v_uv );"
+ "\n vec3 mainColor = mix( v_color, texColor.rgb, texColor.a ); // v_uv.x >= 0. ? texColor.a : 0. );"
+ "\n color = vec4( mainColor * light, 1 );"
+ "\n }"
+ "\n "
+ "\n #endif";
static const char *WORLD_SHADER =
-"\n uniform mat4 model;"
-"\n uniform mat4 view;"
-"\n uniform mat4 projection;"
-"\n uniform sampler2D tex;"
-"\n "
-"\n v2f vec3 v_normal;"
-"\n v2f vec3 v_worldPos;"
-"\n "
-"\n #ifdef VERTEX"
-"\n "
-"\n layout(location = 0) in vec3 position;"
-"\n layout(location = 1) in vec3 normal;"
-"\n "
-"\n void main()"
-"\n {"
-"\n v_normal = inverse(mat3(model)) * normal;"
-"\n vec4 worldPos4 = model * vec4(position, 1.);"
-"\n v_worldPos = worldPos4.xyz;"
-"\n gl_Position = projection * view * worldPos4;"
-"\n }"
-"\n "
-"\n #endif"
-"\n #ifdef FRAGMENT"
-"\n "
-"\n vec3 tri( vec3 x )"
-"\n {"
-"\n return abs(x-floor(x)-.5);"
-"\n } "
-"\n float surfFunc( vec3 p )"
-"\n {"
-"\n float n = dot(tri(p*.15 + tri(p.yzx*.075)), vec3(.444));"
-"\n p = p*1.5773 - n;"
-"\n p.yz = vec2(p.y + p.z, p.z - p.y) * .866;"
-"\n p.xz = vec2(p.x + p.z, p.z - p.x) * .866;"
-"\n n += dot(tri(p*.225 + tri(p.yzx*.1125)), vec3(.222)); "
-"\n return abs(n-.5)*1.9 + (1.-abs(sin(n*9.)))*.05;"
-"\n }"
-"\n "
-"\n const vec3 light_x = vec3(-1.0, 0.4, 0.9);"
-"\n "
-"\n out vec4 color;"
-"\n "
-"\n void main() "
-"\n {"
-"\n float surfy = surfFunc( v_worldPos / 50. );"
-"\n float brightness = smoothstep( .2, .3, surfy );"
-"\n "
-"\n color = vec4( (0.5 + 0.25 * brightness) * (.5+.5*v_normal), 1 );"
-"\n }"
-"\n "
-"\n #endif"
-;
+ "\n uniform mat4 model;"
+ "\n uniform mat4 view;"
+ "\n uniform mat4 projection;"
+ "\n uniform sampler2D tex;"
+ "\n "
+ "\n v2f vec3 v_normal;"
+ "\n v2f vec3 v_worldPos;"
+ "\n "
+ "\n #ifdef VERTEX"
+ "\n "
+ "\n layout(location = 0) in vec3 position;"
+ "\n layout(location = 1) in vec3 normal;"
+ "\n "
+ "\n void main()"
+ "\n {"
+ "\n v_normal = inverse(mat3(model)) * normal;"
+ "\n vec4 worldPos4 = model * vec4(position, 1.);"
+ "\n v_worldPos = worldPos4.xyz;"
+ "\n gl_Position = projection * view * worldPos4;"
+ "\n }"
+ "\n "
+ "\n #endif"
+ "\n #ifdef FRAGMENT"
+ "\n "
+ "\n vec3 tri( vec3 x )"
+ "\n {"
+ "\n return abs(x-floor(x)-.5);"
+ "\n } "
+ "\n float surfFunc( vec3 p )"
+ "\n {"
+ "\n float n = dot(tri(p*.15 + tri(p.yzx*.075)), vec3(.444));"
+ "\n p = p*1.5773 - n;"
+ "\n p.yz = vec2(p.y + p.z, p.z - p.y) * .866;"
+ "\n p.xz = vec2(p.x + p.z, p.z - p.x) * .866;"
+ "\n n += dot(tri(p*.225 + tri(p.yzx*.1125)), vec3(.222)); "
+ "\n return abs(n-.5)*1.9 + (1.-abs(sin(n*9.)))*.05;"
+ "\n }"
+ "\n "
+ "\n const vec3 light_x = vec3(-1.0, 0.4, 0.9);"
+ "\n "
+ "\n out vec4 color;"
+ "\n "
+ "\n void main() "
+ "\n {"
+ "\n float surfy = surfFunc( v_worldPos / 50. );"
+ "\n float brightness = smoothstep( .2, .3, surfy );"
+ "\n "
+ "\n color = vec4( (0.5 + 0.25 * brightness) * (.5+.5*v_normal), 1 );"
+ "\n }"
+ "\n "
+ "\n #endif";
-static void load_collision_mesh( CollisionMesh *mesh )
+static void load_collision_mesh(CollisionMesh *mesh)
{
- mesh->num_vertices = 3 * surfaces_count;
- mesh->position = malloc( sizeof( float ) * surfaces_count * 9 );
- mesh->normal = malloc( sizeof( float ) * surfaces_count * 9 );
- mesh->index = malloc( sizeof( uint16_t ) * surfaces_count * 3 );
+ mesh->num_vertices = 3 * surfaces_count;
+ mesh->position = malloc(sizeof(float) * surfaces_count * 9);
+ mesh->normal = malloc(sizeof(float) * surfaces_count * 9);
+ mesh->index = malloc(sizeof(uint16_t) * surfaces_count * 3);
- for( size_t i = 0; i < surfaces_count; ++i )
- {
- const struct SM64Surface *surf = &surfaces[i];
+ for (size_t i = 0; i < surfaces_count; ++i)
+ {
+ const struct SM64Surface *surf = &surfaces[i];
- float x1 = mesh->position[9*i+0] = surf->vertices[0][0];
- float y1 = mesh->position[9*i+1] = surf->vertices[0][1];
- float z1 = mesh->position[9*i+2] = surf->vertices[0][2];
- float x2 = mesh->position[9*i+3] = surf->vertices[1][0];
- float y2 = mesh->position[9*i+4] = surf->vertices[1][1];
- float z2 = mesh->position[9*i+5] = surf->vertices[1][2];
- float x3 = mesh->position[9*i+6] = surf->vertices[2][0];
- float y3 = mesh->position[9*i+7] = surf->vertices[2][1];
- float z3 = mesh->position[9*i+8] = surf->vertices[2][2];
+ float x1 = mesh->position[9 * i + 0] = surf->vertices[0][0];
+ float y1 = mesh->position[9 * i + 1] = surf->vertices[0][1];
+ float z1 = mesh->position[9 * i + 2] = surf->vertices[0][2];
+ float x2 = mesh->position[9 * i + 3] = surf->vertices[1][0];
+ float y2 = mesh->position[9 * i + 4] = surf->vertices[1][1];
+ float z2 = mesh->position[9 * i + 5] = surf->vertices[1][2];
+ float x3 = mesh->position[9 * i + 6] = surf->vertices[2][0];
+ float y3 = mesh->position[9 * i + 7] = surf->vertices[2][1];
+ float z3 = mesh->position[9 * i + 8] = surf->vertices[2][2];
- float nx = (y2 - y1) * (z3 - z2) - (z2 - z1) * (y3 - y2);
- float ny = (z2 - z1) * (x3 - x2) - (x2 - x1) * (z3 - z2);
- float nz = (x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2);
- float mag = sqrtf(nx * nx + ny * ny + nz * nz);
- nx /= mag;
- ny /= mag;
- nz /= mag;
+ float nx = (y2 - y1) * (z3 - z2) - (z2 - z1) * (y3 - y2);
+ float ny = (z2 - z1) * (x3 - x2) - (x2 - x1) * (z3 - z2);
+ float nz = (x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2);
+ float mag = sqrtf(nx * nx + ny * ny + nz * nz);
+ nx /= mag;
+ ny /= mag;
+ nz /= mag;
- mesh->normal[9*i+0] = nx;
- mesh->normal[9*i+1] = ny;
- mesh->normal[9*i+2] = nz;
- mesh->normal[9*i+3] = nx;
- mesh->normal[9*i+4] = ny;
- mesh->normal[9*i+5] = nz;
- mesh->normal[9*i+6] = nx;
- mesh->normal[9*i+7] = ny;
- mesh->normal[9*i+8] = nz;
+ mesh->normal[9 * i + 0] = nx;
+ mesh->normal[9 * i + 1] = ny;
+ mesh->normal[9 * i + 2] = nz;
+ mesh->normal[9 * i + 3] = nx;
+ mesh->normal[9 * i + 4] = ny;
+ mesh->normal[9 * i + 5] = nz;
+ mesh->normal[9 * i + 6] = nx;
+ mesh->normal[9 * i + 7] = ny;
+ mesh->normal[9 * i + 8] = nz;
- mesh->index[3*i+0] = 3*i+0;
- mesh->index[3*i+1] = 3*i+1;
- mesh->index[3*i+2] = 3*i+2;
- }
+ mesh->index[3 * i + 0] = 3 * i + 0;
+ mesh->index[3 * i + 1] = 3 * i + 1;
+ mesh->index[3 * i + 2] = 3 * i + 2;
+ }
- glGenVertexArrays( 1, &mesh->vao );
- glBindVertexArray( mesh->vao );
+ glGenVertexArrays(1, &mesh->vao);
+ glBindVertexArray(mesh->vao);
- #define X( loc, buff, arr, type ) do { \
+ #define X( loc, buff, arr, type ) do { \
glGenBuffers( 1, &buff ); \
glBindBuffer( GL_ARRAY_BUFFER, buff ); \
glBufferData( GL_ARRAY_BUFFER, mesh->num_vertices*sizeof( type ), arr, GL_STATIC_DRAW ); \
@@ -159,24 +157,24 @@ static void load_collision_mesh( CollisionMesh *mesh )
glVertexAttribPointer( loc, sizeof( type ) / sizeof( float ), GL_FLOAT, GL_FALSE, sizeof( type ), NULL ); \
} while( 0 )
- X( 0, mesh->position_buffer, mesh->position, vec3 );
- X( 1, mesh->normal_buffer, mesh->normal, vec3 );
+ X(0, mesh->position_buffer, mesh->position, vec3);
+ X(1, mesh->normal_buffer, mesh->normal, vec3);
- #undef X
+ #undef X
}
-static void load_mario_mesh( MarioMesh *mesh, struct SM64MarioGeometryBuffers *marioGeo )
+static void load_mario_mesh(MarioMesh *mesh, struct SM64MarioGeometryBuffers *marioGeo)
{
- mesh->index = malloc( 3 * SM64_GEO_MAX_TRIANGLES * sizeof(uint16_t) );
- for( int i = 0; i < 3 * SM64_GEO_MAX_TRIANGLES; ++i )
- mesh->index[i] = i;
+ mesh->index = malloc(3 * SM64_GEO_MAX_TRIANGLES * sizeof(uint16_t));
+ for (int i = 0; i < 3 * SM64_GEO_MAX_TRIANGLES; ++i)
+ mesh->index[i] = i;
- mesh->num_vertices = 3 * SM64_GEO_MAX_TRIANGLES;
+ mesh->num_vertices = 3 * SM64_GEO_MAX_TRIANGLES;
- glGenVertexArrays( 1, &mesh->vao );
- glBindVertexArray( mesh->vao );
+ glGenVertexArrays(1, &mesh->vao);
+ glBindVertexArray(mesh->vao);
- #define X( loc, buff, arr, type ) do { \
+ #define X( loc, buff, arr, type ) do { \
glGenBuffers( 1, &buff ); \
glBindBuffer( GL_ARRAY_BUFFER, buff ); \
glBufferData( GL_ARRAY_BUFFER, sizeof( type ) * 3 * SM64_GEO_MAX_TRIANGLES, arr, GL_DYNAMIC_DRAW ); \
@@ -184,127 +182,134 @@ static void load_mario_mesh( MarioMesh *mesh, struct SM64MarioGeometryBuffers *m
glVertexAttribPointer( loc, sizeof( type ) / sizeof( float ), GL_FLOAT, GL_FALSE, sizeof( type ), NULL ); \
} while( 0 )
- X( 0, mesh->position_buffer, marioGeo->position, vec3 );
- X( 1, mesh->normal_buffer, marioGeo->normal, vec3 );
- X( 2, mesh->color_buffer, marioGeo->color, vec3 );
- X( 3, mesh->uv_buffer, marioGeo->uv, vec2 );
+ X(0, mesh->position_buffer, marioGeo->position, vec3);
+ X(1, mesh->normal_buffer, marioGeo->normal, vec3);
+ X(2, mesh->color_buffer, marioGeo->color, vec3);
+ X(3, mesh->uv_buffer, marioGeo->uv, vec2);
- #undef X
+ #undef X
}
-static void update_mario_mesh( MarioMesh *mesh, struct SM64MarioGeometryBuffers *marioGeo )
+static void update_mario_mesh(MarioMesh *mesh, struct SM64MarioGeometryBuffers *marioGeo)
{
- if( mesh->index == NULL )
- load_mario_mesh( mesh, marioGeo );
+ if (mesh->index == NULL)
+ load_mario_mesh(mesh, marioGeo);
- mesh->num_vertices = 3 * marioGeo->numTrianglesUsed;
+ mesh->num_vertices = 3 * marioGeo->numTrianglesUsed;
- glBindBuffer( GL_ARRAY_BUFFER, mesh->position_buffer );
- glBufferData( GL_ARRAY_BUFFER, sizeof( vec3 ) * 3 * SM64_GEO_MAX_TRIANGLES, marioGeo->position, GL_DYNAMIC_DRAW );
- glBindBuffer( GL_ARRAY_BUFFER, mesh->normal_buffer );
- glBufferData( GL_ARRAY_BUFFER, sizeof( vec3 ) * 3 * SM64_GEO_MAX_TRIANGLES, marioGeo->normal, GL_DYNAMIC_DRAW );
- glBindBuffer( GL_ARRAY_BUFFER, mesh->color_buffer );
- glBufferData( GL_ARRAY_BUFFER, sizeof( vec3 ) * 3 * SM64_GEO_MAX_TRIANGLES, marioGeo->color, GL_DYNAMIC_DRAW );
- glBindBuffer( GL_ARRAY_BUFFER, mesh->uv_buffer );
- glBufferData( GL_ARRAY_BUFFER, sizeof( vec2 ) * 3 * SM64_GEO_MAX_TRIANGLES, marioGeo->uv, GL_DYNAMIC_DRAW );
+ glBindBuffer(GL_ARRAY_BUFFER, mesh->position_buffer);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(vec3) * 3 * SM64_GEO_MAX_TRIANGLES, marioGeo->position, GL_DYNAMIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, mesh->normal_buffer);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(vec3) * 3 * SM64_GEO_MAX_TRIANGLES, marioGeo->normal, GL_DYNAMIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, mesh->color_buffer);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(vec3) * 3 * SM64_GEO_MAX_TRIANGLES, marioGeo->color, GL_DYNAMIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, mesh->uv_buffer);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(vec2) * 3 * SM64_GEO_MAX_TRIANGLES, marioGeo->uv, GL_DYNAMIC_DRAW);
}
-static GLuint shader_compile( const char *shaderContents, size_t shaderContentsLength, GLenum shaderType )
+static GLuint shader_compile(const char *shaderContents, size_t shaderContentsLength, GLenum shaderType)
{
- const GLchar *shaderDefine = shaderType == GL_VERTEX_SHADER
- ? "\n#version 330\n#define VERTEX \n#define v2f out\n"
- : "\n#version 330\n#define FRAGMENT\n#define v2f in \n";
+ const GLchar *shaderDefine = shaderType == GL_VERTEX_SHADER
+ ? "\n#version 330\n#define VERTEX \n#define v2f out\n"
+ : "\n#version 330\n#define FRAGMENT\n#define v2f in \n";
- const GLchar *shaderStrings[2] = { shaderDefine, shaderContents };
- GLint shaderStringLengths[2] = { strlen( shaderDefine ), (GLint)shaderContentsLength };
+ const GLchar *shaderStrings[2] = {shaderDefine, shaderContents};
+ GLint shaderStringLengths[2] = {strlen(shaderDefine), (GLint)shaderContentsLength};
- GLuint shader = glCreateShader( shaderType );
- glShaderSource( shader, 2, shaderStrings, shaderStringLengths );
- glCompileShader( shader );
+ GLuint shader = glCreateShader(shaderType);
+ glShaderSource(shader, 2, shaderStrings, shaderStringLengths);
+ glCompileShader(shader);
- GLint isCompiled;
- glGetShaderiv( shader, GL_COMPILE_STATUS, &isCompiled );
- if( isCompiled == GL_FALSE )
- {
- GLint maxLength;
- glGetShaderiv( shader, GL_INFO_LOG_LENGTH, &maxLength );
- char *log = (char*)malloc( maxLength );
- glGetShaderInfoLog( shader, maxLength, &maxLength, log );
+ GLint isCompiled;
+ glGetShaderiv(shader, GL_COMPILE_STATUS, &isCompiled);
+ if (isCompiled == GL_FALSE)
+ {
+ GLint maxLength;
+ glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength);
+ char *log = malloc(maxLength);
+ glGetShaderInfoLog(shader, maxLength, &maxLength, log);
- printf( "Error in shader: %s\n%s\n%s\n", log, shaderStrings[0], shaderStrings[1] );
- exit( 1 );
- }
+ printf("Error in shader: %s\n%s\n%s\n", log, shaderStrings[0], shaderStrings[1]);
+ exit(1);
+ }
- return shader;
+ return shader;
}
-static GLuint shader_load( const char *shaderContents )
+static GLuint shader_load(const char *shaderContents)
{
- GLuint result;
- GLuint vert = shader_compile( shaderContents, strlen( shaderContents ), GL_VERTEX_SHADER );
- GLuint frag = shader_compile( shaderContents, strlen( shaderContents ), GL_FRAGMENT_SHADER );
+ GLuint result;
+ GLuint vert = shader_compile(shaderContents, strlen(shaderContents), GL_VERTEX_SHADER);
+ GLuint frag = shader_compile(shaderContents, strlen(shaderContents), GL_FRAGMENT_SHADER);
- GLuint ref = glCreateProgram();
- glAttachShader( ref, vert );
- glAttachShader( ref, frag );
+ GLuint ref = glCreateProgram();
+ glAttachShader(ref, vert);
+ glAttachShader(ref, frag);
- glLinkProgram ( ref );
- glDetachShader( ref, vert );
- glDetachShader( ref, frag );
- result = ref;
+ glLinkProgram(ref);
+ glDetachShader(ref, vert);
+ glDetachShader(ref, frag);
+ result = ref;
- return result;
+ return result;
}
static void gl33core_init(RenderState *renderState, uint8_t *marioTexture)
{
- load_collision_mesh( &renderState->collision );
- renderState->world_shader = shader_load( WORLD_SHADER );
- renderState->mario_shader = shader_load( MARIO_SHADER );
+ load_collision_mesh(&renderState->collision);
+ renderState->world_shader = shader_load(WORLD_SHADER);
+ renderState->mario_shader = shader_load(MARIO_SHADER);
- glEnable( GL_CULL_FACE );
- glCullFace( GL_BACK );
- glClearColor( 0.2f, 0.2f, 0.2f, 1.0f );
- glDepthMask( GL_TRUE );
- glDepthFunc( GL_LEQUAL );
- glEnable( GL_DEPTH_TEST );
+ glEnable(GL_CULL_FACE);
+ glCullFace(GL_BACK);
+ glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
+ glDepthMask(GL_TRUE);
+ glDepthFunc(GL_LEQUAL);
+ glEnable(GL_DEPTH_TEST);
- glGenTextures( 1, &renderState->mario_texture );
- glBindTexture( GL_TEXTURE_2D, renderState->mario_texture );
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SM64_TEXTURE_WIDTH, SM64_TEXTURE_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, marioTexture);
+ glGenTextures(1, &renderState->mario_texture);
+ glBindTexture(GL_TEXTURE_2D, renderState->mario_texture);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SM64_TEXTURE_WIDTH, SM64_TEXTURE_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, marioTexture);
}
static void gl33core_draw(RenderState *renderState, const vec3 camPos, const struct SM64MarioState *marioState, struct SM64MarioGeometryBuffers *marioGeo)
{
- update_mario_mesh( &renderState->mario, marioGeo );
+ update_mario_mesh(&renderState->mario, marioGeo);
- mat4 model, view, projection;
- glm_perspective( 45.0f, (float)WINDOW_WIDTH / (float)WINDOW_HEIGHT, 100.0f, 20000.0f, projection );
- glm_translate( view, (float*)camPos );
- glm_lookat( (float*)camPos, (float*)marioState->position, (vec3){0,1,0}, view );
- glm_mat4_identity( model );
+ mat4 model, view, projection;
+ glm_perspective(45.0f, (float)WINDOW_WIDTH / (float)WINDOW_HEIGHT, 100.0f, 20000.0f, projection);
+ glm_translate(view, (float *)camPos);
+ glm_lookat((float *)camPos, (float *)marioState->position, (vec3)
+ {
+ 0, 1, 0
+ }
+ ,
+ view
+ )
+ ;
+ glm_mat4_identity(model);
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glUseProgram( renderState->world_shader );
- glBindVertexArray( renderState->collision.vao );
- glUniformMatrix4fv( glGetUniformLocation( renderState->world_shader, "model" ), 1, GL_FALSE, (GLfloat*)model );
- glUniformMatrix4fv( glGetUniformLocation( renderState->world_shader, "view" ), 1, GL_FALSE, (GLfloat*)view );
- glUniformMatrix4fv( glGetUniformLocation( renderState->world_shader, "projection" ), 1, GL_FALSE, (GLfloat*)projection );
- glDrawElements( GL_TRIANGLES, renderState->collision.num_vertices, GL_UNSIGNED_SHORT, renderState->collision.index );
+ glUseProgram(renderState->world_shader);
+ glBindVertexArray(renderState->collision.vao);
+ glUniformMatrix4fv(glGetUniformLocation(renderState->world_shader, "model"), 1, GL_FALSE, (GLfloat *)model);
+ glUniformMatrix4fv(glGetUniformLocation(renderState->world_shader, "view"), 1, GL_FALSE, (GLfloat *)view);
+ glUniformMatrix4fv(glGetUniformLocation(renderState->world_shader, "projection"), 1, GL_FALSE, (GLfloat *)projection);
+ glDrawElements(GL_TRIANGLES, renderState->collision.num_vertices, GL_UNSIGNED_SHORT, renderState->collision.index);
- glUseProgram( renderState->mario_shader );
- glActiveTexture( GL_TEXTURE0 );
- glBindTexture( GL_TEXTURE_2D, renderState->mario_texture );
- glBindVertexArray( renderState->mario.vao );
- glUniformMatrix4fv( glGetUniformLocation( renderState->mario_shader, "view" ), 1, GL_FALSE, (GLfloat*)view );
- glUniformMatrix4fv( glGetUniformLocation( renderState->mario_shader, "projection" ), 1, GL_FALSE, (GLfloat*)projection );
- glUniform1i( glGetUniformLocation( renderState->mario_shader, "marioTex" ), 0 );
- glDrawElements( GL_TRIANGLES, renderState->mario.num_vertices, GL_UNSIGNED_SHORT, renderState->mario.index );
+ glUseProgram(renderState->mario_shader);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, renderState->mario_texture);
+ glBindVertexArray(renderState->mario.vao);
+ glUniformMatrix4fv(glGetUniformLocation(renderState->mario_shader, "view"), 1, GL_FALSE, (GLfloat *)view);
+ glUniformMatrix4fv(glGetUniformLocation(renderState->mario_shader, "projection"), 1, GL_FALSE, (GLfloat *)projection);
+ glUniform1i(glGetUniformLocation(renderState->mario_shader, "marioTex"), 0);
+ glDrawElements(GL_TRIANGLES, renderState->mario.num_vertices, GL_UNSIGNED_SHORT, renderState->mario.index);
}
struct Renderer gl33core_renderer = {
diff --git a/test/main.cpp b/test/main.cpp
index 00f8c72..84cc464 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -11,41 +11,42 @@
#include "../src/libsm64.h"
-extern "C" {
-#define SDL_MAIN_HANDLED
-#include "level.h"
-#include "context.h"
-#include "renderer.h"
-#include "gl33core/gl33core_renderer.h"
-#include "gl20/gl20_renderer.h"
+extern "C"
+{
+ #define SDL_MAIN_HANDLED
+ #include "level.h"
+ #include "context.h"
+ #include "renderer.h"
+ #include "gl33core/gl33core_renderer.h"
+ #include "gl20/gl20_renderer.h"
}
#include "audio.h"
-uint8_t *utils_read_file_alloc( const char *path, size_t *fileLength )
+uint8_t *utils_read_file_alloc(const char *path, size_t *fileLength)
{
- FILE *f = fopen( path, "rb" );
+ FILE *f = fopen(path, "rb");
- if( !f ) return NULL;
+ if (!f) return nullptr;
- fseek( f, 0, SEEK_END );
- size_t length = (size_t)ftell( f );
- rewind( f );
- uint8_t *buffer = (uint8_t*)malloc( length + 1 );
- fread( buffer, 1, length, f );
+ fseek(f, 0, SEEK_END);
+ size_t length = (size_t)ftell(f);
+ rewind(f);
+ uint8_t *buffer = (uint8_t *)malloc(length + 1);
+ fread(buffer, 1, length, f);
buffer[length] = 0;
- fclose( f );
+ fclose(f);
- if( fileLength ) *fileLength = length;
+ if (fileLength) *fileLength = length;
return buffer;
}
-static float read_axis( int16_t val )
+static float read_axis(int16_t val)
{
float result = (float)val / 32767.0f;
- if( result < 0.2f && result > -0.2f )
+ if (result < 0.2f && result > -0.2f)
return 0.0f;
return result > 0.0f ? (result - 0.2f) / 0.8f : (result + 0.2f) / 0.8f;
@@ -67,50 +68,51 @@ static void DebugPrint(const char *message)
fflush(stdout);
}
-int main( void )
+int main(void)
{
size_t romSize;
- uint8_t *rom = utils_read_file_alloc( "baserom.us.z64", &romSize );
+ uint8_t *rom = utils_read_file_alloc("baserom.us.z64", &romSize);
- if( rom == NULL )
+ if (rom == nullptr)
{
printf("\nFailed to read ROM file \"baserom.us.z64\"\n\n");
return 1;
}
- uint8_t *texture = (uint8_t*)malloc( 4 * SM64_TEXTURE_WIDTH * SM64_TEXTURE_HEIGHT );
+ uint8_t *texture = (uint8_t *)malloc(4 * SM64_TEXTURE_WIDTH * SM64_TEXTURE_HEIGHT);
sm64_global_terminate();
- sm64_global_init( rom, texture );
+ sm64_global_init(rom, texture);
sm64_audio_init(rom);
// sm64_register_debug_print_function(DebugPrint);
- sm64_static_surfaces_load( surfaces, surfaces_count );
- int32_t marioId = sm64_mario_create( 0, 1000, 0 );
+ sm64_static_surfaces_load(surfaces, surfaces_count);
+ int32_t marioId = sm64_mario_create(0, 1000, 0);
printf("MarioID: %i\n", marioId);
- free( rom );
+ free(rom);
RenderState renderState;
- renderState.mario.index = NULL;
- vec3 cameraPos = { 0, 0, 0 };
+ renderState.mario.index = nullptr;
+ vec3 cameraPos = {0, 0, 0};
float cameraRot = 0.0f;
struct Renderer *renderer;
int major, minor;
-#ifdef GL33_CORE
+ #ifdef GL33_CORE
major = 3; minor = 3;
renderer = &gl33core_renderer;
-#else
- major = 2; minor = 0;
+ #else
+ major = 2;
+ minor = 0;
renderer = &gl20_renderer;
-#endif
+ #endif
- context_init( "libsm64", 1280, 720, major, minor );
- renderer->init( &renderState, texture );
+ context_init("libsm64", 1280, 720, major, minor);
+ renderer->init(&renderState, texture);
struct SM64MarioInputs marioInputs;
struct SM64MarioState marioState;
@@ -120,10 +122,10 @@ int main( void )
float lastPos[3], currPos[3];
float lastGeoPos[9 * SM64_GEO_MAX_TRIANGLES], currGeoPos[9 * SM64_GEO_MAX_TRIANGLES];
- marioGeometry.position = (float*)malloc( sizeof(float) * 9 * SM64_GEO_MAX_TRIANGLES );
- marioGeometry.color = (float*)malloc( sizeof(float) * 9 * SM64_GEO_MAX_TRIANGLES );
- marioGeometry.normal = (float*)malloc( sizeof(float) * 9 * SM64_GEO_MAX_TRIANGLES );
- marioGeometry.uv = (float*)malloc( sizeof(float) * 6 * SM64_GEO_MAX_TRIANGLES );
+ marioGeometry.position = (float *)malloc(sizeof(float) * 9 * SM64_GEO_MAX_TRIANGLES);
+ marioGeometry.color = (float *)malloc(sizeof(float) * 9 * SM64_GEO_MAX_TRIANGLES);
+ marioGeometry.normal = (float *)malloc(sizeof(float) * 9 * SM64_GEO_MAX_TRIANGLES);
+ marioGeometry.uv = (float *)malloc(sizeof(float) * 6 * SM64_GEO_MAX_TRIANGLES);
marioGeometry.numTrianglesUsed = 0;
float tick = 0;
@@ -144,7 +146,7 @@ int main( void )
if (!controller) // keyboard
{
- const Uint8* state = SDL_GetKeyboardState(NULL);
+ const Uint8 *state = SDL_GetKeyboardState(nullptr);
float dir;
float spd = 0;
@@ -199,43 +201,43 @@ int main( void )
}
else
{
- x_axis = read_axis( SDL_GameControllerGetAxis( controller, SDL_CONTROLLER_AXIS_LEFTX ));
- y_axis = read_axis( SDL_GameControllerGetAxis( controller, SDL_CONTROLLER_AXIS_LEFTY ));
- x0_axis = read_axis( SDL_GameControllerGetAxis( controller, SDL_CONTROLLER_AXIS_RIGHTX ));
+ x_axis = read_axis(SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_LEFTX));
+ y_axis = read_axis(SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_LEFTY));
+ x0_axis = read_axis(SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_RIGHTX));
- marioInputs.buttonA = SDL_GameControllerGetButton( controller, SDL_CONTROLLER_BUTTON_A );
- marioInputs.buttonB = SDL_GameControllerGetButton( controller, SDL_CONTROLLER_BUTTON_X );
- marioInputs.buttonZ = SDL_GameControllerGetButton( controller, SDL_CONTROLLER_BUTTON_LEFTSHOULDER );
+ marioInputs.buttonA = SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_A);
+ marioInputs.buttonB = SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_X);
+ marioInputs.buttonZ = SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_LEFTSHOULDER);
}
cameraRot += x0_axis * dt * 2;
- cameraPos[0] = marioState.position[0] + 1000.0f * cosf( cameraRot );
+ cameraPos[0] = marioState.position[0] + 1000.0f * cosf(cameraRot);
cameraPos[1] = marioState.position[1] + 200.0f;
- cameraPos[2] = marioState.position[2] + 1000.0f * sinf( cameraRot );
+ cameraPos[2] = marioState.position[2] + 1000.0f * sinf(cameraRot);
marioInputs.camLookX = marioState.position[0] - cameraPos[0];
marioInputs.camLookZ = marioState.position[2] - cameraPos[2];
marioInputs.stickX = x_axis;
marioInputs.stickY = y_axis;
- while (tick >= 1.f/30)
+ while (tick >= 1.f / 30)
{
memcpy(lastPos, currPos, sizeof(currPos));
memcpy(lastGeoPos, currGeoPos, sizeof(currGeoPos));
- tick -= 1.f/30;
- sm64_mario_tick( marioId, &marioInputs, &marioState, &marioGeometry );
+ tick -= 1.f / 30;
+ sm64_mario_tick(marioId, &marioInputs, &marioState, &marioGeometry);
memcpy(currPos, marioState.position, sizeof(currPos));
memcpy(currGeoPos, marioGeometry.position, sizeof(currGeoPos));
}
- for (int i=0; i<3; i++) marioState.position[i] = lerp(lastPos[i], currPos[i], tick / (1.f/30));
- for (int i=0; idraw( &renderState, cameraPos, &marioState, &marioGeometry );
+ renderer->draw(&renderState, cameraPos, &marioState, &marioGeometry);
}
- while( context_flip_frame_poll_events() );
+ while (context_flip_frame_poll_events());
sm64_stop_background_music(sm64_get_current_background_music());
sm64_global_terminate();
diff --git a/test/ns_clock.h b/test/ns_clock.h
index 50ec627..7062086 100644
--- a/test/ns_clock.h
+++ b/test/ns_clock.h
@@ -23,38 +23,42 @@
# define WIN32_LEAN_AND_MEAN
# include
#endif
-static uint64_t ns_clock() {
- static uint64_t is_init = 0;
-#if defined(__APPLE__)
+static uint64_t ns_clock()
+{
+ static uint64_t is_init = 0;
+ #if defined(__APPLE__)
static mach_timebase_info_data_t info;
- if (0 == is_init) {
- mach_timebase_info(&info);
- is_init = 1;
+ if (0 == is_init)
+ {
+ mach_timebase_info(&info);
+ is_init = 1;
}
uint64_t now;
now = mach_absolute_time();
now *= info.numer;
now /= info.denom;
return now;
-#elif defined(__linux)
+ #elif defined(__linux)
static struct timespec linux_rate;
- if (0 == is_init) {
- clock_getres(CLOCKID, &linux_rate);
- is_init = 1;
+ if (0 == is_init)
+ {
+ clock_getres(CLOCKID, &linux_rate);
+ is_init = 1;
}
uint64_t now;
struct timespec spec;
clock_gettime(CLOCKID, &spec);
now = spec.tv_sec * 1.0e9 + spec.tv_nsec;
return now;
-#elif defined(_WIN32)
+ #elif defined(_WIN32)
static LARGE_INTEGER win_frequency;
- if (0 == is_init) {
- QueryPerformanceFrequency(&win_frequency);
- is_init = 1;
+ if (0 == is_init)
+ {
+ QueryPerformanceFrequency(&win_frequency);
+ is_init = 1;
}
LARGE_INTEGER now;
QueryPerformanceCounter(&now);
- return (uint64_t) ((1e9 * now.QuadPart) / win_frequency.QuadPart);
-#endif
+ return (uint64_t)((1e9 * now.QuadPart) / win_frequency.QuadPart);
+ #endif
}
\ No newline at end of file
diff --git a/test/renderer.h b/test/renderer.h
index 00f24e3..f182cdd 100644
--- a/test/renderer.h
+++ b/test/renderer.h
@@ -6,12 +6,13 @@
#include
#ifdef __cplusplus
-extern "C" {
-#endif
+extern "C"
+{
+ #endif
-#include "../src/libsm64.h"
+ #include "../src/libsm64.h"
-#ifdef __cplusplus
+ #ifdef __cplusplus
}
#endif
@@ -58,8 +59,9 @@ RenderState;
struct Renderer
{
- void (*init)(RenderState *renderState, uint8_t *marioTexture);
- void (*draw)(RenderState *renderState, const vec3 camPos, const struct SM64MarioState *marioState, struct SM64MarioGeometryBuffers *marioGeo);
+ void (*init)(RenderState *renderState, uint8_t *marioTexture);
+
+ void (*draw)(RenderState *renderState, const vec3 camPos, const struct SM64MarioState *marioState, struct SM64MarioGeometryBuffers *marioGeo);
};
#endif