Created
November 27, 2019 20:50
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ebpp | |
// IMPORTANT: Redefine these flags so they don't overlap with flags your project is already using | |
define flag_levelup_pc1 = flag 0x0a00 | |
define flag_levelup_pc2 = flag 0x0a01 | |
define flag_levelup_pc3 = flag 0x0a02 | |
command ifgoto (num, target) "[06 {short num} {long target}]" | |
command blue_magic_event_entry(flag1, flag2, flag3, flag4) { | |
"[{short flag1}]" | |
"[{short flag2}]" | |
"[{short flag3}]" | |
"[{short flag4}]" | |
} | |
command blue_magic_levelup_entry(required_level, psi_id, psi_flag, required_flag) { | |
"[{byte required_level}]" | |
"[{byte psi_id}]" | |
"[{short psi_flag}]" | |
"[{short required_flag}]" | |
} | |
command blue_magic_levelup_end "[00]" | |
// Text called before every battle | |
// IMPORTANT: You need to have every enemy's appearance text call this block | |
battle_pre: | |
unset(flag_levelup_pc1) | |
unset(flag_levelup_pc2) | |
unset(flag_levelup_pc3) | |
// Save the party members' levels from the beginning of the battle into memory for later reference | |
load8(10, 0x7E99D3) | |
load8(11, 0x7E9A32) | |
load8(12, 0x7E9A91) | |
load8(13, 0x7E9AF0) | |
eob | |
// You won text | |
ROM[0xEF79D7] = "{goto(you_won)}" | |
you_won: { | |
// Copied except removed homesickness trigger | |
"[18 06][1f 00 00 05][00] [1c 08 02][00][10 78]" | |
"[1f 41 11][1b 03 0a 7a ef 00]" // IMPORTANT: Remove this line if you want to disable homesickness | |
"[03][00]@[08 d7 e6 c7 00] gained [1c 0f] exp[08 ad 8f ef 00][14]" | |
eob | |
} | |
// Level up text | |
ROM[0xEF7A66] = "{goto(level_up)}" | |
level_up: { | |
"[01]@[1c 0e]'s level is[00] now [1c 0f]![14]" | |
ifgoto(flag_levelup_pc1, level_up_pc2) | |
load8(0, 0x7E99D3) | |
if neq(2, 0, 10) { | |
// "[01]@ness level up from " printd(1, 3) " to " printd(0, 3) ".[14]" | |
push(0) | |
psi_learn(1, blue_magic_data.pc1_psi_table) | |
pop | |
load8(10, 0x7E99D3) | |
eob | |
} | |
set(flag_levelup_pc1) | |
level_up_pc2: | |
ifgoto(flag_levelup_pc2, level_up_pc3) | |
load8(0, 0x7E9A32) | |
if neq(2, 0, 11) { | |
// "[01]@paula level up from " printd(1, 3) " to " printd(0, 3) ".[14]" | |
push(0) | |
psi_learn(2, blue_magic_data.pc2_psi_table) | |
pop | |
load8(11, 0x7E9A32) | |
eob | |
} | |
set(flag_levelup_pc2) | |
level_up_pc3: | |
ifgoto(flag_levelup_pc3, level_up_pc4) | |
load8(0, 0x7E9A91) | |
if neq(2, 0, 12) { | |
// "[01]@jeff level up from " printd(1, 3) " to " printd(0, 3) ".[14]" | |
load8(12, 0x7E9A91) | |
eob | |
} | |
set(flag_levelup_pc3) | |
level_up_pc4: | |
load8(0, 0x7E9AF0) | |
if neq(2, 0, 1) { | |
// "[01]@poo level up from " printd(1, 3) " to " printd(0, 3) ".[14]" | |
load8(13, 0x7E9AF0) | |
eob | |
} | |
"@error: no level up detected" prompt | |
eob | |
} | |
// the new level must be value on the top of the stack | |
command psi_learn(pc_num, psi_table_loc) { | |
peek(0) // reg0 = new level | |
load32c(1, psi_table_loc) // reg1 = current psi table offset | |
_loop: | |
// "loop start" next | |
pload8(2, 1) // reg2 = psi[i].required_level | |
// "req level: " printd(2, 3) ", new level: " printd(0, 3) next | |
if eqc(3, 2, 0) { // if psi[i].required_level == 0, then table has ended | |
// "table end" next | |
goto(_psi_learn_end) | |
} else if lte(3, 2, 0) { // if psi[i].required_level <= pc.level | |
// "required level lteq pc level" next | |
// if the required flag is set... | |
addc(3, 1, 4) | |
pload16(3, 3) // reg3 = psi[i].required_flag | |
if eqc(4, 3, 0) { | |
load32c(4, 1) // reg4 = 1 if reg3 == 0 (ie: no required flag) | |
} else { | |
check_flag_register(4, 3) // reg4 = 1 if reg3 flag is true | |
} | |
if eqc(4, 4, 1) { | |
// "required flag set" next | |
// and if the psi flag is unset... | |
addc(3, 1, 2) | |
pload16(3, 3) | |
check_flag_register(4, 3) | |
if eqc(4, 4, 0) { | |
// "psi flag unset" next | |
// Make the character learn the PSI | |
set_flag_register(3, 4, 5, 6) | |
"[01]" | |
sound(SND_LEARNPSI) | |
// Display the text | |
"@" name(pc_num) " realized the power of[00] " | |
addc(3, 1, 1) | |
pload8(3, 3) // reg3 = psi[i].psi_id | |
mov_argument_reg(3) | |
psiname(0) ".[14]" | |
// End | |
goto(_psi_learn_end) | |
} | |
} | |
} | |
addc(1, 1, 6) | |
goto(_loop) | |
_psi_learn_end: | |
} | |
// NOTE: x and flag_reg must be two different registers | |
command check_flag_register(x, flag_reg) { | |
push(flag_reg) | |
// get the address of the flag byte in memory | |
if (ltc(x, flag_reg, 0x401)) { | |
dec(flag_reg, flag_reg) // flag numbering starts at 1 | |
// divide by 8, number of bits in a byte | |
shr(flag_reg, flag_reg) | |
shr(flag_reg, flag_reg) | |
shr(flag_reg, flag_reg) | |
addc(flag_reg, flag_reg, 0x7E9C08) | |
} else { | |
dec(flag_reg, flag_reg) // flag numbering starts at 1 | |
subc(flag_reg, flag_reg, 0x400) | |
// divide by 8, number of bits in a byte | |
shr(flag_reg, flag_reg) | |
shr(flag_reg, flag_reg) | |
shr(flag_reg, flag_reg) | |
addc(flag_reg, flag_reg, 0x316000) | |
} | |
// read flag byte from memory | |
pload8(x, flag_reg) | |
// get the location of the flag bit in the flag byte | |
peek(flag_reg) | |
dec(flag_reg, flag_reg) // flag numbering starts at 1 | |
bwandc(flag_reg, flag_reg, 7) // flag_reg %= 8 | |
_loop: | |
// x >>= flag_reg | |
push(flag_reg) | |
if (eqc(flag_reg, flag_reg, 0)) { | |
pop | |
goto(_loop_end) | |
} | |
pull(flag_reg) | |
shr(x, x) | |
dec(flag_reg, flag_reg) | |
goto(_loop) | |
_loop_end: | |
bwandc(x, x, 1) // get the least significant bit only | |
pull(flag_reg) | |
} | |
command set_flag_register(flag_reg, tmp_reg1, tmp_reg2, tmp_reg3) { | |
push(tmp_reg1) | |
push(tmp_reg2) | |
push(tmp_reg3) | |
push(flag_reg) | |
// get the address of the flag byte in memory | |
if (ltc(tmp_reg1, flag_reg, 0x401)) { | |
dec(flag_reg, flag_reg) // flag numbering starts at 1 | |
// divide by 8, number of bits in a byte | |
shr(flag_reg, flag_reg) | |
shr(flag_reg, flag_reg) | |
shr(flag_reg, flag_reg) | |
addc(flag_reg, flag_reg, 0x7E9C08) | |
} else { | |
dec(flag_reg, flag_reg) // flag numbering starts at 1 | |
subc(flag_reg, flag_reg, 0x400) | |
// divide by 8, number of bits in a byte | |
shr(flag_reg, flag_reg) | |
shr(flag_reg, flag_reg) | |
shr(flag_reg, flag_reg) | |
addc(flag_reg, flag_reg, 0x316000) | |
} | |
// read flag byte from memory | |
pload8(tmp_reg1, flag_reg) | |
// set the flag bit to true | |
peek(tmp_reg2) | |
dec(tmp_reg2, tmp_reg2) | |
bwandc(tmp_reg2, tmp_reg2, 7) | |
if eqc(tmp_reg3, tmp_reg2, 0) { | |
bworc(tmp_reg1, tmp_reg1, 1) | |
} else if eqc(tmp_reg3, tmp_reg2, 1) { | |
bworc(tmp_reg1, tmp_reg1, 2) | |
} else if eqc(tmp_reg3, tmp_reg2, 2) { | |
bworc(tmp_reg1, tmp_reg1, 4) | |
} else if eqc(tmp_reg3, tmp_reg2, 3) { | |
bworc(tmp_reg1, tmp_reg1, 8) | |
} else if eqc(tmp_reg3, tmp_reg2, 4) { | |
bworc(tmp_reg1, tmp_reg1, 16) | |
} else if eqc(tmp_reg3, tmp_reg2, 5) { | |
bworc(tmp_reg1, tmp_reg1, 32) | |
} else if eqc(tmp_reg3, tmp_reg2, 6) { | |
bworc(tmp_reg1, tmp_reg1, 64) | |
} else if eqc(tmp_reg3, tmp_reg2, 7) { | |
bworc(tmp_reg1, tmp_reg1, 128) | |
} | |
// Write the altered flag byte | |
pstore8(tmp_reg1, flag_reg) | |
pull(flag_reg) | |
pull(tmp_reg3) | |
pull(tmp_reg2) | |
pull(tmp_reg1) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import blue_magic | |
define flag_test1 = flag 0x0b00 | |
define flag_test2 = flag 0x0b01 | |
define flag_test3 = flag 0x0b02 | |
// Section 1: Event Flag PSI Table | |
// This sets up which event flags enable which PSI on which characters | |
// This data is referenced by the PSI abilities table, thanks to the Blue Magic patch | |
// Default PSI - unlearnable | |
ROM[0xFE0000] = blue_magic_event_entry(0, 0, 0, 0) | |
// PSI Rockin 1 | |
ROM[0xFE0008] = blue_magic_event_entry(flag_test1, 0, 0, 0) | |
// Lifeup 1 | |
ROM[0xFE0010] = blue_magic_event_entry(flag_test2, 0, 0, 0) | |
// Healing 1 | |
ROM[0xFE0018] = blue_magic_event_entry(0, flag_test3, 0, 0) | |
// Section 2: Level-Up PSI Learning Table | |
// This table defines at which levels PSI is learned by characters during level-up. | |
pc1_psi_table: | |
blue_magic_levelup_entry(2, 23, flag_test2, 0) | |
blue_magic_levelup_end | |
pc2_psi_table: | |
blue_magic_levelup_end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[...] | |
1: | |
Action: 64 | |
# IMPORTANT - Set up these bytes in each entry to point to your entry in blue_magic_data.ccs | |
Level learned by Ness: 0x08 | |
Level learned by Paula: 0x00 | |
Level learned by Poo: 0xFE | |
PSI Menu position (X): 9 | |
PSI Menu position (Y): 0 | |
PSI Name: 1 | |
Strength: alpha | |
Text Address: $ef4e20 | |
Type: | |
- offense | |
Usability Outside of Battle: unusable | |
2: | |
Action: 11 | |
# IMPORTANT - Even unlearnable PSI need to point to an entry | |
Level learned by Ness: 0 | |
Level learned by Paula: 0 | |
Level learned by Poo: 0xFE | |
PSI Menu position (X): 11 | |
PSI Menu position (Y): 0 | |
PSI Name: 0 | |
Strength: beta | |
Text Address: $ef4e38 | |
Type: | |
- offense | |
Usability Outside of Battle: unusable | |
[...] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# IMPORTANT - You need to update the range below to cover all the data you're using in blue_magic_data.ccs | |
- (0x3e0000, 0x3e0020) # Blue Magic PSI table (see blue_magic_data.ccs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment