Skip to content

Commit

Permalink
Add NWAV importer tools and use DMA 3 on NSMB.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGameratorT committed Aug 23, 2020
1 parent 988e693 commit 0743d22
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 3 deletions.
Binary file added MarioKartDS/tool/icon.ico
Binary file not shown.
Binary file added MarioKartDS/tool/nwav_import.exe
Binary file not shown.
116 changes: 116 additions & 0 deletions MarioKartDS/tool/nwav_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# RRWMC, July 4 2019
# TGT, July 13 2020

import sys
import pathlib

import ndspy.fnt
import ndspy.rom

print('Script credits:\n - RoadrunnerWMC\n - TheGameratorT')

def waitEnterExit():
input("\nPress Enter to exit...")

if (not (len(sys.argv) > 1)):
print('\nFor installing the table you can either: ')
print(' - Drag and drop your file into the script.')
print(' - Pass the file path as the first argument of the script.')
waitEnterExit()
sys.exit(0)

# Path to input rom
INPUT_ROM = sys.argv[1]
# Path to the output rom
OUTPUT_ROM = str(pathlib.Path(INPUT_ROM).with_suffix('')) + '_new.nds'

fID = 0
tSize = 0

def importFolder(fname, dirWaves):
global fID
global tSize

folder = ndspy.fnt.Folder(firstID=len(rom.files))
nfname = str(fID) + '_' + fname
dirWaves.folders.append((nfname, folder))
print(' /' + nfname)

for i in range(0, tSize):
rom.files.append([])
flname = 'track' + str(i).zfill(3) + '.nwav'
print(' /' + flname)
folder.files.append(flname)

print()
fID += 1

def askTableSize():
global tSize

txt = input("What is the size of your Nitro WAV table? (default is 76): ")
txt2 = txt
if(txt2[0] == '-'):
txt2 = txt2[1:]
if (txt2.isnumeric()):
n = int(txt)
if (n > 0):
if(n > 256):
print('Are you trying to ascend to the skies or...? Please keep your table size lower than 256.')
else:
tSize = n
return
else:
if (n == 0):
print('Genius, just for that, I will close myself.')
waitEnterExit()
sys.exit(0)
else:
print('Going negative? Really? How original of you.')
else:
print('Bruh, that is not even a number.')

askTableSize()

def askTempoTrack():
txt = input("Do you want to use separated tracks for final lap? (y-Yes | n-No): ").lower()
yes = ((txt == 'y') or (txt == 'yes'))
if (yes or ((txt == 'n') or (txt == 'no'))):
if (yes):
print('Pfft, now I need to import more files, why so rude?\n')
importFolder('final_lap', dirWaves)
return True
else:
print('Oh, ok.')
return False
else:
print('Bruh, that is not a valid option.')
return askTempoTrack()

print('\nDetected input file: ' + INPUT_ROM)
print('Destination file path: ' + OUTPUT_ROM)
print('\nCreating Nitro WAV table for the ROM.\n')

rom = ndspy.rom.NintendoDSRom.fromFile(INPUT_ROM)

askTableSize()

print('/waves')
dirWaves = ndspy.fnt.Folder(firstID=len(rom.files))
rom.filenames.folders.append(('waves', dirWaves))

importFolder('normal', dirWaves)
importFolder('lightning_bolt', dirWaves)

hqTempo = askTempoTrack()

rom.saveToFile(OUTPUT_ROM)

print('\nAll the Nitro WAV template files were created.')
tblStartFileID = str(rom.filenames.idOf('/waves/0_normal/track000.nwav'))
print('Table start file ID: ' + tblStartFileID)
print('Separate tracks for final lap: ' + str(hqTempo))
print('\nPlease change the following in the "NWAVPlayer_mkds.c" file:')
print(' "#define NWAV_HAS_HQ_TEMPO x" -> "#define NWAV_HAS_HQ_TEMPO ' + str(int(hqTempo)) + '"')
print(' "#define NWAV_FIRST_ID x" -> "#define NWAV_FIRST_ID ' + tblStartFileID + '"')
waitEnterExit()
6 changes: 3 additions & 3 deletions NSMBDS/source/NWAVPlayer_nsmb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ __attribute__((naked)) void repl_02012FC0()
asm("BX LR");
}

//Fix HDMA
void repl_02009434() {}
//FS uses DMA channel 3.
int repl_02009444() { return 3; }

/*=============================================================\
| NSMB playback control interface replacement. |
| This is where the Nitro WAV player is controlled. |
\=============================================================*/

constexpr int firstWavID = 2089;
constexpr int firstWavID = 2088;

//Backup the original functions
__attribute__((naked)) static void playSeq(int seqID, int sfxSetID) { asm("STMFD SP!, {R4,LR}\nB 0x02011E80"); }
Expand Down
Binary file added NSMBDS/tool/icon.ico
Binary file not shown.
Binary file added NSMBDS/tool/nwav_import.exe
Binary file not shown.
91 changes: 91 additions & 0 deletions NSMBDS/tool/nwav_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# RRWMC, July 4 2019
# TGT, July 13 2020

import sys
import pathlib

import ndspy.fnt
import ndspy.rom

print('Script credits:\n - RoadrunnerWMC\n - TheGameratorT')

def waitEnterExit():
input("\nPress Enter to exit...")

if (not (len(sys.argv) > 1)):
print('\nFor installing the table you can either: ')
print(' - Drag and drop your file into the script.')
print(' - Pass the file path as the first argument of the script.')
waitEnterExit()
sys.exit(0)

# Path to input rom
INPUT_ROM = sys.argv[1]
# Path to the output rom
OUTPUT_ROM = str(pathlib.Path(INPUT_ROM).with_suffix('')) + '_new.nds'

fID = 0
tSize = 0

def importFolder(dirWaves):
global fID
global tSize

for i in range(0, tSize):
rom.files.append([])
flname = 'track' + str(i).zfill(3) + '.nwav'
print(' /' + flname)
dirWaves.files.append(flname)

print()
fID += 1

def askTableSize():
global tSize

txt = input("What is the size of your Nitro WAV table? (default is 76): ")
txt2 = txt
if(txt2[0] == '-'):
txt2 = txt2[1:]
if (txt2.isnumeric()):
n = int(txt)
if (n > 0):
if(n > 256):
print('Are you trying to ascend to the skies or...? Please keep your table size lower than 256.')
else:
tSize = n
return
else:
if (n == 0):
print('Genius, just for that, I will close myself.')
waitEnterExit()
sys.exit(0)
else:
print('Going negative? Really? How original of you.')
else:
print('Bruh, that is not even a number.')

askTableSize()

print('\nDetected input file: ' + INPUT_ROM)
print('Destination file path: ' + OUTPUT_ROM)
print('\nCreating Nitro WAV table for the ROM.\n')

rom = ndspy.rom.NintendoDSRom.fromFile(INPUT_ROM)

askTableSize()

print('/waves')
dirWaves = ndspy.fnt.Folder(firstID=len(rom.files))
rom.filenames.folders.append(('waves', dirWaves))

importFolder(dirWaves)

rom.saveToFile(OUTPUT_ROM)

print('\nAll the Nitro WAV template files were created.')
tblStartFileID = str(rom.filenames.idOf('/waves/track000.nwav'))
print('Table start file ID: ' + tblStartFileID)
print('\nPlease change the following in the "NWAVPlayer_nsmb.cpp" file:')
print(' "constexpr int firstWavID = x;" -> "constexpr int firstWavID = ' + tblStartFileID + ';"')
waitEnterExit()

0 comments on commit 0743d22

Please sign in to comment.