Browse Source

merge PC port onto the decompile

master
Jan200101 1 year ago
parent
commit
e87c070517
No known key found for this signature in database GPG Key ID: 5B71B1D78B882E05
100 changed files with 38501 additions and 134 deletions
  1. +237
    -9
      Makefile
  2. +0
    -0
      asmdiff.jp.sh
  3. +16
    -2
      bin/segment2.c
  4. +2
    -2
      extract_assets.py
  5. +2618
    -0
      include/GL/eglew.h
  6. +23686
    -0
      include/GL/glew.h
  7. +1775
    -0
      include/GL/glxew.h
  8. +1447
    -0
      include/GL/wglew.h
  9. +83
    -1
      include/PR/gbi.h
  10. +3
    -3
      include/PR/os_cont.h
  11. +0
    -3
      include/PR/os_pi.h
  12. +2
    -0
      include/PR/ultratypes.h
  13. +5
    -0
      include/config.h
  14. +20
    -0
      include/gfx_dimensions.h
  15. +6
    -0
      include/level_commands.h
  16. +1
    -1
      include/level_misc_macros.h
  17. +7
    -0
      include/macros.h
  18. +10
    -0
      include/segment_symbols.h
  19. +7
    -0
      levels/intro/script.c
  20. +11
    -2
      levels/menu/script.c
  21. +13
    -0
      lib/src/guMtxF2L.c
  22. +2
    -2
      lib/src/osContInit.c
  23. +2
    -2
      lib/src/osContStartReadData.c
  24. +4
    -0
      readme2.txt
  25. +26
    -26
      sound/sequences/00_sound_player.s
  26. +19
    -0
      src/audio/external.c
  27. +2
    -0
      src/audio/heap.c
  28. +3
    -1
      src/audio/load.c
  29. +4
    -0
      src/audio/port_eu.c
  30. +4
    -0
      src/audio/synthesis.c
  31. +1
    -6
      src/buffers/buffers.c
  32. +6
    -1
      src/buffers/buffers.h
  33. +67
    -0
      src/engine/level_script.c
  34. +51
    -0
      src/engine/surface_load.c
  35. +3
    -0
      src/engine/surface_load.h
  36. +10
    -2
      src/game/area.c
  37. +1
    -1
      src/game/crash_screen.c
  38. +26
    -0
      src/game/display.h
  39. +28
    -4
      src/game/game_init.c
  40. +4
    -0
      src/game/geo_misc.c
  41. +6
    -0
      src/game/geo_misc.h
  42. +20
    -18
      src/game/hud.c
  43. +33
    -5
      src/game/ingame_menu.c
  44. +3
    -0
      src/game/level_update.c
  45. +46
    -0
      src/game/macro_special_objects.c
  46. +3
    -0
      src/game/macro_special_objects.h
  47. +13
    -7
      src/game/mario_actions_cutscene.c
  48. +22
    -1
      src/game/memory.c
  49. +8
    -0
      src/game/memory.h
  50. +0
    -1
      src/game/paintings.c
  51. +6
    -1
      src/game/print.c
  52. +11
    -1
      src/game/rendering_graph_node.c
  53. +24
    -5
      src/game/screen_transition.c
  54. +12
    -1
      src/game/skybox.c
  55. +4
    -0
      src/goddard/debug_utils.c
  56. +11
    -4
      src/goddard/draw_objects.c
  57. +29
    -6
      src/goddard/renderer.c
  58. +17
    -0
      src/goddard/skin.c
  59. +18
    -6
      src/menu/intro_geo.c
  60. +26
    -9
      src/menu/level_select_menu.c
  61. +15
    -0
      src/pc/audio/audio_api.h
  62. +23
    -0
      src/pc/audio/audio_null.c
  63. +8
    -0
      src/pc/audio/audio_null.h
  64. +48
    -0
      src/pc/audio/audio_sdl.c
  65. +6
    -0
      src/pc/audio/audio_sdl.h
  66. +236
    -0
      src/pc/configfile.c
  67. +22
    -0
      src/pc/configfile.h
  68. +11
    -0
      src/pc/controller/controller_api.h
  69. +151
    -0
      src/pc/controller/controller_emscripten_keyboard.c
  70. +8
    -0
      src/pc/controller/controller_emscripten_keyboard.h
  71. +36
    -0
      src/pc/controller/controller_entry_point.c
  72. +88
    -0
      src/pc/controller/controller_keyboard.c
  73. +19
    -0
      src/pc/controller/controller_keyboard.h
  74. +29
    -0
      src/pc/controller/controller_recorded_tas.c
  75. +8
    -0
      src/pc/controller/controller_recorded_tas.h
  76. +98
    -0
      src/pc/controller/controller_sdl.c
  77. +8
    -0
      src/pc/controller/controller_sdl.h
  78. +25
    -0
      src/pc/gfx/gfx_cc.h
  79. +503
    -0
      src/pc/gfx/gfx_opengl.c
  80. +8
    -0
      src/pc/gfx/gfx_opengl.h
  81. +1547
    -0
      src/pc/gfx/gfx_pc.c
  82. +19
    -0
      src/pc/gfx/gfx_pc.h
  83. +32
    -0
      src/pc/gfx/gfx_rendering_api.h
  84. +7
    -0
      src/pc/gfx/gfx_screen_config.h
  85. +8
    -0
      src/pc/gfx/gfx_sdl.h
  86. +183
    -0
      src/pc/gfx/gfx_sdl2.c
  87. +18
    -0
      src/pc/gfx/gfx_window_manager_api.h
  88. +490
    -0
      src/pc/mixer.c
  89. +39
    -0
      src/pc/mixer.h
  90. +162
    -0
      src/pc/pc_main.c
  91. +160
    -0
      src/pc/ultra_reimplementation.c
  92. +1
    -1
      tools/Makefile
  93. +25
    -0
      tools/audiofile-0.3.6/ACKNOWLEDGEMENTS
  94. +5
    -0
      tools/audiofile-0.3.6/AUTHORS
  95. +502
    -0
      tools/audiofile-0.3.6/COPYING
  96. +339
    -0
      tools/audiofile-0.3.6/COPYING.GPL
  97. +1953
    -0
      tools/audiofile-0.3.6/ChangeLog
  98. +182
    -0
      tools/audiofile-0.3.6/INSTALL
  99. +897
    -0
      tools/audiofile-0.3.6/Makefile
  100. +58
    -0
      tools/audiofile-0.3.6/Makefile.am

+ 237
- 9
Makefile View File

@@ -18,13 +18,35 @@ COMPARE ?= 1
# If NON_MATCHING is 1, define the NON_MATCHING and AVOID_UB macros when building (recommended)
NON_MATCHING ?= 0
# Build for the N64 (turn this off for ports)
TARGET_N64 ?= 1
TARGET_N64 ?= 0
# Compiler to use (ido or gcc)
COMPILER ?= ido

ifeq ($(COMPILER),gcc)
NON_MATCHING := 1
endif
# Build for Emscripten/WebGL
TARGET_WEB ?= 0
# Specify the target you are building for, 0 means native
TARGET_ARCH ?= native
TARGET_BITS ?= 0

ifneq ($(TARGET_BITS),0)
BITS := -m$(TARGET_BITS)
else
BITS :=
endif

# Automatic settings only for ports
ifeq ($(TARGET_N64),0)
NON_MATCHING := 1
GRUCODE := f3dex2e
WINDOWS_BUILD := 0
ifeq ($(TARGET_WEB),0)
ifeq ($(OS),Windows_NT)
WINDOWS_BUILD := 1
endif
endif

# Release

@@ -79,6 +101,11 @@ ifeq ($(GRUCODE), f3dex2) # Fast3DEX2
TARGET := $(TARGET).f3dex2
COMPARE := 0
else
ifeq ($(GRUCODE), f3dex2e) # Fast3DEX2 Extended (for PC)
GRUCODE_CFLAGS := -DF3DEX_GBI_2E
TARGET := $(TARGET).f3dex2e
COMPARE := 0
else
ifeq ($(GRUCODE),f3d_new) # Fast3D 2.0H (Shindou)
GRUCODE_CFLAGS := -DF3D_NEW
GRUCODE_ASFLAGS := --defsym F3D_NEW=1
@@ -95,6 +122,7 @@ endif
endif
endif
endif
endif

ifeq ($(TARGET_N64),0)
NON_MATCHING := 1
@@ -106,6 +134,10 @@ ifeq ($(NON_MATCHING),1)
COMPARE := 0
endif

ifeq ($(TARGET_WEB),1)
VERSION_CFLAGS := $(VERSION_CFLAGS) -DTARGET_WEB
endif

################### Universal Dependencies ###################

# (This is a bit hacky, but a lot of rules implicitly depend
@@ -137,9 +169,26 @@ endif

# BUILD_DIR is location where all build artifacts are placed
BUILD_DIR_BASE := build
BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)
ifeq ($(TARGET_N64),1)
BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)
else
ifeq ($(TARGET_WEB),1)
BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)_web
else
BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)_pc
endif
endif

