Skip to content

Commit

Permalink
Rearrange the code of the SFX NSF, so that it's smaller.
Browse files Browse the repository at this point in the history
Now custom code goes at the back of the file instead of the front.
  • Loading branch information
aldonunez committed Feb 25, 2021
1 parent 10e0818 commit 37c7aa5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
Binary file modified Tools/ExtractRes/Data/nsf-sfx.bin
Binary file not shown.
16 changes: 8 additions & 8 deletions Tools/ExtractRes/Data/nsf-sfx.csv
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
src_name, src_addr, dst_addr, length
, 0, 0, 8080
rom, 2E04D, 20BD, 15
rom, 3AD94, 2E04, 2F
rom, 36EDF, 2F4F, 75
rom, 33EC8, 3F38, 148
rom, 3C010, 4080, 4000
, 0, 0, 6263
rom, 2E04D, BD, 15
rom, 3AD94, E04, 2F
rom, 36EDF, F4F, 75
rom, 33EC8, 1F38, 148
rom, 3C010, 2080, 4000
nsf-sfx.bin, 0, 0, 80
nsf-sfx.bin, 80, 80, 1E3
nsf-sfx.bin, 263, 7F28, 4
nsf-sfx.bin, 80, 6080, 1E3
nsf-sfx.bin, 263, 5F28, 4
29 changes: 14 additions & 15 deletions Tools/ExtractRes/NsfSfx/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,40 +51,39 @@ foreach ( $line in gc $mapPath )

# The output NSF is arranged as follows (bank refers to 4 KiB NSF banks, not NES mapper banks):
# - header: $80 bytes
# - bank 0: custom code, padded to full bank size
# - bank 1: empty (filled with zero)
# - bank 2: code beginning at $A000
# - bank 3: code beginning at $B000
# - bank 4: code beginning at $C000
# - bank 5: code beginning at $D000
# - bank 6: code beginning at $E000
# - bank 7: code beginning at $F000
# - bank 0: code beginning at $A000
# - bank 1: code beginning at $B000
# - bank 2: code beginning at $C000
# - bank 3: code beginning at $D000
# - bank 4: code beginning at $E000
# - bank 5: code beginning at $F000
# - bank 6: custom code, not padded
#
# The Bankswitch Init values in the header are all zero to reflect this layout.
# The Bankswitch Init values in the header are { 6, 6, 0, 1, 2, 3, 4, 5 } to reflect this layout.

$customBeforeExitSize = $segments["EXIT"].Address - 0x8000
$customBeforeExitSizeHex = "{0:X}" -f $customBeforeExitSize
$exitSizeHex = "{0:X}" -f $segments["EXIT"].Size
$exitSrcOffsetHex = "{0:X}" -f ($segments["EXIT"].Address - 0x8000 + $segments["HEADER"].Size)
$nsfSizeHex = "{0:X}" -f 0x8080
$nsfSizeHex = "{0:X}" -f (0x80 + 0x6000 + $customBeforeExitSize)

function GetNsfOffset( $romAddr )
{
$romAddr - 0x8000 + 0x80
$romAddr - 0xA000 + 0x80
}

function redirect( $path, [parameter(ValueFromPipeline)] $p ) { $p | out-file -encoding ascii $path }
function append( $path, [parameter(ValueFromPipeline)] $p ) { $p | out-file -encoding ascii -append $path }

echo "src_name, src_addr, dst_addr, length" | redirect $specPath
echo ", 0, 0, $nsfSizeHex" | append $specPath
echo ("rom, 2E04D, {0:X}, 15" -f (GetNsfOffset 0xA03D)) | append $specPath # Chaos rumble
echo ("rom, 3AD94, {0:X}, 2F" -f (GetNsfOffset 0xAD84)) | append $specPath # Menu confirm and cursor
echo ("rom, 36EDF, {0:X}, 75" -f (GetNsfOffset 0xAECF)) | append $specPath # Minigame error
echo ("rom, 2E04D, {0:X}, 15" -f (GetNsfOffset 0xA03D)) | append $specPath # Chaos rumble
echo ("rom, 3AD94, {0:X}, 2F" -f (GetNsfOffset 0xAD84)) | append $specPath # Menu confirm and cursor
echo ("rom, 36EDF, {0:X}, 75" -f (GetNsfOffset 0xAECF)) | append $specPath # Minigame error
echo ("rom, 33EC8, {0:X}, 148" -f (GetNsfOffset 0xBEB8)) | append $specPath # Battle SFX (magic, hurt, strike)
echo ("rom, 3C010, {0:X}, 4000" -f (GetNsfOffset 0xC000)) | append $specPath
echo ("$baseName.bin, 0, 0, 80") | append $specPath # Header
echo ("$baseName.bin, 80, 80, $customBeforeExitSizeHex") | append $specPath # Custom
echo ("$baseName.bin, 80, 6080, $customBeforeExitSizeHex") | append $specPath # Custom
echo ("$baseName.bin, $exitSrcOffsetHex, {0:X}, $exitSizeHex" -f (GetNsfOffset 0xFEA8)) | append $specPath

# The last entry overwrites the procedure that waits for a VBLANK, with a custom
Expand Down
2 changes: 1 addition & 1 deletion Tools/ExtractRes/NsfSfx/nsf-sfx.asm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
.BYTE $00, $00, $00, $00, $00, $00, $00, $00

.BYTE $00, $00 ; 6E Play speed, NSTC
.BYTE $00, $00, $00, $00, $00, $00, $00, $00 ; 70 Bankswitch init
.BYTE $06, $06, $00, $01, $02, $03, $04, $05 ; 70 Bankswitch init
.BYTE $00, $00 ; 78 Play speed, PAL
.BYTE $00 ; 7A PAL/NSTC bits
.BYTE $00 ; 7B Extra sound chip support
Expand Down

0 comments on commit 37c7aa5

Please sign in to comment.