The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 895 - File: showthread.php PHP 7.3.33 (Linux)
File Line Function
/showthread.php 895 errorHandler->error




Users browsing this thread: 1 Guest(s)
Radom Battle and Boss Themes

#1
Posts: 3,970
Threads: 279
Thanks Received: 236
Thanks Given: 58
Joined: Oct 2011
Reputation: 65
Status
Tissue-aware
author: madsiur
version: 1.1
released on: 2016/04/28
Apply to a FF3us 1.0 ROM
Download


Files
randomsongsC2.asm: For implementation in bank $C2
randomsongsEE.asm: For implementation in bank $EE or any other bank

Apply with xkas 0.06
Command example: xkas randomsongsEE.asm romname.smc

Description

Randomize the battle theme and default boss song. By default the max number of song for the battle theme is 8 and 4 for the boss theme.

By default, battleTable and bossTable have their entries nullified with only the default song as entry. Replace the !noSong in a table  to add a song choice. You can also reduce or expand the tables. If your table has 50% or more of null values (!nosong) it is more efficient to reduce it in half (e.g. remove 4 lines for a 8 song table) than  nullifying most of the entries. You'll also need to change the !numSongBattle and/or !numSongBoss value(s).

What the code does is if he picks a null value it will choose a new random number and repick from the table. If tables are modified properly, the repick probability will always be less than 50%, e.g. 44% maximum for a 16 songs table. The probability of a total of 3 picks before getting a song is 19% maximum and for 4 picks or more is 8,5%. So basically there can be relooping and cycles wasted  but I don't consider it significant taking in account it was the easiest  solution code-wise.

To recap, if you want 12 possible songs for the battle theme, add 8 lines to the table and nullifie 4 entries (!noSong). Then you need to  change the !numSongBattle variable to $0F.


Extra notes: This is a hack that uses the default RNG table at $C0FD00,X, meaning for now it is a much random as the default RNG system can be. Also, having table that are 2^X entries is not the optimal system since cycles are wasted for repicking in case of null entries. I'm opened to suggestion to improve both aspect, especially having as an example a table of 10 entries for 10 songs, not a table of 16 entries with 6 null values in it.

Assembly file:
Code:
hirom   ; Don't change this.
header  ; Comment out if your ROM has no header.

; Configuration
!battleSongId = $24        ; Change only if you changed its value in the $C2BF3B table.
!bossSongId = $14        ; Change only if you changed its value in the $C2BF3B table.
!noSong = $FE            ; "null" song ID value.
!numSongBattle = $07    ; X - 1 battle songs, where X = 2^Y and Y <= 7.
!numSongBoss = $03        ; X - 1 boss songs, where X = 2^Y and Y <= 7.
                        ; In other words, these last two variable must equal
                        ; $01, $03, $07, $0F, $1F, $3F or $7F for respectively
                        ; 2, 4, 8, 16, 32, 64 or 128 songs.

; Code                    
org $C2BDB7
JSL randomness
BRA continue

; Code from above BRA up to here is skipped, since it is no longer needed
org $C2BDCD
continue:

; This can go anywhere where there is enough free space
org $EEAF01
randomness:
LDA $C2BF3B,X        ; Load song ID
CMP #$FF      
BEQ return            ; Branch if we keep the current music playing
CMP #!battleSongId    ; Check if battle song
BEQ getBattle
CMP #!bossSongId        ; Check if boss song
BEQ getBoss
BRA loadSong        ; otherwise just load the song
getBattle:
JSR getRandom        ; Get random number
AND #!numSongBattle    ; Reduce it to a number from 0 to 7
TAX
LDA battleTable,X    ; Load the table song
CMP #!noSong            ; Check if "null" value
BEQ getBattle        ; Get another random number if "null"
BRA loadSong        ; Otherwise load song
getBoss:
JSR getRandom        ; Get random number
AND #!numSongBoss    ; Reduce it to a number from 0 to 3
TAX
LDA bossTable,X        ; Load the table song
CMP #!noSong            ; Check if "null" value
BEQ getBoss            ; Get another random number if "null"
loadSong:            
STA $1301            ; Save song ID
LDA $11E4  
AND #$08                
BNE return    
JSL $C50004            ; Play song
return:
RTL

getRandom:
LDA $1F6D            ; Get RNG index
INC $1F6D            ; Increment RNG index
TAX                
LDA $C0FD00,X        ; Get random number
RTS

; It is more efficient to reduce a table to its half than
; nullifying 50% or more of its entries.
battleTable:
db $24
db !noSong
db !noSong
db !noSong
db !noSong
db !noSong
db !noSong
db !noSong

bossTable:
db $14
db !noSong
db !noSong
db !noSong
  Find
Quote  
[-] The following 1 user says Thank You to madsiur for this post:
  • Gi Nattak (03-08-2016)



Messages In This Thread
Radom Battle and Boss Themes - by madsiur - 03-08-2016, 05:56 PM
RE: Radom battle and boss themes - by Gi Nattak - 03-08-2016, 06:32 PM
RE: Radom battle and boss themes - by Lockirby2 - 03-08-2016, 10:40 PM
RE: Radom battle and boss themes - by madsiur - 03-08-2016, 11:20 PM

Forum Jump:

Users browsing this thread: 1 Guest(s)


Theme by Madsiur2017Custom Graphics by JamesWhite