Skip to content

Commit

Permalink
eliminate PROP/SONGPROP distinction, instead add group to PROP, and a…
Browse files Browse the repository at this point in the history
…dd a group type (SONGPROP is now a group type)
  • Loading branch information
bbbradsmith committed Apr 25, 2024
1 parent 3be17e7 commit 8e2a825
Show file tree
Hide file tree
Showing 11 changed files with 1,319 additions and 1,440 deletions.
19 changes: 2 additions & 17 deletions cmd/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,24 +136,9 @@ int main(int argc, char** argv)
if (nsfplay_prop_exists(core,i))
{
if (info.type == NSFP_PROP_TYPE_INT || info.type == NSFP_PROP_TYPE_LIST)
printf("%s: %d\n",info.key,nsfplay_prop_int(core,i));
printf("%s: %d\n",info.key,nsfplay_prop_int(core,i,-1));
else if (info.type == NSFP_PROP_TYPE_STR)
printf("%s: %s\n",info.key,nsfplay_prop_str(core,i));
else
printf("%s (%d)\n",info.key,info.type);
}
}
printf("SONGPROPS:\n");
for (int i=0;i<NSFP_SONGPROP_COUNT;++i)
{
NSFPropInfo info = nsfplay_songprop_info(core,i);
//printf("%s %s %d\n",info.key,info.name,info.type);
if (nsfplay_songprop_exists(core,i))
{
if (info.type == NSFP_PROP_TYPE_INT || info.type == NSFP_PROP_TYPE_LIST)
printf("%s: %d\n",info.key,nsfplay_songprop_int(core,i));
else if (info.type == NSFP_PROP_TYPE_STR)
printf("%s: %s\n",info.key,nsfplay_songprop_str(core,i));
printf("%s: %s\n",info.key,nsfplay_prop_str(core,i,-1));
else
printf("%s (%d)\n",info.key,info.type);
}
Expand Down
30 changes: 11 additions & 19 deletions core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ NSFSetGroupInfo NSFCore::group_info(sint32 group) const
info.key = GD.key;
info.name = local_text(GD.text+0);
info.desc = local_text(GD.text+1);
info.type = GD.type;
return info;
}

Expand Down Expand Up @@ -614,29 +615,20 @@ bool NSFCore::load(const uint8* data, uint32 size, bool assume, bool bin)
return result;
}

NSFPropInfo NSFCore::prop_info(sint32 prop, bool song) const
NSFPropInfo NSFCore::prop_info(sint32 prop) const
{
NSFPropInfo info = {0};
info.type = NSFP_PROP_TYPE_INVALID;
info.key = info.name = local_text(0);
const NSFPropData* PD;
if (!song)
{
if (prop < 0 || prop > NSFP_PROP_COUNT) return info;
PD = &NSFPD_PROP[prop];
}
else
{
if (prop < 0 || prop > NSFP_SONGPROP_COUNT) return info;
PD = &NSFPD_SONGPROP[prop];
}
info.key = PD->key;
info.name = local_text(PD->text);
info.max_list = PD->max_list;
info.list = (PD->list >= 0) ? (local_text(NSFPD_LIST_TEXT[PD->list]+1)) : NULL;
info.list_keys = (PD->list >= 0) ? (local_text(NSFPD_LIST_TEXT[PD->list]+0)) : NULL;
info.type = PD->type;
info.display = PD->display;
const NSFPropData& PD = NSFPD_PROP[prop];
info.key = PD.key;
info.name = local_text(PD.text);
info.max_list = PD.max_list;
info.group = PD.group;
info.list = (PD.list >= 0) ? (local_text(NSFPD_LIST_TEXT[PD.list]+1)) : NULL;
info.list_keys = (PD.list >= 0) ? (local_text(NSFPD_LIST_TEXT[PD.list]+0)) : NULL;
info.type = PD.type;
info.display = PD.display;
return info;
}

Expand Down
8 changes: 3 additions & 5 deletions core/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ typedef uint64_t uint64;
#define SETTING(setenum_) (setting[NSFP_SET_##setenum_])
#define PROP(propenum_) (nsf_prop_int(NSFP_PROP_##propenum_))
#define PROPS(propenum_) (nsf_prop_str(NSFP_PROP_##propenum_))
#define SONGPROP(songpropenum_) (nsf_prop_int(NSFP_SONGPROP_$$songpropenum_,song_current))
#define SONGPROPS(songpropenum_) (nsf_prop_str(NSFP_SONGPROP_$$songpropenum_,song_current))

// NSFCore structure, code members defined in core.cpp unless otherwised marked

Expand All @@ -55,7 +53,7 @@ typedef struct NSFCore_
// general rule of thumb:
// Try not to store unnecessary state.
// Use a setting directly instead of copying it, where possible.
// Use prop/songprop to look up instead of store values.
// Use prop to look up instead of store values.
// Can make exceptions for performance:
// Volume applies per-cycle/sample, should store that with fixed point adjustments.
// Square phase reset only applies per emulated-write, just use the setting directly.
Expand Down Expand Up @@ -145,7 +143,7 @@ typedef struct NSFCore_
bool parse_ini_line(const char* line, int len, int linenum); // linenum=-1 to parse a line with no INI file context

bool load(const uint8* data, uint32 size, bool assume, bool bin=false);
NSFPropInfo prop_info(sint32 prop, bool song=false) const; // if song, prop is a SONGPROP
NSFPropInfo prop_info(sint32 prop) const;

const char* local_text(sint32 textenum) const; // NSFP_TEXT_x for curent locale (local_text(0) is a default error string)
static const char* local_text(sint32 textenum, sint32 locale); // NSFP_TEXT_x for specific locale
Expand All @@ -154,7 +152,7 @@ typedef struct NSFCore_
bool nsf_parse(bool bin);
const uint8* nsfe_chunk(uint32 fourcc, uint32* chunk_size) const; // fourcc is packed little-endian into uint32
const uint8* nsfe_chunk(const char* fourcc, uint32* chunk_size) const;
bool nsf_prop_exists(sint32 prop, sint32 song=-1) const; // if song>=0 prop is a SONGPROP
bool nsf_prop_exists(sint32 prop, sint32 song=-1) const; // song<0 = song_current
sint32 nsf_prop_int(sint32 prop, sint32 song=-1) const;
sint64 nsf_prop_long(sint32 prop, sint32 song=-1) const;
const char* nsf_prop_str(sint32 prop, sint32 song=-1) const;
Expand Down
Loading

0 comments on commit 8e2a825

Please sign in to comment.