Skip to content

Commit

Permalink
fix locale table generation (shared array bug, also comparing index i…
Browse files Browse the repository at this point in the history
…nstead of key)

add unique entry verification to avoid accidentally masking entries
tweak date display
  • Loading branch information
bbbradsmith committed Apr 21, 2024
1 parent f9ff7b0 commit 6f23b3c
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 78 deletions.
119 changes: 56 additions & 63 deletions core/enums_data.h
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
#pragma once
// generated by nsfplayenums.py
// Sun Apr 21 03:40:40 2024
// 2024-04-21 04:21:35

#include "../include/nsfplayenums.h"

const int32_t NSFPD_LIST[NSFP_LIST_COUNT] = {
0, 2,
0, 1,
};

typedef struct {
const char* key;
int32_t text;
} NSFSetGroupData;
const NSFSetGroupData NSFPD_GROUP[NSFP_GROUP_COUNT] = {
{ "MAIN", 4 },
{ "APU0", 8 },
{ "APU1", 12 },
{ "MAIN", 2 },
{ "APU0", 4 },
{ "APU1", 6 },
};

typedef struct {
const char* key;
int32_t unit, text;
} NSFChannelData;
const NSFChannelData NSFPD_CHANNEL[NSFP_CHANNEL_COUNT] = {
{ "SQU0", 0, 16 },
{ "SQU1", 0, 18 },
{ "TRI", 1, 20 },
{ "NSE", 1, 22 },
{ "DPCM", 1, 24 },
{ "SQU0", 0, 8 },
{ "SQU1", 0, 9 },
{ "TRI", 1, 10 },
{ "NSE", 1, 11 },
{ "DPCM", 1, 12 },
};

