Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
44cd938
initial work to enhance demos
Sep 3, 2024
144cda2
game compiles and boots; still need to fix the initial DMA
Sep 4, 2024
d184844
full demo functionality has been restored
Sep 4, 2024
22e0f63
remove the first command (which was actually a header in the old form…
Sep 4, 2024
7053aa9
remove debug print
Sep 4, 2024
d094604
demos are actually fixed
Sep 4, 2024
f437e5f
remove temp tool
Sep 4, 2024
2c50720
return config defines to normal
Sep 4, 2024
31b887d
Recording demos now works through ISViewer
Sep 4, 2024
bdafc1d
clarify title_screen defines
Sep 4, 2024
be73c9d
add CCM demo; fix a small demo recording bug that added trailing spac…
Sep 4, 2024
17ddfb9
update ccm demo
Sep 4, 2024
60b71e5
add hmc demo
Sep 4, 2024
3a639d2
new PSS demo
Sep 4, 2024
bd2a1ad
new JRB demo (clickbait)
Sep 4, 2024
ea5355b
Add BBH demo
Sep 4, 2024
d4013f6
add failed owlless demo
Sep 4, 2024
1d7b018
Add failsafe so a user can't clobber the Demo segment
Sep 4, 2024
2f71da5
remove debug demo recorder during normal gameplay
Sep 4, 2024
2a73042
Create new demo format
Sep 7, 2024
cf95b11
Demos are now dynamically DMA'd into the segment memory; 3/6 demos co…
Sep 7, 2024
ed9dc70
add demo_system.c and move all related functions
Sep 7, 2024
dfb928a
PSS demo; HMC demo fixed
Sep 7, 2024
e37be3c
Add demo recording mode define
Sep 7, 2024
07c5a6c
Add DEMO_RECORDING_MODE
Sep 8, 2024
519cf02
More trying to fix demo desyncs
Sep 23, 2024
814fa60
revert back to input based demos
Dec 15, 2024
f75ca2b
clean up
Dec 15, 2024
1210d31
clean up more things
Dec 15, 2024
0f21f63
turn off ISVPRINT by default
Dec 15, 2024
caa635e
remove more debug stuff; fix a small printing bug while recording
Dec 15, 2024
d01ce13
fix that pinting bug the correct way
Dec 15, 2024
3e6e3a3
hide more stuff behind DISABLE_DEMO; bring back logo
Dec 15, 2024
ee0e36e
remove demos from rom if disabled
Dec 15, 2024
db9a354
remove vanilla demos entirely
Dec 28, 2024
5e09abe
turn off mario head'
Dec 28, 2024
961efa5
add demo tutorial
Dec 28, 2024
3224020
clarify how to end recording a demo
Dec 28, 2024
047533b
diff reduction
Jan 30, 2025
855fd30
flip DISABLE_DEMOS into ENABLE_DEMO_SYSTEM
Feb 7, 2025
c3018bc
flip the link script too
Feb 7, 2025
a1f439d
clarify DEMO_RECORDING_MODE
Feb 17, 2025
77ded6c
and the demo readme too
Feb 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ CPP_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
LIBZ_C_FILES := $(foreach dir,$(LIBZ_SRC_DIRS),$(wildcard $(dir)/*.c))
GODDARD_C_FILES := $(foreach dir,$(GODDARD_SRC_DIRS),$(wildcard $(dir)/*.c))
S_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.s))
GENERATED_C_FILES := $(BUILD_DIR)/assets/mario_anim_data.c $(BUILD_DIR)/assets/demo_data.c
GENERATED_C_FILES := $(BUILD_DIR)/assets/mario_anim_data.c
GENERATED_S_FILES := $(BUILD_DIR)/assets/demo_data.s

# Ignore all .inc.c files
C_FILES := $(filter-out %.inc.c,$(C_FILES))
Expand All @@ -421,6 +422,7 @@ O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) \
$(foreach file,$(CPP_FILES),$(BUILD_DIR)/$(file:.cpp=.o)) \
$(foreach file,$(S_FILES),$(BUILD_DIR)/$(file:.s=.o)) \
$(foreach file,$(GENERATED_C_FILES),$(file:.c=.o)) \
$(foreach file,$(GENERATED_S_FILES),$(file:.s=.o)) \
lib/PR/hvqm/hvqm2sp1.o lib/PR/hvqm/hvqm2sp2.o

LIBZ_O_FILES := $(foreach file,$(LIBZ_C_FILES),$(BUILD_DIR)/$(file:.c=.o))
Expand Down Expand Up @@ -800,9 +802,9 @@ $(BUILD_DIR)/assets/mario_anim_data.c: $(wildcard assets/anims/*.inc.c)
$(V)$(PYTHON) $(TOOLS_DIR)/mario_anims_converter.py > $@

# Generate demo input data
$(BUILD_DIR)/assets/demo_data.c: assets/demo_data.json $(wildcard assets/demos/*.bin)
$(BUILD_DIR)/assets/demo_data.s: $(wildcard assets/demos/*.s)
@$(PRINT) "$(GREEN)Generating demo data $(NO_COL)\n"
$(V)$(PYTHON) $(TOOLS_DIR)/demo_data_converter.py assets/demo_data.json $(DEF_INC_CFLAGS) > $@
$(V)$(PYTHON) $(TOOLS_DIR)/demo_data_converter.py assets/demos/ > $@

# Level headers
$(BUILD_DIR)/include/level_headers.h: levels/level_headers.h.in
Expand Down Expand Up @@ -838,6 +840,9 @@ $(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c
$(BUILD_DIR)/%.o: %.s
$(call print,Assembling:,$<,$@)
$(V)$(CROSS)gcc -c $(ASMFLAGS) $(foreach i,$(INCLUDE_DIRS),-Wa,-I$(i)) -x assembler-with-cpp -MMD -MF $(BUILD_DIR)/$*.d -o $@ $<
$(BUILD_DIR)/%.o: $(BUILD_DIR)/%.s
$(call print,Assembling:,$<,$@)
$(V)$(CROSS)gcc -c $(ASMFLAGS) -U_LANGUAGE_C $(foreach i,$(INCLUDE_DIRS),-Wa,-I$(i)) -x assembler-with-cpp -MMD -MF $(BUILD_DIR)/$*.d -o $@ $<

# Assemble RSP assembly code
$(BUILD_DIR)/rsp/%.bin $(BUILD_DIR)/rsp/%_data.bin: rsp/%.s
Expand Down
8 changes: 0 additions & 8 deletions assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,6 @@
"actors/yoshi_egg/yoshi_egg_5_unused.rgba16.png": [32,32,2048,{"jp":[1215456,32696],"us":[1222624,32696],"eu":[1094592,32696],"sh":[1071104,32696]}],
"actors/yoshi_egg/yoshi_egg_6_unused.rgba16.png": [32,32,2048,{"jp":[1215456,34744],"us":[1222624,34744],"eu":[1094592,34744],"sh":[1071104,34744]}],
"actors/yoshi_egg/yoshi_egg_7_unused.rgba16.png": [32,32,2048,{"jp":[1215456,36792],"us":[1222624,36792],"eu":[1094592,36792],"sh":[1071104,36792]}],
"assets/demos/bbh.bin": [988,{"jp":[5733368],"us":[5741664],"eu":[5620584],"sh":[5589632]}],
"assets/demos/bitdw.bin": [1412,{"us":[5747100],"sh":[5595068]}],
"assets/demos/ccm.bin": [1320,{"jp":[5734356],"us":[5742652],"eu":[5621572],"sh":[5590620]}],
"assets/demos/hmc.bin": [980,{"jp":[5735676],"us":[5743972],"eu":[5622892],"sh":[5591940]}],
"assets/demos/jrb.bin": [620,{"jp":[5736656],"us":[5744952],"eu":[5623872],"sh":[5592920]}],
"assets/demos/pss.bin": [748,{"jp":[5737948],"us":[5746244],"eu":[5625164],"sh":[5594212]}],
"assets/demos/unused.bin": [108,{"jp":[5738696],"us":[5746992],"eu":[5625912],"sh":[5594960]}],
"assets/demos/wf.bin": [672,{"jp":[5737276],"us":[5745572],"eu":[5624492],"sh":[5593540]}],
"levels/bbh/0.rgba16.png": [32,64,4096,{"jp":[3604960,0],"us":[3611712,0],"eu":[3485312,0],"sh":[3459680,0]}],
"levels/bbh/1.rgba16.png": [32,32,2048,{"jp":[3604960,4096],"us":[3611712,4096],"eu":[3485312,4096],"sh":[3459680,4096]}],
"levels/bbh/2.rgba16.png": [32,32,2048,{"jp":[3604960,6144],"us":[3611712,6144],"eu":[3485312,6144],"sh":[3459680,6144]}],
Expand Down
49 changes: 0 additions & 49 deletions assets/demo_data.json

This file was deleted.

17 changes: 17 additions & 0 deletions assets/demos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Demos
To record a demo, a few steps have to be taken.
- Enable `DEMO_RECORDING_MODE` in `include/config/config_goddard.h`.
- Set a `START_LEVEL` or `TEST_LEVEL` in `config_game.h` or `config_debug.h`, respectively.
- Set `ISVPRINT=1` in the `Makefile` (or `UNF=1` if using a USB-enabled flashcart on console)
- Rebuild the repo, and launch an emulator with debug console support such as Parallel Launcher.

The demo recording mode will boot into the level you set, from which you can start moving around and interacting with the level and camera. Press the Start button to end the demo

To test the demo after it's done:

- Enable `KEEP_MARIO_HEAD` and comment out `DISABLE_DEMO` and `DEMO_RECORDING_MODE` in `config_goddard.h`.
- If you set a `TEST_LEVEL`, comment that out too.
- Set `ISVPRINT=0` in the Makefile if you don't need debug printing anymore.
- Build the game again and wait on the title screen.

To see demos faster on the title screen, edit `PRESS_START_DEMO_TIMER` in `src/game/demo_system.h`. The default is 800 frames (close to 27 seconds).
18 changes: 18 additions & 0 deletions include/config/config_game.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,21 @@
* The levelscript needs to have a MARIO_POS command for this to work.
*/
#define START_LEVEL LEVEL_CASTLE_GROUNDS

/**
* Allows demos to be played back, if they exist in assets/demos/
*/
// #define ENABLE_DEMO_SYSTEM

/**
* Boots directly to `TEST_LEVEL` (see config_debug.h) and prints inputs to a debug console.
* Press Start to end the recording.
* Copy the console output to a new file in `assets/demos/`. The name of the file should be printed at the top of the output.
* For emulator users (confirmed working in Parallel Launcher and Ares), `ISVPRINT` in the Makefile must be set to 1.
* For N64 testing with a USB-enabled flashcart, `UNF` in the Makefile must be set to 1.
* This define suppresses a few debug prints to keep the console output limited to just the file to save.
*
* If `TEST_LEVEL` is not set, this define will boot into `START_LEVEL`.
*/
// #define DEMO_RECORDING_MODE

5 changes: 0 additions & 5 deletions include/config/config_goddard.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,3 @@
* Enables the Goddard easter egg from Shindou (has no effect if KEEP_MARIO_HEAD is disabled).
*/
#define GODDARD_EASTER_EGG

/**
* Disables the demo that plays when idle on the start screen (has no effect if KEEP_MARIO_HEAD is disabled).
*/
#define DISABLE_DEMO
12 changes: 8 additions & 4 deletions include/config/config_safeguards.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@
#define FLYING_CAMERA_MODE CAMERA_MODE_BEHIND_MARIO
#endif // !FLYING_CAMERA_MODE


/*****************
* config_game.h
*/
Expand All @@ -166,11 +165,16 @@

#ifndef KEEP_MARIO_HEAD
#undef GODDARD_EASTER_EGG

#undef DISABLE_DEMO
#define DISABLE_DEMO
#undef ENABLE_DEMO_SYSTEM // Demos only play back on the title screen
#endif // !KEEP_MARIO_HEAD

#ifdef DEMO_RECORDING_MODE
#ifndef TEST_LEVEL
// assume user is testing the start level
#define TEST_LEVEL START_LEVEL
#endif
#endif


/*****************
* config_menu.h
Expand Down
43 changes: 43 additions & 0 deletions include/demo_macros.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once
#include <PR/os_cont.h>

/* Demo Macros */

.macro stick x, y
.byte \x, \y
.endm

.macro end_demo
.half 0
.byte 0, 0
.half 0
.half 0
.endm

.macro for holdcount_frames
.half \holdcount_frames
.endm

/* purely for legibility */
#define frames

.macro press buttonMask
.half \buttonMask
.half 0
.endm

/* Pretty names since pressing every button on a frame might overrun a buffer*/
#define A A_BUTTON
#define B B_BUTTON
#define Z Z_TRIG
#define Start START_BUTTON
#define L L_TRIG
#define R R_TRIG

#define C_Up U_CBUTTONS
#define C_Down D_CBUTTONS
#define C_Left L_CBUTTONS
#define C_Right R_CBUTTONS

/* Macro for no button */
#define _ 0
2 changes: 1 addition & 1 deletion levels/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const LevelScript level_script_entry[] = {
INIT_LEVEL(),
SLEEP(/*frames*/ 2),
BLACKOUT(/*active*/ FALSE),
#ifdef TEST_LEVEL
#if defined(TEST_LEVEL) || defined(DEMO_RECORDING_MODE)
SET_REG(/*value*/ TEST_LEVEL),
EXECUTE(/*seg*/ SEGMENT_GLOBAL_LEVEL_SCRIPT, /*script*/ _scriptsSegmentRomStart, /*scriptEnd*/ _scriptsSegmentRomEnd, /*entry*/ level_main_scripts_entry),
#else
Expand Down
7 changes: 7 additions & 0 deletions levels/scripts.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include "game/level_update.h"
#include "level_commands.h"
#include "game/area.h"
#ifdef DEMO_RECORDING_MODE
#include "game/demo_system.h"
#endif // DEMO_RECORDING_MODE

#include "make_const_nonconst.h"

Expand Down Expand Up @@ -122,6 +125,10 @@ const LevelScript level_main_scripts_entry[] = {
EXECUTE(/*seg*/ SEGMENT_MENU_INTRO, _menuSegmentRomStart, _menuSegmentRomEnd, level_main_menu_entry_act_select),
JUMP_LINK(script_exec_level_table),
SLEEP(/*frames*/ 1),
#ifdef DEMO_RECORDING_MODE
CALL(/*arg*/ 0, /*func*/ print_demo_footer),
SET_REG(WARP_SPECIAL_ENDING),
#endif // DEMO_RECORDING_MODE
LOOP_UNTIL(/*op*/ OP_LT, /*arg*/ WARP_SPECIAL_NONE),
JUMP_IF( /*op*/ OP_EQ, /*arg*/ WARP_SPECIAL_ENDING, goto_ending),
JUMP_IF( /*op*/ OP_EQ, /*arg*/ WARP_SPECIAL_MARIO_HEAD_REGULAR, goto_mario_head_regular),
Expand Down
2 changes: 2 additions & 0 deletions sm64.ld
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,9 @@ SECTIONS
{
KEEP(BUILD_DIR/assets/mario_anim_data.o(.data*));
KEEP(BUILD_DIR/assets/mario_anim_data.o(.rodata*));
#ifdef ENABLE_DEMO_SYSTEM
KEEP(BUILD_DIR/assets/demo_data.o(.data*));
#endif /* ENABLE_DEMO_SYSTEM */
KEEP(BUILD_DIR/sound/sound_data.o(.data*));
}
END_SEG(assets)
Expand Down
2 changes: 1 addition & 1 deletion src/audio/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ enum Codecs {
// Since u8 and u16 fit losslessly in both, behavior is the same.
#define FLOAT_CAST(x) (f32) (s32) (x)

#if defined(ISVPRINT) || defined(UNF)
#if (!defined(DEMO_RECORDING_MODE)) && (defined(ISVPRINT) || defined(UNF))
#define stubbed_printf osSyncPrintf
#else

Expand Down
2 changes: 2 additions & 0 deletions src/audio/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ void audio_init() {
gAudioLoadLock = AUDIO_LOCK_NOT_LOADING;
// Should probably contain the sizes of the data banks, but those aren't
// easily accessible from here.
#ifndef DEMO_RECORDING_MODE
osSyncPrintf("---------- Init Completed. ------------\n");
osSyncPrintf(" Syndrv :[%6d]\n", gSoundDataRaw - gSoundDataADSR); // gSoundDataADSR
#ifndef VERSION_SH
Expand All @@ -895,5 +896,6 @@ void audio_init() {
#endif
osSyncPrintf(" audiodata :[%6d]\n", gMusicData - gSoundDataRaw); // gSoundDataRaw
osSyncPrintf("---------------------------------------\n");
#endif // DEMO_RECORDING_MODE
}
#endif
2 changes: 1 addition & 1 deletion src/boot/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ void thread3_main(UNUSED void *arg) {
debug_initialize();
#endif

#ifdef DEBUG
#if !defined(DEMO_RECORDING_MODE) && defined(DEBUG)
osSyncPrintf("Super Mario 64\n");
#if 0 // if your PC username isn't your real name feel free to uncomment
osSyncPrintf("Built by: %s\n", __username__);
Expand Down
8 changes: 7 additions & 1 deletion src/boot/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ uintptr_t set_segment_base_addr(s32 segment, void *addr) {
return sSegmentTable[segment];
}

UNUSED void *get_segment_base_addr(s32 segment) {
void *get_segment_base_addr(s32 segment) {
return (void *) (sSegmentTable[segment] | 0x80000000);
}

Expand Down Expand Up @@ -397,7 +397,10 @@ void *load_segment_decompress(s32 segment, u8 *srcStart, u8 *srcEnd) {
dest = main_pool_alloc(*size, MEMORY_POOL_LEFT);
#endif
if (dest != NULL) {
#ifndef DEMO_RECORDING_MODE
osSyncPrintf("start decompress\n");
#endif // DEMO_RECORDING_MODE

#ifdef GZIP
expand_gzip(compressed, dest, compSize, (u32)size);
#elif RNC1
Expand All @@ -409,7 +412,10 @@ void *load_segment_decompress(s32 segment, u8 *srcStart, u8 *srcEnd) {
#elif MIO0
decompress(compressed, dest);
#endif

#ifndef DEMO_RECORDING_MODE
osSyncPrintf("end decompress\n");
#endif // DEMO_RECORDING_MODE
set_segment_base_addr(segment, dest);
main_pool_free(compressed);
}
Expand Down
4 changes: 4 additions & 0 deletions src/engine/math_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Vec3s gVec3sOne = { 1, 1, 1 };

static u16 gRandomSeed16;

void set_random_seed(u16 seed) {
gRandomSeed16 = seed;
}

// Generate a pseudorandom integer from 0 to 65535 from the random seed, and update the seed.
u16 random_u16(void) {
if (gRandomSeed16 == 22026) {
Expand Down
1 change: 1 addition & 0 deletions src/engine/math_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ ALWAYS_INLINE s32 roundf(f32 in) {
((u32 *)(mtx))[15] = FLOAT_ONE; \
}

void set_random_seed(u16 seed);
u16 random_u16(void);
f32 random_float(void);
s32 random_sign(void);
Expand Down
Loading