I was wondering... What is the best way to store game data (in a NES game) that can be easily loaded and edited by a computer program (written in something like C)?
There are many types of data in the game, some fixed sized entries, as well as variable sized entries. I want to keep game data on 2 fixed 16kb banks, and to just be two big files inc'ed into the needed bank.
Should I just use lookup table at the start of each data bank, or is there a better method?
I think the easiest to deal with would be lookup tables NOT split into two one byte list. Seems it would be easier to code and manage in my opinion.
Any comments welcome.
Storing game data
Moderator: Moderators
If you're going to be writing a C program, why not allocate space in the game for the data and have the C program directly edit the game? This could be later expanded to much more too like a game editor or something.
I would do the table route. For data of a defined size, store a table of structures containing the bank number (for switching) and a pointer to the address of the data. For variable size data, I'd say do the same but add a size constant.
I would do the table route. For data of a defined size, store a table of structures containing the bank number (for switching) and a pointer to the address of the data. For variable size data, I'd say do the same but add a size constant.
- never-obsolete
- Posts: 403
- Joined: Wed Sep 07, 2005 9:55 am
- Location: Phoenix, AZ
- Contact:
for variable length strings, i've seen things like this:
where the length is calculated by subtracting the low byte of the needed entry from the low byte of the entry that follows. you would also need a "terminating" pointer at the end of the table so your last string ends at the correct point.
Code: Select all
asl ; A=string entry index
tax
lda PtrTable, X ; get pointer
sta DataPtr
lda PtrTable + 1, X
sta DataPtr + 1
lda PtrTable + 2, X ; get length
sec
sbc PtrTable, X
tax
That was kind of my plan.If you're going to be writing a C program, why not allocate space in the game for the data and have the C program directly edit the game? This could be later expanded to much more too like a game editor or something.
I'm not sure I follow you there.I would do the table route. For data of a defined size, store a table of structures containing the bank number (for switching) and a pointer to the address of the data. For variable size data, I'd say do the same but add a size constant.
I figured I'd have main pointer table at the start of each bank. A routine on the fixed bank where the vectors are, would fetch the address by a one byte index value. Some of the main table entries can lead to other pointer tables on the same bank for variable length things like strings, etc.
Which would be load be the same routine.
When I need to load the first/next byte, just use a simple routine on the vectors bank.
Does this sound ok?
Here's what I meant in C:
Code: Select all
struct {
byte bank; /*the bank the data is in*/
word pointer; /*6502 address to start of data */
word size; /*size of data */
} entry;
entry table[256]; /*table of structures containing information on how to retrieve data items 0-255 */
write_bank(table[datanumber].bank); /* bankswitch to bank containing data */
size = table[datanumber].size;
address = table[datanumber].address;
while (size != 0) {
do_something(get(*address++));
size--;
}