LIBULTRA := $(BUILD_DIR)/libultra.a
ifeq ($(TARGET_WEB),1)
EXE := $(BUILD_DIR)/$(TARGET).html
else
ifeq ($(WINDOWS_BUILD),1)
EXE := $(BUILD_DIR)/$(TARGET).exe
else
EXE := $(BUILD_DIR)/$(TARGET)
endif
endif
ROM := $(BUILD_DIR)/$(TARGET).z64
ELF := $(BUILD_DIR)/$(TARGET).elf
LD_SCRIPT := sm64.ld
@@ -151,7 +200,13 @@ LEVEL_DIRS := $(patsubst levels/%,%,$(dir $(wildcard levels/*/header.h)))

# Directories containing source files
SRC_DIRS := src src/engine src/game src/audio src/menu src/buffers actors levels bin data assets
ASM_DIRS := asm lib
ASM_DIRS := lib
ifeq ($(TARGET_N64),1)
ASM_DIRS := asm $(ASM_DIRS)
else
SRC_DIRS := $(SRC_DIRS) src/pc src/pc/gfx src/pc/audio src/pc/controller
ASM_DIRS :=
endif
BIN_DIRS := bin bin/$(VERSION)

ULTRA_SRC_DIRS := lib/src lib/src/math
@@ -177,6 +232,15 @@ else
endif
endif

ifeq ($(TARGET_N64),0)
OPT_FLAGS += $(BITS)
endif

ifeq ($(TARGET_WEB),1)
OPT_FLAGS := -O2 -g4 --source-map-base http://localhost:8080/
endif
endif

# Use a default opt flag for gcc
ifeq ($(COMPILER),gcc)
OPT_FLAGS := -O2
@@ -188,11 +252,80 @@ include Makefile.split
# Source code files
LEVEL_C_FILES := $(wildcard levels/*/leveldata.c) $(wildcard levels/*/script.c) $(wildcard levels/*/geo.c)
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c)) $(LEVEL_C_FILES)
CXX_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
S_FILES := $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/*.s))
ULTRA_C_FILES := $(foreach dir,$(ULTRA_SRC_DIRS),$(wildcard $(dir)/*.c))
GODDARD_C_FILES := $(foreach dir,$(GODDARD_SRC_DIRS),$(wildcard $(dir)/*.c))
ULTRA_S_FILES := $(foreach dir,$(ULTRA_ASM_DIRS),$(wildcard $(dir)/*.s))
GENERATED_C_FILES := $(BUILD_DIR)/assets/mario_anim_data.c $(BUILD_DIR)/assets/demo_data.c
ifeq ($(TARGET_N64),1)
ULTRA_S_FILES := $(foreach dir,$(ULTRA_ASM_DIRS),$(wildcard $(dir)/*.s))
endif
GENERATED_C_FILES := $(BUILD_DIR)/assets/mario_anim_data.c $(BUILD_DIR)/assets/demo_data.c \
$(addprefix $(BUILD_DIR)/bin/,$(addsuffix _skybox.c,$(notdir $(basename $(wildcard textures/skyboxes/*.png)))))

ifeq ($(WINDOWS_BUILD),0)
CXX_FILES :=
endif

ifneq ($(TARGET_N64),1)
ULTRA_C_FILES_SKIP := \
sqrtf.c \
string.c \
sprintf.c \
_Printf.c \
kdebugserver.c \
osInitialize.c \
func_802F7140.c \
func_802F71F0.c \
func_802F4A20.c \
EU_D_802f4330.c \
D_802F4380.c \
osLeoDiskInit.c \
osCreateThread.c \
osDestroyThread.c \
osStartThread.c \
osSetThreadPri.c \
osPiStartDma.c \
osPiRawStartDma.c \
osPiRawReadIo.c \
osPiGetCmdQueue.c \
osJamMesg.c \
osSendMesg.c \
osRecvMesg.c \
osSetEventMesg.c \
osTimer.c \
osSetTimer.c \
osSetTime.c \
osCreateViManager.c \
osViSetSpecialFeatures.c \
osVirtualToPhysical.c \
osViBlack.c \
osViSetEvent.c \
osViSetMode.c \
osViSwapBuffer.c \
osSpTaskLoadGo.c \
osCreatePiManager.c \
osGetTime.c \
osEepromProbe.c \
osEepromWrite.c \
osEepromLongWrite.c \
osEepromRead.c \
osEepromLongRead.c \
osContInit.c \
osContStartReadData.c \
osAiGetLength.c \
osAiSetFrequency.c \
osAiSetNextBuffer.c \
__osViInit.c \
__osSyncPutChars.c \
__osAtomicDec.c \
__osSiRawStartDma.c \
__osViSwapContext.c \
__osViGetCurrentContext.c \
__osDevMgrMain.c

C_FILES := $(filter-out src/game/main.c,$(C_FILES))
ULTRA_C_FILES := $(filter-out $(addprefix lib/src/,$(ULTRA_C_FILES_SKIP)),$(ULTRA_C_FILES))
endif

ifeq ($(VERSION),sh)
SOUND_BANK_FILES := $(wildcard sound/sound_banks/*.json)
@@ -220,6 +353,7 @@ SOUND_OBJ_FILES := $(SOUND_BIN_DIR)/sound_data.ctl.o \

# Object files
O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) \
$(foreach file,$(CXX_FILES),$(BUILD_DIR)/$(file:.cpp=.o)) \
$(foreach file,$(S_FILES),$(BUILD_DIR)/$(file:.s=.o)) \
$(foreach file,$(GENERATED_C_FILES),$(file:.c=.o))

@@ -232,21 +366,27 @@ GODDARD_O_FILES := $(foreach file,$(GODDARD_C_FILES),$(BUILD_DIR)/$(file:.c=.o))
DEP_FILES := $(O_FILES:.o=.d) $(ULTRA_O_FILES:.o=.d) $(GODDARD_O_FILES:.o=.d) $(BUILD_DIR)/$(LD_SCRIPT).d

# Files with GLOBAL_ASM blocks
ifneq ($(NON_MATCHING),1)
GLOBAL_ASM_C_FILES != grep -rl 'GLOBAL_ASM(' $(wildcard src/**/*.c)
GLOBAL_ASM_O_FILES = $(foreach file,$(GLOBAL_ASM_C_FILES),$(BUILD_DIR)/$(file:.c=.o))
GLOBAL_ASM_DEP = $(BUILD_DIR)/src/audio/non_matching_dep
endif

# Segment elf files
SEG_FILES := $(SEGMENT_ELF_FILES) $(ACTOR_ELF_FILES) $(LEVEL_ELF_FILES)

##################### Compiler Options #######################
INCLUDE_CFLAGS := -I include -I $(BUILD_DIR) -I $(BUILD_DIR)/include -I src -I .
ENDIAN_BITWIDTH := $(BUILD_DIR)/endian-and-bitwidth

ifeq ($(TARGET_N64),1)
IRIX_ROOT := tools/ido5.3_compiler

ifeq ($(shell type mips-linux-gnu-ld >/dev/null 2>/dev/null; echo $$?), 0)
CROSS := mips-linux-gnu-
else ifeq ($(shell type mips64-linux-gnu-ld >/dev/null 2>/dev/null; echo $$?), 0)
CROSS := mips64-linux-gnu-
else
else ifeq ($(shell type mips64-elf-ld >/dev/null 2>/dev/null; echo $$?), 0)
CROSS := mips64-elf-
endif

@@ -277,8 +417,6 @@ ifeq ($(TARGET_N64),1)
CC_CFLAGS := -fno-builtin
endif

INCLUDE_CFLAGS := -I include -I $(BUILD_DIR) -I $(BUILD_DIR)/include -I src -I .

# Check code syntax with host compiler
CC_CHECK := gcc -fsyntax-only -fsigned-char $(CC_CFLAGS) $(TARGET_CFLAGS) $(INCLUDE_CFLAGS) -std=gnu90 -Wall -Wextra -Wno-format-security -Wno-main -DNON_MATCHING -DAVOID_UB $(VERSION_CFLAGS) $(GRUCODE_CFLAGS)

@@ -300,7 +438,51 @@ ifeq ($(shell getconf LONG_BIT), 32)
export QEMU_GUEST_BASE := 1
else
# Ensure that gcc treats the code as 32-bit
CC_CHECK += -m32
CC_CHECK += $(BITS)
endif

else # TARGET_N64

AS := as
ifneq ($(TARGET_WEB),1)
CC := $(CROSS)gcc
CXX := $(CROSS)g++
else
CC := emcc
endif
ifeq ($(WINDOWS_BUILD),1)
LD := $(CXX)
else
LD := $(CC)
endif
CPP := cpp -P
OBJDUMP := objdump
OBJCOPY := objcopy
PYTHON := python3

ifeq ($(WINDOWS_BUILD),1)
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) `$(CROSS)sdl2-config --cflags`
CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv `$(CROSS)sdl2-config --cflags`
else ifeq ($(TARGET_WEB),1)
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -s USE_SDL=2
CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv -s USE_SDL=2
else
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) `$(CROSS)pkg-config --cflags libusb-1.0 glfw3` `$(CROSS)sdl2-config --cflags`
CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv `$(CROSS)pkg-config --cflags libusb-1.0 glfw3` `$(CROSS)sdl2-config --cflags`
endif

ASFLAGS := -I include -I $(BUILD_DIR) $(VERSION_ASFLAGS)

ifeq ($(TARGET_WEB),1)
LDFLAGS := -lm -lGL -lSDL2 -no-pie -s TOTAL_MEMORY=20MB -g4 --source-map-base http://localhost:8080/ -s "EXTRA_EXPORTED_RUNTIME_METHODS=['callMain']"
else
ifeq ($(WINDOWS_BUILD),1)
LDFLAGS := $(BITS) -march=$(TARGET_ARCH) -Llib -lpthread -lglew32 `$(CROSS)sdl2-config --static-libs` -lm -lglu32 -lsetupapi -ldinput8 -luser32 -lgdi32 -limm32 -lole32 -loleaut32 -lshell32 -lwinmm -lversion -luuid -lopengl32 -no-pie -static
else
LDFLAGS := $(BITS) -march=$(TARGET_ARCH) -lm -lGL `$(CROSS)sdl2-config --libs` -no-pie -lpthread `$(CROSS)pkg-config --libs libusb-1.0 glfw3` -lasound -lX11 -lXrandr -lpulse
endif
endif

endif

# Prevent a crash with -sopt
@@ -333,23 +515,32 @@ endif

###################### Dependency Check #####################

ifeq ($(TARGET_N64),1)
BINUTILS_VER_MAJOR := $(shell $(LD) --version | grep ^GNU | sed 's/^.* //; s/\..*//g')
BINUTILS_VER_MINOR := $(shell $(LD) --version | grep ^GNU | sed 's/^[^.]*\.//; s/\..*//g')
BINUTILS_DEPEND := $(shell expr $(BINUTILS_VER_MAJOR) \>= 2 \& $(BINUTILS_VER_MINOR) \>= 27)
ifeq ($(BINUTILS_DEPEND),0)
$(error binutils version 2.27 required, version $(BINUTILS_VER_MAJOR).$(BINUTILS_VER_MINOR) detected)
endif
endif

######################## Targets #############################