typedef struct {
Expand All @@ -37,83 +37,75 @@ typedef struct {
const char* default_str;
} NSFSetData;
const NSFSetData NSFPD_SET[NSFP_SET_COUNT] = {
{ "VOLUME", 0, 26, 500, 0, 1000, -1,NULL },
{ "SAMPLERATE", 0, 30, 48000, 1000,4000000, -1,NULL },
{ "STEREO", 0, 34, 1, 0, 1, 0,NULL },
{ "TITLE_FORMAT", 0, 38, 0, 0, 0, -1,"%L (%n/%e) %T - %A" },
{ "LOCALE", 0, 42, 0, 0, 1, 1,NULL },
{ "SQU0_ON", 1, 46, 1, 0, 1, 0,NULL },
{ "SQU0_VOL", 1, 50, 500, 0, 1000, -1,NULL },
{ "SQU0_PAN", 1, 54, 500, 0, 1000, -1,NULL },
{ "SQU1_ON", 1, 58, 1, 0, 1, 0,NULL },
{ "SQU1_VOL", 1, 62, 500, 0, 1000, -1,NULL },
{ "SQU1_PAN", 1, 66, 500, 0, 1000, -1,NULL },
{ "TRI_ON", 2, 70, 1, 0, 1, 0,NULL },
{ "TRI_VOL", 2, 74, 500, 0, 1000, -1,NULL },
{ "TRI_PAN", 2, 78, 500, 0, 1000, -1,NULL },
{ "NSE_ON", 2, 82, 1, 0, 1, 0,NULL },
{ "NSE_VOL", 2, 86, 500, 0, 1000, -1,NULL },
{ "NSE_PAN", 2, 90, 500, 0, 1000, -1,NULL },
{ "DPCM_ON", 2, 94, 1, 0, 1, 0,NULL },
{ "DPCM_VOL", 2, 98, 500, 0, 1000, -1,NULL },
{ "DPCM_PAN", 2, 102, 500, 0, 1000, -1,NULL },
{ "VOLUME", 0, 13, 500, 0, 1000, -1,NULL },
{ "SAMPLERATE", 0, 15, 48000, 1000,4000000, -1,NULL },
{ "STEREO", 0, 17, 1, 0, 1, 0,NULL },
{ "TITLE_FORMAT", 0, 19, 0, 0, 0, -1,"%L (%n/%e) %T - %A" },
{ "LOCALE", 0, 21, 0, 0, 1, 1,NULL },
{ "SQU0_ON", 1, 23, 1, 0, 1, 0,NULL },
{ "SQU0_VOL", 1, 25, 500, 0, 1000, -1,NULL },
{ "SQU0_PAN", 1, 27, 500, 0, 1000, -1,NULL },
{ "SQU1_ON", 1, 29, 1, 0, 1, 0,NULL },
{ "SQU1_VOL", 1, 31, 500, 0, 1000, -1,NULL },
{ "SQU1_PAN", 1, 33, 500, 0, 1000, -1,NULL },
{ "TRI_ON", 2, 35, 1, 0, 1, 0,NULL },
{ "TRI_VOL", 2, 37, 500, 0, 1000, -1,NULL },
{ "TRI_PAN", 2, 39, 500, 0, 1000, -1,NULL },
{ "NSE_ON", 2, 41, 1, 0, 1, 0,NULL },
{ "NSE_VOL", 2, 43, 500, 0, 1000, -1,NULL },
{ "NSE_PAN", 2, 45, 500, 0, 1000, -1,NULL },
{ "DPCM_ON", 2, 47, 1, 0, 1, 0,NULL },
{ "DPCM_VOL", 2, 49, 500, 0, 1000, -1,NULL },
{ "DPCM_PAN", 2, 51, 500, 0, 1000, -1,NULL },
};

typedef struct {
const char* key;
int32_t type, text;
} NSFPropData;
const NSFPropData NSFPD_PROP[NSFP_PROP_COUNT] = {
{ "SONGCOUNT",1, 106 },
{ "LONG",2, 108 },
{ "TITLE",3, 110 },
{ "INFO",4, 112 },
{ "BLOB",5, 114 },
{ "SONGCOUNT",1, 53 },
{ "LONG",2, 54 },
{ "TITLE",3, 55 },
{ "INFO",4, 56 },
{ "BLOB",5, 57 },
};

typedef struct {
const char* key;
int32_t type, text;
} NSFSongPropData;
const NSFSongPropData NSFPD_SONGPROP[NSFP_SONGPROP_COUNT] = {
{ "INT",1, 116 },
{ "SONGTEST",1, 118 },
{ "LONG",2, 120 },
{ "TITLE",3, 122 },
{ "INFO",4, 124 },
{ "BLOB",5, 126 },
{ "INT",1, 58 },
{ "SONGTEST",1, 59 },
{ "LONG",2, 60 },
{ "TITLE",3, 61 },
{ "INFO",4, 62 },
{ "BLOB",5, 63 },
};

const int32_t NSFPD_TEXT[NSFP_LIST_COUNT] = {
128, 130,
64, 65,
};

const int32_t NSFPD_LOCAL_TEXT[NSFP_LOCALE_COUNT][132] = {
const int32_t NSFPD_LOCAL_TEXT[NSFP_LOCALE_COUNT][66] = {
{
0x000000,0x000000,0x000008,0x000008,0x00001B,0x000020,0x00001B,0x000020,0x00002E,0x000033,0x00002E,0x000033,0x00002E,0x00002E,0x00002E,0x00002E,
0x000057,0x000057,0x00005C,0x00005C,0x000061,0x000061,0x000065,0x000065,0x000069,0x000069,0x00006E,0x000075,0x00006E,0x000075,0x00007C,0x000087,
0x00007C,0x000087,0x000092,0x000099,0x000092,0x000099,0x0000A0,0x0000AD,0x0000A0,0x0000AD,0x0000C3,0x0000C3,0x0000C3,0x0000C3,0x0000CA,0x0000CA,
0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000D1,0x0000D1,0x0000D1,0x0000D1,0x0000D1,0x0000D1,
0x0000D1,0x0000D1,0x0000D1,0x0000D1,0x0000D1,0x0000D1,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,
0x0000D8,0x0000D8,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000E4,0x0000E4,
0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000EB,0x0000EB,0x0000F6,0x0000F6,0x0000FB,0x0000FB,
0x000101,0x000101,0x000106,0x000106,0x00010B,0x00010B,0x00010F,0x00010F,0x0000F6,0x0000F6,0x000119,0x000119,0x000101,0x000101,0x000106,0x000106,
0x000124,0x000124,0x000129,0x000129,
0x000000,0x000008,0x00001B,0x000020,0x00002E,0x000033,0x00002E,0x00002E,0x000057,0x00005C,0x000061,0x000065,0x000069,0x00006E,0x000075,0x00007C,
0x000087,0x000092,0x000099,0x0000A0,0x0000AD,0x0000C3,0x0000C3,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000D1,0x0000D1,0x0000D1,
0x0000D1,0x0000D1,0x0000D1,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000E4,
0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000EB,0x0000F6,0x0000FB,0x000101,0x000106,0x00010B,0x00010F,0x0000F6,0x000119,0x000101,0x000106,
0x000124,0x000136,
},
{
0x000000,0x000000,0x000008,0x000008,0x00001B,0x000020,0x00001B,0x000020,0x00002E,0x000033,0x00002E,0x000033,0x00002E,0x00002E,0x00002E,0x00002E,
0x000057,0x000057,0x00005C,0x00005C,0x000061,0x000061,0x000065,0x000065,0x000069,0x000069,0x00006E,0x000075,0x00006E,0x000075,0x00007C,0x000087,
0x00007C,0x000087,0x000092,0x000099,0x000092,0x000099,0x0000A0,0x0000AD,0x0000A0,0x0000AD,0x0000C3,0x0000C3,0x0000C3,0x0000C3,0x0000CA,0x0000CA,
0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000D1,0x0000D1,0x0000D1,0x0000D1,0x0000D1,0x0000D1,
0x0000D1,0x0000D1,0x0000D1,0x0000D1,0x0000D1,0x0000D1,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,
0x0000D8,0x0000D8,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000E4,0x0000E4,
0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000EB,0x0000EB,0x0000F6,0x0000F6,0x0000FB,0x0000FB,
0x000101,0x000101,0x000106,0x000106,0x00010B,0x00010B,0x00010F,0x00010F,0x0000F6,0x0000F6,0x000119,0x000119,0x000101,0x000101,0x000106,0x000106,
0x000124,0x000124,0x000129,0x000129,
0x000000,0x000008,0x00001B,0x000020,0x00002E,0x000033,0x00002E,0x00002E,0x000057,0x00005C,0x000061,0x000065,0x000069,0x00006E,0x000075,0x00007C,
0x000087,0x000092,0x000099,0x0000A0,0x0000AD,0x0000C3,0x0000C3,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000D1,0x0000D1,0x0000D1,
0x0000D1,0x0000D1,0x0000D1,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000E4,
0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000EB,0x0000F6,0x0000FB,0x000101,0x000106,0x00010B,0x00010F,0x0000F6,0x000119,0x000101,0x000106,
0x00012E,0x000141,
},
};

const uint8_t NSFPD_LOCAL_TEXT_DATA[0x000135] = {
const uint8_t NSFPD_LOCAL_TEXT_DATA[0x00014D] = {
0x4F,0x66,0x66,0x00,0x4F,0x6E,0x00,0x00,0x45,0x6E,0x67,0x6C,0x69,0x73,0x68,0x00,0xE6,0x97,0xA5,0xE6,0x9C,0xAC,0xE8,0xAA,0x9E,0x00,0x00,0x4D,0x61,0x69,0x6E,0x00,
0x4D,0x61,0x69,0x6E,0x20,0x53,0x65,0x74,0x74,0x69,0x6E,0x67,0x73,0x00,0x41,0x50,0x55,0x31,0x00,0x42,0x75,0x69,0x6C,0x74,0x2D,0x69,0x6E,0x20,0x74,0x72,0x69,0x61,
0x6E,0x67,0x6C,0x65,0x2C,0x20,0x6E,0x6F,0x69,0x73,0x65,0x2C,0x20,0x61,0x6E,0x64,0x20,0x44,0x50,0x43,0x4D,0x2E,0x00,0x53,0x51,0x55,0x30,0x00,0x53,0x51,0x55,0x31,
Expand All @@ -123,7 +115,8 @@ const uint8_t NSFPD_LOCAL_TEXT_DATA[0x000135] = {
0x61,0x74,0x00,0x4C,0x4F,0x43,0x41,0x4C,0x45,0x00,0x53,0x51,0x55,0x30,0x4F,0x4E,0x00,0x53,0x51,0x55,0x31,0x4F,0x4E,0x00,0x54,0x52,0x49,0x4F,0x4E,0x00,0x4E,0x53,
0x45,0x4F,0x4E,0x00,0x44,0x50,0x43,0x4D,0x4F,0x4E,0x00,0x53,0x6F,0x6E,0x67,0x20,0x63,0x6F,0x75,0x6E,0x74,0x00,0x4C,0x4F,0x4E,0x47,0x00,0x54,0x49,0x54,0x4C,0x45,
0x00,0x49,0x4E,0x46,0x4F,0x00,0x42,0x4C,0x4F,0x42,0x00,0x49,0x4E,0x54,0x00,0x53,0x6F,0x6E,0x67,0x20,0x74,0x65,0x73,0x74,0x00,0x53,0x6F,0x6E,0x67,0x20,0x74,0x69,
0x74,0x6C,0x65,0x00,0x54,0x45,0x58,0x54,0x00,0x45,0x52,0x52,0x4F,0x52,0x5F,0x45,0x52,0x52,0x4F,0x52,0x00,
0x74,0x6C,0x65,0x00,0x54,0x65,0x73,0x74,0x20,0x54,0x65,0x78,0x74,0x00,0x67,0x6F,0x6F,0x64,0x62,0x79,0x65,0x00,0x54,0x65,0x73,0x74,0x20,0x45,0x72,0x72,0x6F,0x72,
0x00,0x45,0x52,0x52,0x4F,0x52,0x5F,0x45,0x52,0x52,0x4F,0x52,0x00,
};

// end of file
2 changes: 2 additions & 0 deletions enums/japanese.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ LOCAL JAPANESE "日本語"

# LOCALPROP NOTFOUND "Not found"
# LOCALTEXT BAD "Not in English"
# LOCALTEXT TEXT "hellote"
LOCALTEXT TEXT "goodbye"
38 changes: 24 additions & 14 deletions enums/nsfplayenums.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
warnings = 0
errors = 0

now_string = datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y")
now_string = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

#
# warnings and errors
Expand Down Expand Up @@ -347,6 +347,15 @@ def check_channel(unit_key,key):
parse_error("UNIT not found: "+unit_key)
return (None,None)

def add_unique_entry(defs,id_elements,error_name,entry):
ide = entry[0:id_elements]
for i in range(len(defs)):
idi = defs[i][0:id_elements]
if idi == ide:
parse_error(error_name + " is not unique")
return
defs.append(entry)

# parse enums file

def parse_enums(path):
Expand Down Expand Up @@ -403,7 +412,8 @@ def parse_enums(path):
else:
defs_channelonlist = li
elif command == "LOCAL":
defs_local.append([p[0],p[1],[],[],[],[],[],[],[],None,[]]) # local: key, name, list, group, set, prop, songprop, unit, channel, channelset,text
add_unique_entry(defs_local,1,command+" "+p[0],
[p[0],p[1],[],[],[],[],[],[],[],None,[]]) # local: key, name, list, group, set, prop, songprop, unit, channel, channelset,text
localcurrent = len(defs_local)-1
elif command == "LOCALDEFAULT":
if localcurrent == None: parse_error("LOCAL must be used before "+command)
Expand All @@ -416,43 +426,43 @@ def parse_enums(path):
else:
(li,lk,lcount) = check_list(p[0],p[1])
if li != None:
defs_local[localcurrent][2].append((li,lk,p[2])) # list, key, name
add_unique_entry(defs_local[localcurrent][2],2,command+" "+p[1],(li,lk,p[2])) # list, key, name
elif command == "LOCALSETGROUP":
if localcurrent == None: parse_error("LOCAL must be used before "+command)
else:
gi = check_setgroup(p[0])
if gi != None:
defs_local[localcurrent][3].append((gi,p[1],p[2])) # group, name, desc
add_unique_entry(defs_local[localcurrent][3],1,command+" "+p[0],(gi,p[1],p[2])) # group, name, desc
elif command == "LOCALSET":
if localcurrent == None: parse_error("LOCAL must be used before "+command)
else:
(gi,si) = check_set(p[0],p[1])
if gi != None:
defs_local[localcurrent][4].append((gi,si,p[1],p[2])) # group, set, name, desc
add_unique_entry(defs_local[localcurrent][4],2,command+" "+p[1],(gi,si,p[1],p[2])) # group, set, name, desc
elif command == "LOCALPROP":
if localcurrent == None: parse_error("LOCAL must be used before "+command)
else:
pi = check_prop(p[0])
if pi != None:
defs_local[localcurrent][5].append((pi,p[1])) # prop, name
add_unique_entry(defs_local[localcurrent][5],1,command+" "+p[0],(pi,p[1])) # prop, name
elif command == "LOCALSONGPROP":
if localcurrent == None: parse_error("LOCAL must be used before "+command)
else:
pi = check_songprop(p[0])
if pi != None:
defs_local[localcurrent][6].append((pi,p[1])) # songprop, name
add_unique_entry(defs_local[localcurrent][6],1,command+" "+p[0],(pi,p[1])) # songprop, name
elif command == "LOCALUNIT":
if localcurrent == None: parse_error("LOCAL must be used before "+command)
else:
ui = check_unit(p[0])
if ui != None:
defs_local[localcurrent][7].append((ui,p[1],p[2])) # unit, name, desc
add_unique_entry(defs_local[localcurrent][7],1,command+" "+p[0],(ui,p[1],p[2])) # unit, name, desc
elif command == "LOCALCHANNEL":
if localcurrent == None: parse_error("LOCAL must be used before "+command)
else:
(ui,ci) = check_channel(p[0],p[1])
if ui != None:
defs_local[localcurrent][8].append((ci,p[2])) # channel, name
add_unique_entry(defs_local[localcurrent][8],1,command+" "+p[1],(ci,p[2])) # channel, name
elif command == "LOCALCHANNELSET":
if localcurrent == None: parse_error("LOCAL must be used before "+command)
else:
Expand All @@ -463,11 +473,11 @@ def parse_enums(path):
elif command == "LOCALTEXT":
if localcurrent == None: parse_error("LOCAL must be used before "+command)
else:
defs_local[localcurrent][10].append(p)
add_unique_entry(defs_local[localcurrent][10],1,command+" "+p[0],p)
elif command == "LOCALERROR":
if localcurrent == None: parse_error("LOCAL must be used before "+command)
else:
defs_local[localcurrent][10].append(("ERROR_"+p[0],p[1]))
add_unique_entry(defs_local[localcurrent][10],1,command+" "+p[0],("ERROR_"+p[0],p[1]))
parse_path = None

def parse_enum_files(files):
Expand Down Expand Up @@ -551,7 +561,7 @@ def generate_enums(file_enum,file_data,do_write):
# locale tables contain a byte index to every generated string in gen_data_blob
# defs_local: key, name, list, group, set, prop, songprop, unit, channel, channelset,text
#
table_locale = [[]] * locs
table_locale = [[] for i in range(locs)]
#
# generate list data
#
Expand Down Expand Up @@ -835,8 +845,8 @@ def generate_enums(file_enum,file_data,do_write):
for i in range(locs):
name = None
mapped = False
for (lti,lname) in defs_local[i][10]:
if lti == ti:
for (lkey,lname) in defs_local[i][10]:
if lkey == text_key:
mapped = True
name = lname
break
Expand Down
2 changes: 1 addition & 1 deletion include/nsfplayenums.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
// generated by nsfplayenums.py
// Sun Apr 21 03:40:40 2024
// 2024-04-21 04:21:35

#define NSFP_LIST_COUNT 2
#define NSFP_LIST_ENABLE 0
Expand Down

0 comments on commit 6f23b3c

Please sign in to comment.