I feel like this should be simple, but I've been banging my head against the wall for 2 days with it.
I'm making a game using mapper 11. I only have two 32k PRG banks, one for the main game engine and the other is used to store a bunch of arrays containing 96 bytes of level data. Everything is basically working like I want it to, except I can't use memcpy to copy the array. Here is the code I have at the same address in PRG0 and PRG1
If I use this, the game resets. I'm guessing that what is happening is the code for memcpy doesn't exist in PRG1, and the first code the game encounters is the reset code, which switches back to PRG0 and resets (as it should). I've tried using a for loop instead of memcpy, but I have the same problem. I can copy each byte individually, but that's it.
Obviously this is hardly ideal, but at least it does show that I'm switching PRG banks successfully. Right now I just have extremely ugly, bloated code that I want to get rid of. I'm guessing that I'll have to write something in assembly that will copy data into my L_MAP array, but I'm having trouble wrapping my head around it for some reason.
I'm making a game using mapper 11. I only have two 32k PRG banks, one for the main game engine and the other is used to store a bunch of arrays containing 96 bytes of level data. Everything is basically working like I want it to, except I can't use memcpy to copy the array. Here is the code I have at the same address in PRG0 and PRG1
Code:
void Load_Array(void) {
do_Switch = 1;
while (do_Switch) {
new_bank = PRG_bank + CHR_bank;
change_reg(new_bank); // Call to bank switching routine
do_Switch = 0; // Break the loop so we can return
}
}
// At the same address in PRG1
void Load_Array1(void) {
do_Switch = 1;
while(do_Switch) {
new_bank = PRG_bank + CHR_bank;
change_reg(new_bank);
memcpy(L_MAP, All_Levels[level], 96);
PRG_bank = 0x00; // Send us back to PRG0
}
}
do_Switch = 1;
while (do_Switch) {
new_bank = PRG_bank + CHR_bank;
change_reg(new_bank); // Call to bank switching routine
do_Switch = 0; // Break the loop so we can return
}
}
// At the same address in PRG1
void Load_Array1(void) {
do_Switch = 1;
while(do_Switch) {
new_bank = PRG_bank + CHR_bank;
change_reg(new_bank);
memcpy(L_MAP, All_Levels[level], 96);
PRG_bank = 0x00; // Send us back to PRG0
}
}
If I use this, the game resets. I'm guessing that what is happening is the code for memcpy doesn't exist in PRG1, and the first code the game encounters is the reset code, which switches back to PRG0 and resets (as it should). I've tried using a for loop instead of memcpy, but I have the same problem. I can copy each byte individually, but that's it.
Code:
// I tried a for loop, but it also doesn't work.
for (A = 0; A < 96; ++A) {
L_MAP[A] = All_Levels[level][A];
}
// Even this doesn't work.
L_MAP[A] = All_Levels[level][A];
// This works, but is disgusting.
L_MAP[0] = All_Levels[level][0];
...
L_MAP[95] = All_Levels[level][95];
for (A = 0; A < 96; ++A) {
L_MAP[A] = All_Levels[level][A];
}
// Even this doesn't work.
L_MAP[A] = All_Levels[level][A];
// This works, but is disgusting.
L_MAP[0] = All_Levels[level][0];
...
L_MAP[95] = All_Levels[level][95];
Obviously this is hardly ideal, but at least it does show that I'm switching PRG banks successfully. Right now I just have extremely ugly, bloated code that I want to get rid of. I'm guessing that I'll have to write something in assembly that will copy data into my L_MAP array, but I'm having trouble wrapping my head around it for some reason.