ifeq ($(TARGET_N64),1)
all: $(ROM)
ifeq ($(COMPARE),1)
@$(SHA1SUM) -c $(TARGET).sha1 || (echo 'The build succeeded, but did not match the official ROM. This is expected if you are making changes to the game.\nTo silence this message, use "make COMPARE=0"'. && false)
endif
else
all: $(EXE)
endif

clean:
$(RM) -r $(BUILD_DIR_BASE)

cleantools:
$(MAKE) -s -C tools clean

distclean:
$(RM) -r $(BUILD_DIR_BASE)
./extract_assets.py --clean
@@ -402,6 +593,7 @@ $(BUILD_DIR)/bin/segment2.o: $(BUILD_DIR)/text/$(VERSION)/define_text.inc.c
endif
endif


$(BUILD_DIR)/text/%/define_courses.inc.c: text/define_courses.inc.c text/%/courses.h
$(CPP) $(VERSION_CFLAGS) $< -o $@ -I text/$*/
$(TEXTCONV) charmap.txt $@ $@
@@ -410,6 +602,8 @@ $(BUILD_DIR)/text/%/define_text.inc.c: text/define_text.inc.c text/%/courses.h t
$(CPP) $(VERSION_CFLAGS) $< -o $@ -I text/$*/
$(TEXTCONV) charmap.txt $@ $@

O_FILES += $(wildcard $(BUILD_DIR)/bin/$(VERSION)/*.o)

ALL_DIRS := $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(SRC_DIRS) $(ASM_DIRS) $(GODDARD_SRC_DIRS) $(ULTRA_SRC_DIRS) $(ULTRA_ASM_DIRS) $(ULTRA_BIN_DIRS) $(BIN_DIRS) $(TEXTURE_DIRS) $(TEXT_DIRS) $(SOUND_SAMPLE_DIRS) $(addprefix levels/,$(LEVEL_DIRS)) include) $(MIO0_DIR) $(addprefix $(MIO0_DIR)/,$(VERSION)) $(SOUND_BIN_DIR) $(SOUND_BIN_DIR)/sequences/$(VERSION)

# Make sure build directory exists before compiling anything
@@ -444,6 +638,7 @@ $(BUILD_DIR)/%.ci4: %.ci4.png

# compressed segment generation

ifeq ($(TARGET_N64),1)
# TODO: ideally this would be `-Trodata-segment=0x07000000` but that doesn't set the address

$(BUILD_DIR)/bin/%.elf: $(BUILD_DIR)/bin/%.o
@@ -473,6 +668,7 @@ $(BUILD_DIR)/%.mio0.o: $(BUILD_DIR)/%.mio0.s

$(BUILD_DIR)/%.mio0.s: $(BUILD_DIR)/%.mio0
printf ".section .data\n\n.incbin \"$<\"\n" > $@
endif

$(BUILD_DIR)/%.table: %.aiff
$(AIFF_EXTRACT_CODEBOOK) $< >$@
@@ -510,8 +706,30 @@ $(SOUND_BIN_DIR)/%.m64: $(SOUND_BIN_DIR)/%.o
$(SOUND_BIN_DIR)/%.o: $(SOUND_BIN_DIR)/%.s
$(AS) $(ASFLAGS) -o $@ $<

ifeq ($(TARGET_N64),1)
$(SOUND_BIN_DIR)/%.s: $(SOUND_BIN_DIR)/%
printf ".section .data\n\n.incbin \"$<\"\n" > $@
else
$(SOUND_BIN_DIR)/sound_data.ctl.c: $(SOUND_BIN_DIR)/sound_data.ctl
echo "unsigned char gSoundDataADSR[] = {" > $@
hexdump -v -e '1/1 "0x%X,"' $< >> $@
echo "};" >> $@

$(SOUND_BIN_DIR)/sound_data.tbl.c: $(SOUND_BIN_DIR)/sound_data.tbl
echo "unsigned char gSoundDataRaw[] = {" > $@
hexdump -v -e '1/1 "0x%X,"' $< >> $@
echo "};" >> $@

$(SOUND_BIN_DIR)/sequences.bin.c: $(SOUND_BIN_DIR)/sequences.bin
echo "unsigned char gMusicData[] = {" > $@
hexdump -v -e '1/1 "0x%X,"' $< >> $@
echo "};" >> $@

$(SOUND_BIN_DIR)/bank_sets.c: $(SOUND_BIN_DIR)/bank_sets
echo "unsigned char gBankSetsData[] = {" > $@
hexdump -v -e '1/1 "0x%X,"' $< >> $@
echo "};" >> $@
endif

$(BUILD_DIR)/levels/scripts.o: $(BUILD_DIR)/include/level_headers.h

@@ -578,6 +796,10 @@ $(GLOBAL_ASM_DEP).$(NON_MATCHING):
@rm -f $(GLOBAL_ASM_DEP).*
touch $@

$(BUILD_DIR)/%.o: %.cpp
@$(CXX) -fsyntax-only $(CFLAGS) -MMD -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
$(CXX) -c $(CFLAGS) -o $@ $<

$(BUILD_DIR)/%.o: %.c
@$(CC_CHECK) -MMD -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
$(CC) -c $(CFLAGS) -o $@ $<
@@ -590,6 +812,7 @@ $(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c
$(BUILD_DIR)/%.o: %.s
$(AS) $(ASFLAGS) -MD $(BUILD_DIR)/$*.d -o $@ $<

ifeq ($(TARGET_N64),1)
$(BUILD_DIR)/$(LD_SCRIPT): $(LD_SCRIPT)
$(CPP) $(VERSION_CFLAGS) -MMD -MP -MT $@ -MF $@.d -I include/ -I . -DBUILD_DIR=$(BUILD_DIR) -o $@ $<

@@ -610,6 +833,11 @@ $(ROM): $(ELF)
$(BUILD_DIR)/$(TARGET).objdump: $(ELF)
$(OBJDUMP) -D $< > $@

else
$(EXE): $(O_FILES) $(MIO0_FILES:.mio0=.o) $(SOUND_OBJ_FILES) $(ULTRA_O_FILES) $(GODDARD_O_FILES)
$(LD) -L $(BUILD_DIR) -o $@ $(O_FILES) $(SOUND_OBJ_FILES) $(ULTRA_O_FILES) $(GODDARD_O_FILES) $(LDFLAGS)
endif



.PHONY: all clean distclean default diff test load libultra


+ 0
- 0
asmdiff.jp.sh View File


+ 16
- 2
bin/segment2.c View File

@@ -2499,6 +2499,7 @@ static const Lights1 segment2_lights_unused = gdSPDefLights1(

// 0x02014470 - 0x020144B0
static const Mtx matrix_identity = {
#ifdef TARGET_N64
{{0x00010000, 0x00000000,
0x00000001, 0x00000000},
{0x00000000, 0x00010000,
@@ -2507,19 +2508,32 @@ static const Mtx matrix_identity = {
0x00000000, 0x00000000},
{0x00000000, 0x00000000,
0x00000000, 0x00000000}}
#else
{{1.0f, 0.0f, 0.0f, 0.0f},
{0.0f, 1.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 1.0f, 0.0f},
{0.0f, 0.0f, 0.0f, 1.0f}}
#endif
};


// 0x020144B0 - 0x020144F0
static const Mtx matrix_fullscreen = {
#if TARGET_N64
{{0x00000000, 0x00000000,
0x00000000, 0x00000000},
{0x00000000, 0xffff0000,
0xffffffff, 0xffff0001},
{0x01990000, 0x00000000,
0x00000222, 0x00000000},
{((65536 * 2 / SCREEN_WIDTH) << 16) | 0, 0x00000000,
(0 << 16) | (65536 * 2 / SCREEN_HEIGHT), 0x00000000},
{0x00000000, 0x00000000,
0x00000000, 0x00000000}}
#else
{{2.0f / SCREEN_WIDTH, 0.0f, 0.0f, 0.0f},
{0.0f, 2.0f / SCREEN_HEIGHT, 0.0f, 0.0f},
{0.0f, 0.0f, -1.0f, 0.0f},
{-1.0f, -1.0f, -1.0f, 1.0f}}
#endif
};




+ 2
- 2
extract_assets.py View File

@@ -215,7 +215,7 @@ def main():
input = image[pos : pos + size]
os.makedirs(os.path.dirname(asset), exist_ok=True)
if asset.endswith(".png"):
with tempfile.NamedTemporaryFile(prefix="asset") as png_file:
with tempfile.NamedTemporaryFile(prefix="asset", delete=False) as png_file:
png_file.write(input)
png_file.flush()
if asset.startswith("textures/skyboxes/") or asset.startswith("levels/ending/cake"):
@@ -278,4 +278,4 @@ def main():
f.write(output)


main()
main()

+ 2618
- 0
include/GL/eglew.h
File diff suppressed because it is too large
View File


+ 23686
- 0
include/GL/glew.h
File diff suppressed because it is too large
View File


+ 1775
- 0
include/GL/glxew.h
File diff suppressed because it is too large
View File


+ 1447
- 0
include/GL/wglew.h
File diff suppressed because it is too large
View File


+ 83
- 1
include/PR/gbi.h View File

@@ -87,6 +87,12 @@
*
*/

#ifdef F3DEX_GBI_2E
# ifndef F3DEX_GBI_2
# define F3DEX_GBI_2
# endif
#endif

#ifdef F3DEX_GBI_2
# ifndef F3DEX_GBI
# define F3DEX_GBI
@@ -1103,7 +1109,11 @@
* Vertex (set up for use with colors)
*/
typedef struct {
#ifdef TARGET_N64
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 */
@@ -1113,7 +1123,11 @@ typedef struct {
* Vertex (set up for use with normals)
*/
typedef struct {
#ifdef TARGET_N64
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 */
@@ -1162,6 +1176,7 @@ typedef struct {
unsigned char v[3];
} Tri;

#ifdef TARGET_N64
/*
* 4x4 matrix, fixed point s15.16 format.
* First 8 words are integer portion of the 4x4 matrix
@@ -1173,6 +1188,11 @@ typedef union {
Mtx_t m;
long long int force_structure_alignment;
} Mtx;
#else
typedef struct {
float m[4][4];
} Mtx;
#endif

/*
* Viewport
@@ -4396,6 +4416,26 @@ typedef union {
}}

/* Fraction never used in fill */
#ifdef F3DEX_GBI_2E
#define gDPFillRectangle(pkt, ulx, uly, lrx, lry) \
{ \
Gfx *_g0 = (Gfx *)(pkt), *_g1 = (Gfx *)(pkt); \
_g0->words.w0 = _SHIFTL(G_FILLRECT, 24, 8) | \
_SHIFTL((lrx), 2, 22); \
_g0->words.w1 = _SHIFTL((lry), 2, 22); \
_g1->words.w0 = _SHIFTL((ulx), 2, 22); \
_g1->words.w1 = _SHIFTL((uly), 2, 22); \
}
#define gsDPFillRectangle(ulx, uly, lrx, lry) \
{{ \
(_SHIFTL(G_FILLRECT, 24, 8) | _SHIFTL((lrx), 2, 22)), \
_SHIFTL((lry), 2, 22), \
}}, \
{{ \
_SHIFTL((ulx), 2, 22), \
_SHIFTL((uly), 2, 22), \
}}
#else
#define gDPFillRectangle(pkt, ulx, uly, lrx, lry) \
{ \
Gfx *_g = (Gfx *)(pkt); \
@@ -4404,15 +4444,16 @@ typedef union {
_SHIFTL((lrx), 14, 10) | _SHIFTL((lry), 2, 10));\
_g->words.w1 = (_SHIFTL((ulx), 14, 10) | _SHIFTL((uly), 2, 10));\
}

#define gsDPFillRectangle(ulx, uly, lrx, lry) \
{{ \
(_SHIFTL(G_FILLRECT, 24, 8) | _SHIFTL((lrx), 14, 10) | \
_SHIFTL((lry), 2, 10)), \
(_SHIFTL((ulx), 14, 10) | _SHIFTL((uly), 2, 10)) \
}}
#endif

/* like gDPFillRectangle but accepts negative arguments */
#ifndef F3DEX_GBI_2E
#define gDPScisFillRectangle(pkt, ulx, uly, lrx, lry) \
{ \
Gfx *_g = (Gfx *)(pkt); \
@@ -4423,6 +4464,7 @@ typedef union {
_g->words.w1 = (_SHIFTL(MAX((ulx),0), 14, 10) | \
_SHIFTL(MAX((uly),0), 2, 10)); \
}
#endif

#define gDPSetConvert(pkt, k0, k1, k2, k3, k4, k5) \
{ \
@@ -4620,6 +4662,46 @@ typedef union {
gImmp1(pkt, G_RDPHALF_2, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))); \
gImmp1(pkt, G_RDPHALF_CONT, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16))); \
}
#elif defined(F3DEX_GBI_2E)
# define gSPTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy)\
{ \
Gfx *_g0 = (Gfx *)(pkt), *_g1 = (Gfx *)(pkt), *_g2 = (Gfx *)(pkt); \
\
_g0->words.w0 = _SHIFTL(G_TEXRECT, 24, 8) | \
_SHIFTL((xh), 0, 24); \
_g0->words.w1 = _SHIFTL((yh), 0, 24); \
_g1->words.w0 = (_SHIFTL(tile, 24, 3) | _SHIFTL((xl), 0, 24)); \
_g1->words.w1 = _SHIFTL((yl), 0, 24); \
_g2->words.w0 = (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16)); \
_g2->words.w1 = (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16)); \
}

# define gsSPTextureRectangle(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \
{{ \
(_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL((xh), 0, 24)), \
_SHIFTL((yh), 0, 24), \
}}, \
{{ \
(_SHIFTL((tile), 24, 3) | _SHIFTL((xl), 0, 24)), \
_SHIFTL((yl), 0, 24), \
}}, \
{{ \
_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16), \
_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16) \
}}

# define gSPTextureRectangleFlip(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \
{ \
Gfx *_g0 = (Gfx *)(pkt), *_g1 = (Gfx *)(pkt), *_g2 = (Gfx *)(pkt); \
\
_g0->words.w0 = _SHIFTL(G_TEXRECTFLIP, 24, 8) | \
_SHIFTL((xh), 0, 24); \
_g0->words.w1 = _SHIFTL((yh), 0, 24); \
_g1->words.w0 = (_SHIFTL(tile, 24, 3) | _SHIFTL((xl), 0, 24)); \
_g1->words.w1 = _SHIFTL((yl), 0, 24); \
_g2->words.w0 = (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16)); \
_g2->words.w1 = (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16)); \
}
#else
# define gSPTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy)\
{ \


+ 3
- 3
include/PR/os_cont.h View File

@@ -53,14 +53,14 @@ extern "C" {
typedef struct {
u16 type; /* Controller Type */
u8 status; /* Controller status */
u8 errno;
u8 errnum;
}OSContStatus;

typedef struct {
u16 button;
s8 stick_x; /* -80 <= stick_x <= 80 */
s8 stick_y; /* -80 <= stick_y <= 80 */
u8 errno;
u8 errnum;
} OSContPad;

typedef struct {
@@ -68,7 +68,7 @@ typedef struct {
u8 databuffer[32]; /* address of the data buffer */
u8 addressCrc; /* CRC code for address */
u8 dataCrc; /* CRC code for data */
u8 errno;
u8 errnum;
} OSContRamIo;




+ 0
- 3
include/PR/os_pi.h View File

@@ -81,7 +81,4 @@ void osCreatePiManager(OSPri pri, OSMesgQueue *cmdQ, OSMesg *cmdBuf, s32 cmdMsgC
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

+ 2
- 0
include/PR/ultratypes.h View File

@@ -37,6 +37,8 @@ typedef s32 intptr_t;
typedef s32 ptrdiff_t;
#else
#include <stddef.h>
#include <stdint.h>
typedef ptrdiff_t ssize_t;
#endif

#endif

+ 5
- 0
include/config.h View File

@@ -28,10 +28,15 @@
#define SCREEN_HEIGHT 240

// Border Height Define for NTSC Versions
#ifdef TARGET_N64
#ifndef VERSION_EU
#define BORDER_HEIGHT 8
#else
#define BORDER_HEIGHT 1
#endif
#else
// What's the point of having a border?
#define BORDER_HEIGHT 0
#endif

#endif

+ 20
- 0
include/gfx_dimensions.h View File

@@ -0,0 +1,20 @@
#ifndef GFX_DIMENSIONS_H
#define GFX_DIMENSIONS_H

#ifndef TARGET_N64
#include <math.h>
#include "pc/gfx/gfx_pc.h"
#define GFX_DIMENSIONS_FROM_LEFT_EDGE(v) (SCREEN_WIDTH / 2 - SCREEN_HEIGHT / 2 * gfx_current_dimensions.aspect_ratio + (v))
#define GFX_DIMENSIONS_FROM_RIGHT_EDGE(v) (SCREEN_WIDTH / 2 + SCREEN_HEIGHT / 2 * gfx_current_dimensions.aspect_ratio - (v))
#define GFX_DIMENSIONS_RECT_FROM_LEFT_EDGE(v) floorf(GFX_DIMENSIONS_FROM_LEFT_EDGE(v))
#define GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(v) ceilf(GFX_DIMENSIONS_FROM_RIGHT_EDGE(v))
#define GFX_DIMENSIONS_ASPECT_RATIO (gfx_current_dimensions.aspect_ratio)
#else
#define GFX_DIMENSIONS_FROM_LEFT_EDGE(v) (v)
#define GFX_DIMENSIONS_FROM_RIGHT_EDGE(v) (SCREEN_WIDTH - (v))
#define GFX_DIMENSIONS_RECT_FROM_LEFT_EDGE(v) (v)
#define GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(v) (SCREEN_WIDTH - (v))
#define GFX_DIMENSIONS_ASPECT_RATIO (4.0f / 3.0f)
#endif

#endif

+ 6
- 0
include/level_commands.h View File

@@ -275,4 +275,10 @@
#define GET_OR_SET(op, var) \
CMD_BBBB(0x3C, 0x04, op, var)

#define ADV_DEMO() \
CMD_BBH(0x3D, 0x04, 0x0000)
#define CLEAR_DEMO_PTR() \
CMD_BBH(0x3E, 0x04, 0x0000)

#endif

+ 1
- 1
include/level_misc_macros.h View File

@@ -2,7 +2,7 @@
#define LEVEL_MISC_MACROS_H

#define MACRO_OBJECT_WITH_BEH_PARAM(preset, yaw, posX, posY, posZ, behParam) \
(((yaw * 0x10 / 45) << 9) | (preset + 0x1F)), posX, posY, posZ, behParam
((s16)((yaw * 0x10 / 45) << 9) | (preset + 0x1F)), posX, posY, posZ, behParam

#define MACRO_OBJECT(preset, yaw, posX, posY, posZ) \
MACRO_OBJECT_WITH_BEH_PARAM(preset, yaw, posX, posY, posZ, 0)


+ 7
- 0
include/macros.h View File

@@ -46,6 +46,7 @@
#define ALIGNED16
#endif

#ifdef TARGET_N64
// convert a virtual address to physical.
#define VIRTUAL_TO_PHYSICAL(addr) ((uintptr_t)(addr) & 0x1FFFFFFF)

@@ -54,5 +55,11 @@

// another way of converting virtual to physical
#define VIRTUAL_TO_PHYSICAL2(addr) ((u8 *)(addr) - 0x80000000U)
#else
// no conversion for pc port other than cast
#define VIRTUAL_TO_PHYSICAL(addr) ((uintptr_t)(addr))
#define PHYSICAL_TO_VIRTUAL(addr) ((uintptr_t)(addr))
#define VIRTUAL_TO_PHYSICAL2(addr) ((void *)(addr))
#endif

#endif

+ 10
- 0
include/segment_symbols.h View File

@@ -1,9 +1,15 @@
#ifndef SEGMENT_SYMBOLS_H
#define SEGMENT_SYMBOLS_H

#ifdef TARGET_N64
#define DECLARE_SEGMENT(name) \
extern u8 _##name##SegmentRomStart[]; \
extern u8 _##name##SegmentRomEnd[];
#else
#define DECLARE_SEGMENT(name) \
static u8 _##name##SegmentRomStart[1]; \
static u8 _##name##SegmentRomEnd[1];
#endif

#define DECLARE_ACTOR_SEGMENT(name) \
DECLARE_SEGMENT(name##_mio0) \
@@ -37,7 +43,11 @@ DECLARE_ACTOR_SEGMENT(group17)
DECLARE_SEGMENT(behavior)
DECLARE_SEGMENT(scripts)
DECLARE_SEGMENT(goddard)
#ifdef TARGET_N64
extern u8 _goddardSegmentStart[];
#else
static u8 _goddardSegmentStart[1];
#endif

DECLARE_LEVEL_SEGMENT(menu)
DECLARE_LEVEL_SEGMENT(intro)


+ 7
- 0
levels/intro/script.c View File

@@ -44,17 +44,24 @@ const LevelScript level_intro_entry_2[] = {
INIT_LEVEL(),
BLACKOUT(/*active*/ TRUE),
FIXED_LOAD(/*loadAddr*/ _goddardSegmentStart, /*romStart*/ _goddardSegmentRomStart, /*romEnd*/ _goddardSegmentRomEnd),
//LOAD_MARIO_HEAD(/*loadHeadID*/ REGULAR_FACE),
LOAD_MARIO_HEAD(/*loadHeadID*/ REGULAR_FACE),
LOAD_RAW(/*seg*/ 0x13, _behaviorSegmentRomStart, _behaviorSegmentRomEnd),
LOAD_MIO0_TEXTURE(/*seg*/ 0x0A, _title_screen_bg_mio0SegmentRomStart, _title_screen_bg_mio0SegmentRomEnd),
ALLOC_LEVEL_POOL(),

//AREA(/*index*/ 1, intro_geo_00035C),
//END_AREA(),
AREA(/*index*/ 1, intro_geo_00035C),
END_AREA(),

FREE_LEVEL_POOL(),
SLEEP(/*frames*/ 2),
BLACKOUT(/*active*/ FALSE),
//LOAD_AREA(/*area*/ 1),
CLEAR_DEMO_PTR(), // we need to do this or else file select will be tainted with inputs
GET_OR_SET(/*op*/ OP_GET, /*var*/ 5),
JUMP_IF(/*op*/ OP_EQ, /*arg*/ 1, script_intro_L1), // was start pressed when demo ended last time?
LOAD_AREA(/*area*/ 1),
SET_MENU_MUSIC(/*seq*/ 0x0002),
TRANSITION(/*transType*/ WARP_TRANSITION_FADE_FROM_STAR, /*time*/ 20, /*color*/ 0x00, 0x00, 0x00),


+ 11
- 2
levels/menu/script.c View File

@@ -50,7 +50,7 @@ const LevelScript level_main_menu_entry_1[] = {
GET_OR_SET(/*op*/ OP_SET, /*var*/ VAR_CURR_SAVE_FILE_NUM),
STOP_MUSIC(/*fadeOutTime*/ 0x00BE),
TRANSITION(/*transType*/ WARP_TRANSITION_FADE_INTO_COLOR, /*time*/ 16, /*color*/ 0xFF, 0xFF, 0xFF),
SLEEP(/*frames*/ 16),
SLEEP(/*frames*/ 24),
CLEAR_LEVEL(),
SLEEP_BEFORE_EXIT(/*frames*/ 1),
SET_REG(/*value*/ LEVEL_CASTLE_GROUNDS),
@@ -72,15 +72,24 @@ const LevelScript level_main_menu_entry_2[] = {

/*25*/ FREE_LEVEL_POOL(),
/*26*/ LOAD_AREA(/*area*/ 2),
#ifndef TARGET_N64
// sVisibleStars is set to 0 during FIXED_LOAD above on N64, but not on PC-port.
// lvl_init_act_selector_values_and_stars must be called here otherwise the
// previous value is retained and causes incorrect drawing during the 16 transition
// frames.
CALL(/*arg*/ 0, /*func*/ lvl_init_act_selector_values_and_stars),
#endif
/*27*/ TRANSITION(/*transType*/ WARP_TRANSITION_FADE_FROM_COLOR, /*time*/ 16, /*color*/ 0xFF, 0xFF, 0xFF),
/*29*/ SLEEP(/*frames*/ 16),
/*30*/ SET_MENU_MUSIC(/*seq*/ 0x000D),
#ifdef TARGET_N64
/*31*/ CALL(/*arg*/ 0, /*func*/ lvl_init_act_selector_values_and_stars),
#endif
/*33*/ CALL_LOOP(/*arg*/ 0, /*func*/ lvl_update_obj_and_load_act_button_actions),
/*35*/ GET_OR_SET(/*op*/ OP_SET, /*var*/ VAR_CURR_ACT_NUM),
/*36*/ STOP_MUSIC(/*fadeOutTime*/ 0x00BE),
/*37*/ TRANSITION(/*transType*/ WARP_TRANSITION_FADE_INTO_COLOR, /*time*/ 16, /*color*/ 0xFF, 0xFF, 0xFF),
/*39*/ SLEEP(/*frames*/ 16),
/*39*/ SLEEP(/*frames*/ 24),
/*40*/ CLEAR_LEVEL(),
/*41*/ SLEEP_BEFORE_EXIT(/*frames*/ 1),
// L1:


+ 13
- 0
lib/src/guMtxF2L.c View File

@@ -1,5 +1,9 @@
#include "libultra_internal.h"
#ifndef TARGET_N64
#include <string.h>
#endif

#ifdef TARGET_N64
void guMtxF2L(float mf[4][4], Mtx *m) {
int r, c;
s32 tmp1;
@@ -35,6 +39,11 @@ void guMtxL2F(float mf[4][4], Mtx *m) {
}
}
}
#else
void guMtxF2L(float mf[4][4], Mtx *m) {
memcpy(m, mf, sizeof(Mtx));
}
#endif

void guMtxIdentF(float mf[4][4]) {
int r, c;
@@ -49,7 +58,11 @@ void guMtxIdentF(float mf[4][4]) {
}
}
void guMtxIdent(Mtx *m) {
#ifdef TARGET_N64
float mf[4][4];
guMtxIdentF(mf);
guMtxF2L(mf, m);
#else
guMtxIdentF(m->m);
#endif
}

+ 2
- 2
lib/src/osContInit.c View File

@@ -61,8 +61,8 @@ void __osContGetInitData(u8 *a0, OSContStatus *status) {
sp14 = &(D_80365CE0[0].request);
for (i = 0; i < _osCont_numControllers; i++, sp14++, status++) {
spc = *(OSContPackedRequest *) sp14;
status->errno = (spc.unk02 & 0xc0) >> 4;
if (status->errno == 0) {
status->errnum = (spc.unk02 & 0xc0) >> 4;
if (status->errnum == 0) {
status->type = spc.unk05 << 8 | spc.unk04;
status->status = spc.unk06;



+ 2
- 2
lib/src/osContStartReadData.c View File

@@ -41,8 +41,8 @@ void osContGetReadData(OSContPad *pad) {
spc = &D_80365CE0[0].read;
for (i = 0; i < _osCont_numControllers; i++, spc++, pad++) {
sp4 = *spc;
pad->errno = (sp4.unk02 & 0xc0) >> 4;
if (pad->errno == 0) {
pad->errnum = (sp4.unk02 & 0xc0) >> 4;
if (pad->errnum == 0) {
pad->button = sp4.button;
pad->stick_x = sp4.rawStickX;
pad->stick_y = sp4.rawStickY;


+ 4
- 0
readme2.txt View File

@@ -0,0 +1,4 @@
You need audiofile, sdl2, glew, glfw
for Windows you also need mingw32
>https://packages.msys2.org/base/mingw-w64-SDL2
>https://packages.msys2.org/base/mingw-w64-glew

+ 26
- 26
sound/sequences/00_sound_player.s View File

@@ -66,7 +66,7 @@ chan_stereoheadseteffects 1
chan_setdyntable .channel59_table
chan_jump .main_loop_023589

# Main loop for standard, non-continuous sound effects
.main_loop_023589:
chan_delay1
chan_ioreadval 0
@@ -80,17 +80,17 @@ chan_iowriteval 5
chan_ioreadval 4
chan_dyncall

# keep looping until layer 0 finishes or we are told to stop or to play something else
.poll_023589:
chan_delay1
chan_ioreadval 0
chan_bltz .skip_023589 # if we have a signal:
chan_beqz .force_stop_023589 # told to stop
chan_jump .start_playing_023589 # told to play something else
chan_bltz .skip_023589
chan_beqz .force_stop_023589
chan_jump .start_playing_023589
.skip_023589:
chan_testlayerfinished 0
chan_beqz .poll_023589 # if layer 0 hasn't finished, keep polling
chan_jump .main_loop_023589 # otherwise go back to the main loop
chan_beqz .poll_023589
chan_jump .main_loop_023589
.force_stop_023589:
chan_freelayer 0
chan_freelayer 1
@@ -133,7 +133,7 @@ chan_stereoheadseteffects 1
chan_setdyntable .channel6_table
chan_jump .main_loop_146

# Main loop for moving, env and air sound effects, which play continuously
.main_loop_146:
chan_delay1
chan_ioreadval 0
@@ -148,7 +148,7 @@ chan_iowriteval 5
chan_ioreadval 4
chan_dyncall

# keep looping until we are told to stop or to play something else
.poll_146:
chan_delay1
chan_ioreadval 0
@@ -170,7 +170,7 @@ chan_iowriteval 5
chan_stereoheadseteffects 1
chan_setdyntable .channel7_table

# Loop for menu sound effects
.main_loop_7:
chan_delay1
chan_ioreadval 0
@@ -187,19 +187,19 @@ chan_setpanmix 127
chan_ioreadval 4
chan_dyncall

# keep looping until layer 0 finishes or we are told to stop or to play something else
.poll_7:
chan_delay1
chan_ioreadval 0
chan_bltz .skip_7 # if we have a signal:
chan_beqz .force_stop_7 # told to stop
chan_bltz .skip_7
chan_beqz .force_stop_7
chan_unreservenotes
chan_jump .start_playing_7 # told to play something else
chan_jump .start_playing_7
.skip_7:
chan_testlayerfinished 0
chan_beqz .poll_7 # if layer 0 hasn't finished, keep polling
chan_beqz .poll_7
chan_unreservenotes
chan_jump .main_loop_7 # otherwise go back to the main loop
chan_jump .main_loop_7
.force_stop_7:
chan_freelayer 0
chan_freelayer 1
@@ -207,7 +207,7 @@ chan_freelayer 2
chan_unreservenotes
chan_jump .main_loop_7

# Delay for a number of ticks (1-255) in an interruptible manner.
.delay:
chan_writeseq_nextinstr 0, 1
chan_loop 20
@@ -222,15 +222,15 @@ chan_end
chan_setpanmix 127
chan_setvolscale 127
chan_setvibratoextent 0
chan_ioreadval 1 # IO slots 0-3 are reset to -1 when read; restore the value
chan_ioreadval 1
chan_iowriteval 0
chan_break # break out of the loop
chan_break # force the caller to return immediately
chan_break
chan_break
chan_end

# Set reverb in way that takes area echo level and volume into account. This
# is done by writing to IO slot 5 and letting get_sound_reverb in external.c
# do the necessary math.
.set_reverb:
chan_writeseq_nextinstr 0, 1
chan_setreverb 10
@@ -977,7 +977,7 @@ layer_portamento 0x81, 42, 255
layer_note1 37, 0x1e, 105
layer_end

.sound_action_climb_down_tree: # unused
.sound_action_climb_down_tree:
chan_setbank 0
chan_setinstr 1
chan_setlayer 0, .layer_579
@@ -988,7 +988,7 @@ layer_portamento 0x81, 44, 255
layer_note1 40, 0xb4, 100
layer_end

.chan_582: # unused
.chan_582:
chan_setbank 0
chan_setinstr 2
chan_setlayer 0, .layer_58A
@@ -1408,7 +1408,7 @@ layer_note1 42, 0x8, 127
layer_end

.ifndef VERSION_JP
.chan_828: # unused
.chan_828:
chan_setbank 7
chan_setinstr 3
chan_setlayer 0, .layer_83C


+ 19
- 0
src/audio/external.c View File

@@ -765,6 +765,7 @@ void func_eu_802e9bec(s32 player, s32 channel, s32 arg2) {

#else

#ifdef TARGET_N64
struct SPTask *create_next_audio_frame_task(void) {
u32 samplesRemainingInAI;
s32 writtenCmds;
@@ -868,6 +869,24 @@ struct SPTask *create_next_audio_frame_task(void) {
return gAudioTask;
}
#endif
#endif

#ifndef TARGET_N64
struct SPTask *create_next_audio_frame_task(void) {
return NULL;
}
void create_next_audio_buffer(s16 *samples, u32 num_samples) {
gAudioFrameCount++;
if (sGameLoopTicked != 0) {
update_game_sound();
sGameLoopTicked = 0;
}
s32 writtenCmds;
synthesis_execute(gAudioCmdBuffers[0], &writtenCmds, samples, num_samples);
gAudioRandom = ((gAudioRandom + gAudioFrameCount) * gAudioFrameCount);
decrease_sample_dma_ttls();
}
#endif

void play_sound(s32 soundBits, f32 *pos) {
sSoundRequests[sSoundRequestCount].soundBits = soundBits;


+ 2
- 0
src/audio/heap.c View File

@@ -651,10 +651,12 @@ s32 audio_shut_down_and_reset_step(void) {
*/
void wait_for_audio_frames(s32 frames) {
gAudioFrameCount = 0;
#ifdef TARGET_N64
// Sound thread will update gAudioFrameCount
while (gAudioFrameCount < frames) {
// spin
}
#endif
}
#endif



+ 3
- 1
src/audio/load.c View File

@@ -884,7 +884,7 @@ void audio_init() {
s32 lim2, lim3;
#endif
u32 size;
u64 *ptr64;
UNUSED u64 *ptr64;
void *data;
UNUSED s32 pad2;

@@ -902,6 +902,7 @@ void audio_init() {
((u64 *) gAudioHeap)[i] = 0;
}

#ifndef AVOID_UB
i = 0;
lim3 = ((uintptr_t) &gAudioGlobalsEndMarker - (uintptr_t) &gAudioGlobalsStartMarker) / 8;
ptr64 = &gAudioGlobalsStartMarker - 1;
@@ -909,6 +910,7 @@ void audio_init() {
i++;
ptr64[i] = 0;
}
#endif
#else
for (i = 0; i < gAudioHeapSize / 8; i++) {
((u64 *) gAudioHeap)[i] = 0;


+ 4
- 0
src/audio/port_eu.c View File

@@ -34,6 +34,7 @@ void decrease_sample_dma_ttls(void);
s32 audio_shut_down_and_reset_step(void);
void func_802ad7ec(u32);

#ifdef TARGET_N64
struct SPTask *create_next_audio_frame_task(void) {
u32 samplesRemainingInAI;
s32 writtenCmds;
@@ -114,12 +115,14 @@ struct SPTask *create_next_audio_frame_task(void) {
task = &gAudioTask->task.t;
task->type = M_AUDTASK;
task->flags = flags;
#if TARGET_N64
task->ucode_boot = rspF3DBootStart;
task->ucode_boot_size = (u8 *) rspF3DBootEnd - (u8 *) rspF3DBootStart;
task->ucode = rspAspMainStart;
task->ucode_data = rspAspMainDataStart;
task->ucode_size = 0x800; // (this size is ignored)
task->ucode_data_size = (rspAspMainDataEnd - rspAspMainDataStart) * sizeof(u64);
#endif
task->dram_stack = NULL;
task->dram_stack_size = 0;
task->output_buff = NULL;
@@ -130,6 +133,7 @@ struct SPTask *create_next_audio_frame_task(void) {
task->yield_data_size = 0;
return gAudioTask;
}
#endif

void eu_process_audio_cmd(struct EuAudioCmd *cmd) {
s32 i;


+ 4
- 0
src/audio/synthesis.c View File

@@ -9,6 +9,10 @@
#include "external.h"


#ifndef TARGET_N64
#include "../pc/mixer.h"
#endif

#define DMEM_ADDR_TEMP 0x0
#define DMEM_ADDR_UNCOMPRESSED_NOTE 0x180
#define DMEM_ADDR_ADPCM_RESAMPLED 0x20


+ 1
- 6
src/buffers/buffers.c View File

@@ -23,7 +23,7 @@ ALIGNED8 u8 gGfxSPTaskYieldBuffer[OS_YIELD_DATA_SIZE];
// 0x200 bytes
ALIGNED8 struct SaveBuffer gSaveBuffer;
// 0x190a0 bytes
struct GfxPool gGfxPools[2];
struct GfxPool gGfxPools[GFX_NUM_POOLS];


// Yield buffer for audio, 0x400 bytes. Stubbed out post-JP since the audio
@@ -37,8 +37,3 @@ ALIGNED8 u8 gAudioSPTaskYieldBuffer[OS_YIELD_AUDIO_SIZE];
#if !defined(F3DEX_GBI_SHARED) && !defined(VERSION_EU)
ALIGNED8 u8 gUnusedThread2Stack[0x1400];
#endif






+ 6
- 1
src/buffers/buffers.h View File

@@ -27,6 +27,11 @@ extern struct SaveBuffer gSaveBuffer;

extern u8 gGfxSPTaskStack[];

extern struct GfxPool gGfxPools[2];
#ifdef TARGET_N64
#define GFX_NUM_POOLS 2
#else
#define GFX_NUM_POOLS 1
#endif
extern struct GfxPool gGfxPools[GFX_NUM_POOLS];

#endif

+ 67
- 0
src/engine/level_script.c View File

@@ -1,4 +1,7 @@
#include <ultra64.h>
#ifndef TARGET_N64
#include <string.h>
#endif

#include "sm64.h"
#include "audio/external.h"
@@ -20,6 +23,7 @@
#include "math_util.h"
#include "surface_collision.h"
#include "surface_load.h"
#include "level_table.h"

#define CMD_SIZE_SHIFT (sizeof(void *) >> 3)
#define CMD_PROCESS_OFFSET(offset) ((offset & 3) | ((offset & ~3) << CMD_SIZE_SHIFT))
@@ -601,7 +605,17 @@ static void level_cmd_set_gamma(void) {

static void level_cmd_set_terrain_data(void) {
if (sCurrAreaIndex != -1) {
#ifdef TARGET_N64
gAreas[sCurrAreaIndex].terrainData = segmented_to_virtual(CMD_GET(void *, 4));
#else
Collision *data;
u32 size;

data = segmented_to_virtual(CMD_GET(void *, 4));
size = get_area_terrain_size(data) * sizeof(Collision);
gAreas[sCurrAreaIndex].terrainData = alloc_only_pool_alloc(sLevelPool, size);
memcpy(gAreas[sCurrAreaIndex].terrainData, data, size);
#endif
}
sCurrentCmd = CMD_NEXT;
}
@@ -615,7 +629,17 @@ static void level_cmd_set_rooms(void) {

static void level_cmd_set_macro_objects(void) {
if (sCurrAreaIndex != -1) {
#ifdef TARGET_N64
gAreas[sCurrAreaIndex].macroObjects = segmented_to_virtual(CMD_GET(void *, 4));
#else
MacroObject *data = segmented_to_virtual(CMD_GET(void *, 4));
s32 len = 0;
while (data[len++] != 0x001E) {
len += 4;
}
gAreas[sCurrAreaIndex].macroObjects = alloc_only_pool_alloc(sLevelPool, len * sizeof(MacroObject));
memcpy(gAreas[sCurrAreaIndex].macroObjects, data, len * sizeof(MacroObject));
#endif
}
sCurrentCmd = CMD_NEXT;
}
@@ -696,6 +720,8 @@ static void level_cmd_38(void) {
sCurrentCmd = CMD_NEXT;
}

extern int gPressedStart;

static void level_cmd_get_or_set_var(void) {
if (CMD_GET(u8, 2) == 0) {
switch (CMD_GET(u8, 3)) {
@@ -714,6 +740,9 @@ static void level_cmd_get_or_set_var(void) {
case 4:
gCurrAreaIndex = sRegister;
break;
case 5:
gPressedStart = sRegister;
break;
}
} else {
switch (CMD_GET(u8, 3)) {
@@ -732,12 +761,48 @@ static void level_cmd_get_or_set_var(void) {
case 4:
sRegister = gCurrAreaIndex;
break;
case 5:
sRegister = gPressedStart;
break;
}
}

sCurrentCmd = CMD_NEXT;
}

int gDemoLevels[7] = {
LEVEL_BOWSER_1,
LEVEL_WF,
LEVEL_CCM,
LEVEL_BBH,
LEVEL_JRB,
LEVEL_HMC,
LEVEL_PSS
};

int gDemoLevelID = 0;
int gDemoInputListID_2 = 0;

extern int start_demo(int);

static void level_cmd_advdemo(void)
{
start_demo(0);
if(gDemoLevelID == 6) {
sRegister = gDemoLevels[6];
gDemoLevelID = 0;
} else {
sRegister = gDemoLevels[gDemoLevelID++];
}
sCurrentCmd = CMD_NEXT;
}

static void level_cmd_cleardemoptr(void)
{
gCurrDemoInput = NULL;
sCurrentCmd = CMD_NEXT;
}

static void (*LevelScriptJumpTable[])(void) = {
/*00*/ level_cmd_load_and_execute,
/*01*/ level_cmd_exit_and_execute,
@@ -800,6 +865,8 @@ static void (*LevelScriptJumpTable[])(void) = {
/*3A*/ level_cmd_3A,
/*3B*/ level_cmd_create_whirlpool,
/*3C*/ level_cmd_get_or_set_var,
/*3D*/ level_cmd_advdemo,
/*3E*/ level_cmd_cleardemoptr,
};

struct LevelCommand *level_script_execute(struct LevelCommand *cmd) {


+ 51
- 0
src/engine/surface_load.c View File

@@ -533,6 +533,57 @@ void alloc_surface_pools(void) {
reset_red_coins_collected();
}

#ifndef TARGET_N64
/**
* Get the size of the terrain data, to get the correct size when copying later.
*/
u32 get_area_terrain_size(s16 *data) {
s16 *startPos = data;
s32 end = FALSE;
s16 terrainLoadType;
s32 numVertices;
s32 numRegions;
s32 numSurfaces;
s16 hasForce;

while (!end) {
terrainLoadType = *data++;

switch (terrainLoadType) {
case TERRAIN_LOAD_VERTICES:
numVertices = *data++;
data += 3 * numVertices;
break;

case TERRAIN_LOAD_OBJECTS:
data += get_special_objects_size(data);
break;

case TERRAIN_LOAD_ENVIRONMENT:
numRegions = *data++;
data += 6 * numRegions;
break;

case TERRAIN_LOAD_CONTINUE:
continue;

case TERRAIN_LOAD_END:
end = TRUE;
break;

default:
numSurfaces = *data++;
hasForce = surface_has_force(terrainLoadType);
data += (3 + hasForce) * numSurfaces;
break;
}
}

return data - startPos;
}
#endif


/**
* Process the level file, loading in vertices, surfaces, some objects, and environmental
* boxes (water, gas, JRB fog).


+ 3
- 0
src/engine/surface_load.h View File

@@ -28,6 +28,9 @@ extern struct Surface *sSurfacePool;
extern s16 sSurfacePoolSize;

void alloc_surface_pools(void);
#ifndef TARGET_N64
u32 get_area_terrain_size(s16 *data);
#endif
void load_area_terrain(s16 index, s16 *data, s8 *surfaceRooms, s16 *macroObjects);
void clear_dynamic_surfaces(void);
void load_object_collision_model(void);


+ 10
- 2
src/game/area.c View File

@@ -2,6 +2,7 @@

#include "area.h"
#include "sm64.h"
#include "gfx_dimensions.h"
#include "behavior_data.h"
#include "game_init.h"
#include "object_list_processor.h"
@@ -20,6 +21,8 @@
#include "save_file.h"
#include "level_table.h"

#include "gfx_dimensions.h"

struct SpawnInfo gPlayerSpawnInfos[1];
struct GraphNode *D_8033A160[0x100];
struct Area gAreaData[8];
@@ -104,6 +107,11 @@ void set_warp_transition_rgb(u8 red, u8 green, u8 blue) {
gWarpTransBlue = blue;
}

static int scale_x_to_correct_aspect_center(int x) {
f32 aspect = GFX_DIMENSIONS_ASPECT_RATIO;
return x + (SCREEN_HEIGHT * aspect / 2) - (SCREEN_WIDTH / 2);
}

void print_intro_text(void) {
#ifdef VERSION_EU
int language = eu_get_language();
@@ -111,9 +119,9 @@ void print_intro_text(void) {
if ((gGlobalTimer & 0x1F) < 20) {
if (gControllerBits == 0) {
#ifdef VERSION_EU
print_text_centered(160, 20, gNoControllerMsg[language]);
print_text_centered(SCREEN_WIDTH / 2, 20, gNoControllerMsg[language]);
#else
print_text_centered(160, 20, "NO CONTROLLER");
print_text_centered(scale_x_to_correct_aspect_center(SCREEN_WIDTH / 2), 20, "NO CONTROLLER");
#endif
} else {
#ifdef VERSION_EU


+ 1
- 1
src/game/crash_screen.c View File

@@ -4,7 +4,7 @@

#include "sm64.h"

#if defined(VERSION_EU) || defined(VERSION_SH)
#if defined(TARGET_N64) && (defined(VERSION_EU) || defined(VERSION_SH))

s32 _Printf(char *(*prout)(char *, const char *, size_t), char *dst, const char *fmt, va_list args);



+ 26
- 0
src/game/display.h View File

@@ -0,0 +1,26 @@
#ifndef _DISPLAY_H
#define _DISPLAY_H

#include "types.h"

#define GFX_POOL_SIZE 6400

extern u16 frameBufferIndex;
extern u32 gGlobalTimer;

// extern ? my_rdp_init(?);
// extern ? my_rsp_init(?);
// extern ? clear_z_buffer(?);
// extern ? display_frame_buffer(?);
extern void clear_frame_buffer(s32);
extern void clear_viewport(Vp *, s32);
// extern ? draw_screen_borders(?);
void make_viewport_clip_rect(Vp *viewport);
extern void init_render_image(void);
extern void end_master_display_list(void);
extern void func_80247D84(void);
extern void func_80247ED8(void);
extern void func_80247FAC(void);
extern void display_and_vsync(void);

#endif /* _DISPLAY_H */

+ 28
- 4
src/game/game_init.c View File

@@ -212,11 +212,13 @@ void create_task_structure(void) {
gGfxSPTask->msgqueue = &D_80339CB8;
gGfxSPTask->msg = (OSMesg) 2;
gGfxSPTask->task.t.type = M_GFXTASK;
#if TARGET_N64
gGfxSPTask->task.t.ucode_boot = rspF3DBootStart;
gGfxSPTask->task.t.ucode_boot_size = ((u8 *) rspF3DBootEnd - (u8 *) rspF3DBootStart);
gGfxSPTask->task.t.flags = 0;
gGfxSPTask->task.t.ucode = rspF3DStart;
gGfxSPTask->task.t.ucode_data = rspF3DDataStart;
#endif
gGfxSPTask->task.t.ucode_size = SP_UCODE_SIZE; // (this size is ignored)
gGfxSPTask->task.t.ucode_data_size = SP_UCODE_DATA_SIZE;
gGfxSPTask->task.t.dram_stack = (u64 *) gGfxSPTaskStack;
@@ -578,10 +580,16 @@ void setup_game_memory(void) {
load_segment_decompress(2, _segment2_mio0SegmentRomStart, _segment2_mio0SegmentRomEnd);
}

#ifndef TARGET_N64
static struct LevelCommand *levelCommandAddr;
#endif

// main game loop thread. runs forever as long as the game
// continues.
void thread5_game_loop(UNUSED void *arg) {
struct LevelCommand *addr;
#ifdef TARGET_N64
struct LevelCommand *levelCommandAddr;
#endif

setup_game_memory();
#ifdef VERSION_SH
@@ -595,18 +603,32 @@ void thread5_game_loop(UNUSED void *arg) {

set_vblank_handler(2, &gGameVblankHandler, &gGameVblankQueue, (OSMesg) 1);

// point addr to the entry point into the level script data.
addr = segmented_to_virtual(level_script_entry);
// point levelCommandAddr to the entry point into the level script data.
levelCommandAddr = segmented_to_virtual(level_script_entry);

play_music(SEQ_PLAYER_SFX, SEQUENCE_ARGS(0, SEQ_SOUND_PLAYER), 0);
set_sound_mode(save_file_get_sound_mode());

#ifdef TARGET_N64
func_80247ED8();
rendering_init();

while (1) {
#else
gGlobalTimer++;
}

void game_loop_one_iteration(void) {
#endif
// if the reset timer is active, run the process to reset the game.
if (gResetTimer) {

#ifdef TARGET_N64
draw_reset_bars();
continue;
#else
return;
#endif
}
profiler_log_thread5_time(THREAD5_START);

@@ -622,7 +644,7 @@ void thread5_game_loop(UNUSED void *arg) {
audio_game_loop_tick();
config_gfx_pool();
read_controller_inputs();
addr = level_script_execute(addr);
levelCommandAddr = level_script_execute(levelCommandAddr);
display_and_vsync();

// when debug info is enabled, print the "BUF %d" information.
@@ -631,5 +653,7 @@ void thread5_game_loop(UNUSED void *arg) {
// amount of free space remaining.
print_text_fmt_int(180, 20, "BUF %d", gGfxPoolEnd - (u8 *) gDisplayListHead);
}
#ifdef TARGET_N64
}
#endif
}

+ 4
- 0
src/game/geo_misc.c View File

@@ -46,7 +46,11 @@ s8 gFlyingCarpetState;
*
* Texture coordinates are s10.5 fixed-point, which means you should left-shift the actual coordinates by 5.
*/
#ifdef TARGET_N64
void make_vertex(Vtx *vtx, s32 n, s16 x, s16 y, s16 z, s16 tx, s16 ty, u8 r, u8 g, u8 b, u8 a) {
#else
void make_vertex(Vtx *vtx, s32 n, f32 x, f32 y, f32 z, s16 tx, s16 ty, u8 r, u8 g, u8 b, u8 a) {
#endif
vtx[n].v.ob[0] = x;
vtx[n].v.ob[1] = y;
vtx[n].v.ob[2] = z;


+ 6
- 0
src/game/geo_misc.h View File

@@ -12,9 +12,15 @@ enum FlyingCarpetState

extern s8 gFlyingCarpetState;

#ifdef TARGET_N64
extern void make_vertex(
Vtx *vtx, s32 n, s16 x, s16 y, s16 z, s16 tx, s16 ty, u8 r, u8 g, u8 b, u8 a
);
#else
extern void make_vertex(
Vtx *vtx, s32 n, f32 x, f32 y, f32 z, s16 tx, s16 ty, u8 r, u8 g, u8 b, u8 a
);
#endif
extern s16 round_float(f32);
extern Gfx *geo_exec_inside_castle_light(s32 callContext, struct GraphNode *node, f32 mtx[4][4]);
extern Gfx *geo_exec_flying_carpet_timer_update(s32 callContext, struct GraphNode *node,


+ 20
- 18
src/game/hud.c View File

@@ -1,6 +1,7 @@
#include <ultra64.h>

#include "sm64.h"
#include "gfx_dimensions.h"
#include "game_init.h"
#include "level_update.h"
#include "camera.h"
@@ -264,9 +265,9 @@ void render_hud_power_meter(void) {
* Renders the amount of lives Mario has.
*/
void render_hud_mario_lives(void) {
print_text(22, HUD_TOP_Y, ","); // 'Mario Head' glyph
print_text(38, HUD_TOP_Y, "*"); // 'X' glyph
print_text_fmt_int(54, HUD_TOP_Y, "%d", gHudDisplay.lives);
print_text(GFX_DIMENSIONS_RECT_FROM_LEFT_EDGE(22), HUD_TOP_Y, ","); // 'Mario Head' glyph
print_text(GFX_DIMENSIONS_RECT_FROM_LEFT_EDGE(38), HUD_TOP_Y, "*"); // 'X' glyph
print_text_fmt_int(GFX_DIMENSIONS_RECT_FROM_LEFT_EDGE(54), HUD_TOP_Y, "%d", gHudDisplay.lives);
}

/**
@@ -279,9 +280,9 @@ void render_hud_coins(void) {
}

#ifdef VERSION_JP
#define HUD_STARS_X 247
#define HUD_STARS_X 73
#else
#define HUD_STARS_X 242
#define HUD_STARS_X 78
#endif

/**
@@ -299,11 +300,12 @@ void render_hud_stars(void) {
showX = 1;
}

print_text(HUD_STARS_X, HUD_TOP_Y, "-"); // 'Star' glyph
print_text(GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(HUD_STARS_X), HUD_TOP_Y, "-"); // 'Star' glyph
if (showX == 1) {
print_text((HUD_STARS_X + 16), HUD_TOP_Y, "*"); // 'X' glyph
print_text(GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(HUD_STARS_X) + 16, HUD_TOP_Y, "*"); // 'X' glyph
}
print_text_fmt_int(((showX * 14) + (HUD_STARS_X + 16)), HUD_TOP_Y, "%d", gHudDisplay.stars);
print_text_fmt_int((showX * 14) + GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(HUD_STARS_X - 16),
HUD_TOP_Y, "%d", gHudDisplay.stars);
}

/**
@@ -333,13 +335,13 @@ void render_hud_timer(void) {
#ifdef VERSION_EU
switch (eu_get_language()) {
case LANGUAGE_ENGLISH:
print_text(170, 185, "TIME");
print_text(GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(150), 185, "TIME");
break;
case LANGUAGE_FRENCH:
print_text(165, 185, "TEMPS");
print_text(GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(155), 185, "TEMPS");
break;
case LANGUAGE_GERMAN:
print_text(170, 185, "ZEIT");
print_text(GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(150), 185, "ZEIT");
break;
}
#endif
@@ -348,14 +350,14 @@ void render_hud_timer(void) {

timerFracSecs = ((timerValFrames - (timerMins * 1800) - (timerSecs * 30)) & 0xFFFF) / 3;
#ifndef VERSION_EU
print_text(170, 185, "TIME");
print_text(GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(150), 185, "TIME");
#endif
print_text_fmt_int(229, 185, "%0d", timerMins);
print_text_fmt_int(249, 185, "%02d", timerSecs);
print_text_fmt_int(283, 185, "%d", timerFracSecs);
print_text_fmt_int(GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(91), 185, "%0d", timerMins);
print_text_fmt_int(GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(71), 185, "%02d", timerSecs);
print_text_fmt_int(GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(37), 185, "%d", timerFracSecs);
gSPDisplayList(gDisplayListHead++, dl_hud_img_begin);
render_hud_tex_lut(239, 32, (*hudLUT)[GLYPH_APOSTROPHE]);
render_hud_tex_lut(274, 32, (*hudLUT)[GLYPH_DOUBLE_QUOTE]);
render_hud_tex_lut(GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(81), 32, (*hudLUT)[GLYPH_APOSTROPHE]);
render_hud_tex_lut(GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(46), 32, (*hudLUT)[GLYPH_DOUBLE_QUOTE]);
gSPDisplayList(gDisplayListHead++, dl_hud_img_end);
}

@@ -377,7 +379,7 @@ void render_hud_camera_status(void) {
s32 y;

cameraLUT = segmented_to_virtual(&main_hud_camera_lut);
x = 266;
x = GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(54);
y = 205;

if (sCameraHUD.status == CAM_STATUS_NONE) {


+ 33
- 5
src/game/ingame_menu.c View File

@@ -1,6 +1,7 @@
#include <ultra64.h>

#include "sm64.h"
#include "gfx_dimensions.h"
#include "memory.h"
#include "types.h"
#include "audio/external.h"
@@ -127,11 +128,15 @@ void create_dl_identity_matrix(void) {
return;
}

#ifdef TARGET_N64
matrix->m[0][0] = 0x00010000; matrix->m[1][0] = 0x00000000; matrix->m[2][0] = 0x00000000; matrix->m[3][0] = 0x00000000;
matrix->m[0][1] = 0x00000000; matrix->m[1][1] = 0x00010000; matrix->m[2][1] = 0x00000000; matrix->m[3][1] = 0x00000000;
matrix->m[0][2] = 0x00000001; matrix->m[1][2] = 0x00000000; matrix->m[2][2] = 0x00000000; matrix->m[3][2] = 0x00000000;
matrix->m[0][3] = 0x00000000; matrix->m[1][3] = 0x00000001; matrix->m[2][3] = 0x00000000; matrix->m[3][3] = 0x00000000;
#else
guMtxIdent(matrix);
#endif

gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH);
gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);
}
@@ -1793,13 +1798,26 @@ void render_dialog_entries(void) {

render_dialog_box_type(dialog, dialog->linesPerBox);

gDPSetScissor(gDisplayListHead++, G_SC_NON_INTERLACE, ensure_nonnegative(dialog->leftOffset),
gDPSetScissor(gDisplayListHead++, G_SC_NON_INTERLACE,
#ifdef TARGET_N64
ensure_nonnegative(dialog->leftOffset),
#else
0,
#endif
ensure_nonnegative(DIAG_VAL2 - dialog->width),
#ifdef VERSION_EU
#ifdef TARGET_N64
ensure_nonnegative(dialog->leftOffset + DIAG_VAL3 / gDialogBoxScale),
#else
SCREEN_WIDTH,
#endif
ensure_nonnegative((240 - dialog->width) + ((dialog->linesPerBox * 80) / DIAG_VAL4) / gDialogBoxScale));
#else
#ifdef TARGET_N64
ensure_nonnegative(DIAG_VAL3 + dialog->leftOffset),
#else
SCREEN_WIDTH,
#endif
ensure_nonnegative(240 + ((dialog->linesPerBox * 80) / DIAG_VAL4) - dialog->width));
#endif
#if defined(VERSION_JP) || defined(VERSION_SH)
@@ -2108,8 +2126,17 @@ void change_dialog_camera_angle(void) {
}

void shade_screen(void) {
create_dl_translation_matrix(MENU_MTX_PUSH, 0, 240.0f, 0);
create_dl_translation_matrix(MENU_MTX_PUSH, GFX_DIMENSIONS_FROM_LEFT_EDGE(0), 240.0f, 0);

// This is a bit weird. It reuses the dialog text box (width 130, height -80),
// so scale to at least fit the screen.
#ifdef TARGET_N64
create_dl_scale_matrix(MENU_MTX_NOPUSH, 2.6f, 3.4f, 1.0f);
#else
create_dl_scale_matrix(MENU_MTX_NOPUSH,
GFX_DIMENSIONS_ASPECT_RATIO * SCREEN_HEIGHT / 130.0f, 3.0f, 1.0f);
#endif

gDPSetEnvColor(gDisplayListHead++, 0, 0, 0, 110);
gSPDisplayList(gDisplayListHead++, dl_draw_text_bg_box);
gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW);
@@ -2145,7 +2172,7 @@ void render_pause_red_coins(void) {
s8 x;

for (x = 0; x < gRedCoinsCollected; x++) {
print_animated_red_coin(290 - x * 20, 16);
print_animated_red_coin(GFX_DIMENSIONS_FROM_RIGHT_EDGE(30) - x * 20, 16);
}
}

@@ -2437,7 +2464,8 @@ void print_hud_pause_colorful_str(void) {
gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, gDialogTextAlpha);

#ifdef VERSION_EU
print_hud_lut_string(HUD_LUT_GLOBAL, get_str_x_pos_from_center_scale(160, textPause, 12.0f), 81, textPause);
print_hud_lut_string(HUD_LUT_GLOBAL, get_str_x_pos_from_center_scale(