Skip to content

Commit 6f23b3c

Browse files
committed
fix locale table generation (shared array bug, also comparing index instead of key)
add unique entry verification to avoid accidentally masking entries tweak date display
1 parent f9ff7b0 commit 6f23b3c

File tree

4 files changed

+83
-78
lines changed

4 files changed

+83
-78
lines changed

core/enums_data.h

Lines changed: 56 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
#pragma once
22
// generated by nsfplayenums.py
3-
// Sun Apr 21 03:40:40 2024
3+
// 2024-04-21 04:21:35
44

55
#include "../include/nsfplayenums.h"
66

77
const int32_t NSFPD_LIST[NSFP_LIST_COUNT] = {
8-
0, 2,
8+
0, 1,
99
};
1010

1111
typedef struct {
1212
const char* key;
1313
int32_t text;
1414
} NSFSetGroupData;
1515
const NSFSetGroupData NSFPD_GROUP[NSFP_GROUP_COUNT] = {
16-
{ "MAIN", 4 },
17-
{ "APU0", 8 },
18-
{ "APU1", 12 },
16+
{ "MAIN", 2 },
17+
{ "APU0", 4 },
18+
{ "APU1", 6 },
1919
};
2020

2121
typedef struct {
2222
const char* key;
2323
int32_t unit, text;
2424
} NSFChannelData;
2525
const NSFChannelData NSFPD_CHANNEL[NSFP_CHANNEL_COUNT] = {
26-
{ "SQU0", 0, 16 },
27-
{ "SQU1", 0, 18 },
28-
{ "TRI", 1, 20 },
29-
{ "NSE", 1, 22 },
30-
{ "DPCM", 1, 24 },
26+
{ "SQU0", 0, 8 },
27+
{ "SQU1", 0, 9 },
28+
{ "TRI", 1, 10 },
29+
{ "NSE", 1, 11 },
30+
{ "DPCM", 1, 12 },
3131
};
3232

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

6262
typedef struct {
6363
const char* key;
6464
int32_t type, text;
6565
} NSFPropData;
6666
const NSFPropData NSFPD_PROP[NSFP_PROP_COUNT] = {
67-
{ "SONGCOUNT",1, 106 },
68-
{ "LONG",2, 108 },
69-
{ "TITLE",3, 110 },
70-
{ "INFO",4, 112 },
71-
{ "BLOB",5, 114 },
67+
{ "SONGCOUNT",1, 53 },
68+
{ "LONG",2, 54 },
69+
{ "TITLE",3, 55 },
70+
{ "INFO",4, 56 },
71+
{ "BLOB",5, 57 },
7272
};
7373

7474
typedef struct {
7575
const char* key;
7676
int32_t type, text;
7777
} NSFSongPropData;
7878
const NSFSongPropData NSFPD_SONGPROP[NSFP_SONGPROP_COUNT] = {
79-
{ "INT",1, 116 },
80-
{ "SONGTEST",1, 118 },
81-
{ "LONG",2, 120 },
82-
{ "TITLE",3, 122 },
83-
{ "INFO",4, 124 },
84-
{ "BLOB",5, 126 },
79+
{ "INT",1, 58 },
80+
{ "SONGTEST",1, 59 },
81+
{ "LONG",2, 60 },
82+
{ "TITLE",3, 61 },
83+
{ "INFO",4, 62 },
84+
{ "BLOB",5, 63 },
8585
};
8686

8787
const int32_t NSFPD_TEXT[NSFP_LIST_COUNT] = {
88-
128, 130,
88+
64, 65,
8989
};
9090

91-
const int32_t NSFPD_LOCAL_TEXT[NSFP_LOCALE_COUNT][132] = {
91+
const int32_t NSFPD_LOCAL_TEXT[NSFP_LOCALE_COUNT][66] = {
9292
{
93-
0x000000,0x000000,0x000008,0x000008,0x00001B,0x000020,0x00001B,0x000020,0x00002E,0x000033,0x00002E,0x000033,0x00002E,0x00002E,0x00002E,0x00002E,
94-
0x000057,0x000057,0x00005C,0x00005C,0x000061,0x000061,0x000065,0x000065,0x000069,0x000069,0x00006E,0x000075,0x00006E,0x000075,0x00007C,0x000087,
95-
0x00007C,0x000087,0x000092,0x000099,0x000092,0x000099,0x0000A0,0x0000AD,0x0000A0,0x0000AD,0x0000C3,0x0000C3,0x0000C3,0x0000C3,0x0000CA,0x0000CA,
96-
0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000D1,0x0000D1,0x0000D1,0x0000D1,0x0000D1,0x0000D1,
97-
0x0000D1,0x0000D1,0x0000D1,0x0000D1,0x0000D1,0x0000D1,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,
98-
0x0000D8,0x0000D8,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000E4,0x0000E4,
99-
0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000EB,0x0000EB,0x0000F6,0x0000F6,0x0000FB,0x0000FB,
100-
0x000101,0x000101,0x000106,0x000106,0x00010B,0x00010B,0x00010F,0x00010F,0x0000F6,0x0000F6,0x000119,0x000119,0x000101,0x000101,0x000106,0x000106,
101-
0x000124,0x000124,0x000129,0x000129,
93+
0x000000,0x000008,0x00001B,0x000020,0x00002E,0x000033,0x00002E,0x00002E,0x000057,0x00005C,0x000061,0x000065,0x000069,0x00006E,0x000075,0x00007C,
94+
0x000087,0x000092,0x000099,0x0000A0,0x0000AD,0x0000C3,0x0000C3,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000D1,0x0000D1,0x0000D1,
95+
0x0000D1,0x0000D1,0x0000D1,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000E4,
96+
0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000EB,0x0000F6,0x0000FB,0x000101,0x000106,0x00010B,0x00010F,0x0000F6,0x000119,0x000101,0x000106,
97+
0x000124,0x000136,
10298
},
10399
{
104-
0x000000,0x000000,0x000008,0x000008,0x00001B,0x000020,0x00001B,0x000020,0x00002E,0x000033,0x00002E,0x000033,0x00002E,0x00002E,0x00002E,0x00002E,
105-
0x000057,0x000057,0x00005C,0x00005C,0x000061,0x000061,0x000065,0x000065,0x000069,0x000069,0x00006E,0x000075,0x00006E,0x000075,0x00007C,0x000087,
106-
0x00007C,0x000087,0x000092,0x000099,0x000092,0x000099,0x0000A0,0x0000AD,0x0000A0,0x0000AD,0x0000C3,0x0000C3,0x0000C3,0x0000C3,0x0000CA,0x0000CA,
107-
0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000D1,0x0000D1,0x0000D1,0x0000D1,0x0000D1,0x0000D1,
108-
0x0000D1,0x0000D1,0x0000D1,0x0000D1,0x0000D1,0x0000D1,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,
109-
0x0000D8,0x0000D8,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000E4,0x0000E4,
110-
0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000EB,0x0000EB,0x0000F6,0x0000F6,0x0000FB,0x0000FB,
111-
0x000101,0x000101,0x000106,0x000106,0x00010B,0x00010B,0x00010F,0x00010F,0x0000F6,0x0000F6,0x000119,0x000119,0x000101,0x000101,0x000106,0x000106,
112-
0x000124,0x000124,0x000129,0x000129,
100+
0x000000,0x000008,0x00001B,0x000020,0x00002E,0x000033,0x00002E,0x00002E,0x000057,0x00005C,0x000061,0x000065,0x000069,0x00006E,0x000075,0x00007C,
101+
0x000087,0x000092,0x000099,0x0000A0,0x0000AD,0x0000C3,0x0000C3,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000CA,0x0000D1,0x0000D1,0x0000D1,
102+
0x0000D1,0x0000D1,0x0000D1,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000D8,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000DE,0x0000E4,
103+
0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000E4,0x0000EB,0x0000F6,0x0000FB,0x000101,0x000106,0x00010B,0x00010F,0x0000F6,0x000119,0x000101,0x000106,
104+
0x00012E,0x000141,
113105
},
114106
};
115107

116-
const uint8_t NSFPD_LOCAL_TEXT_DATA[0x000135] = {
108+
const uint8_t NSFPD_LOCAL_TEXT_DATA[0x00014D] = {
117109
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,
118110
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,
119111
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,
@@ -123,7 +115,8 @@ const uint8_t NSFPD_LOCAL_TEXT_DATA[0x000135] = {
123115
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,
124116
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,
125117
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,
126-
0x74,0x6C,0x65,0x00,0x54,0x45,0x58,0x54,0x00,0x45,0x52,0x52,0x4F,0x52,0x5F,0x45,0x52,0x52,0x4F,0x52,0x00,
118+
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,
119+
0x00,0x45,0x52,0x52,0x4F,0x52,0x5F,0x45,0x52,0x52,0x4F,0x52,0x00,
127120
};
128121

129122
// end of file

enums/japanese.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ LOCAL JAPANESE "日本語"
22

33
# LOCALPROP NOTFOUND "Not found"
44
# LOCALTEXT BAD "Not in English"
5+
# LOCALTEXT TEXT "hellote"
6+
LOCALTEXT TEXT "goodbye"

enums/nsfplayenums.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
warnings = 0
115115
errors = 0
116116

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

119119
#
120120
# warnings and errors
@@ -347,6 +347,15 @@ def check_channel(unit_key,key):
347347
parse_error("UNIT not found: "+unit_key)
348348
return (None,None)
349349

350+
def add_unique_entry(defs,id_elements,error_name,entry):
351+
ide = entry[0:id_elements]
352+
for i in range(len(defs)):
353+
idi = defs[i][0:id_elements]
354+
if idi == ide:
355+
parse_error(error_name + " is not unique")
356+
return
357+
defs.append(entry)
358+
350359
# parse enums file
351360

352361
def parse_enums(path):
@@ -403,7 +412,8 @@ def parse_enums(path):
403412
else:
404413
defs_channelonlist = li
405414
elif command == "LOCAL":
406-
defs_local.append([p[0],p[1],[],[],[],[],[],[],[],None,[]]) # local: key, name, list, group, set, prop, songprop, unit, channel, channelset,text
415+
add_unique_entry(defs_local,1,command+" "+p[0],
416+
[p[0],p[1],[],[],[],[],[],[],[],None,[]]) # local: key, name, list, group, set, prop, songprop, unit, channel, channelset,text
407417
localcurrent = len(defs_local)-1
408418
elif command == "LOCALDEFAULT":
409419
if localcurrent == None: parse_error("LOCAL must be used before "+command)
@@ -416,43 +426,43 @@ def parse_enums(path):
416426
else:
417427
(li,lk,lcount) = check_list(p[0],p[1])
418428
if li != None:
419-
defs_local[localcurrent][2].append((li,lk,p[2])) # list, key, name
429+
add_unique_entry(defs_local[localcurrent][2],2,command+" "+p[1],(li,lk,p[2])) # list, key, name
420430
elif command == "LOCALSETGROUP":
421431
if localcurrent == None: parse_error("LOCAL must be used before "+command)
422432
else:
423433
gi = check_setgroup(p[0])
424434
if gi != None:
425-
defs_local[localcurrent][3].append((gi,p[1],p[2])) # group, name, desc
435+
add_unique_entry(defs_local[localcurrent][3],1,command+" "+p[0],(gi,p[1],p[2])) # group, name, desc
426436
elif command == "LOCALSET":
427437
if localcurrent == None: parse_error("LOCAL must be used before "+command)
428438
else:
429439
(gi,si) = check_set(p[0],p[1])
430440
if gi != None:
431-
defs_local[localcurrent][4].append((gi,si,p[1],p[2])) # group, set, name, desc
441+
add_unique_entry(defs_local[localcurrent][4],2,command+" "+p[1],(gi,si,p[1],p[2])) # group, set, name, desc
432442
elif command == "LOCALPROP":
433443
if localcurrent == None: parse_error("LOCAL must be used before "+command)
434444
else:
435445
pi = check_prop(p[0])
436446
if pi != None:
437-
defs_local[localcurrent][5].append((pi,p[1])) # prop, name
447+
add_unique_entry(defs_local[localcurrent][5],1,command+" "+p[0],(pi,p[1])) # prop, name
438448
elif command == "LOCALSONGPROP":
439449
if localcurrent == None: parse_error("LOCAL must be used before "+command)
440450
else:
441451
pi = check_songprop(p[0])
442452
if pi != None:
443-
defs_local[localcurrent][6].append((pi,p[1])) # songprop, name
453+
add_unique_entry(defs_local[localcurrent][6],1,command+" "+p[0],(pi,p[1])) # songprop, name
444454
elif command == "LOCALUNIT":
445455
if localcurrent == None: parse_error("LOCAL must be used before "+command)
446456
else:
447457
ui = check_unit(p[0])
448458
if ui != None:
449-
defs_local[localcurrent][7].append((ui,p[1],p[2])) # unit, name, desc
459+
add_unique_entry(defs_local[localcurrent][7],1,command+" "+p[0],(ui,p[1],p[2])) # unit, name, desc
450460
elif command == "LOCALCHANNEL":
451461
if localcurrent == None: parse_error("LOCAL must be used before "+command)
452462
else:
453463
(ui,ci) = check_channel(p[0],p[1])
454464
if ui != None:
455-
defs_local[localcurrent][8].append((ci,p[2])) # channel, name
465+
add_unique_entry(defs_local[localcurrent][8],1,command+" "+p[1],(ci,p[2])) # channel, name
456466
elif command == "LOCALCHANNELSET":
457467
if localcurrent == None: parse_error("LOCAL must be used before "+command)
458468
else:
@@ -463,11 +473,11 @@ def parse_enums(path):
463473
elif command == "LOCALTEXT":
464474
if localcurrent == None: parse_error("LOCAL must be used before "+command)
465475
else:
466-
defs_local[localcurrent][10].append(p)
476+
add_unique_entry(defs_local[localcurrent][10],1,command+" "+p[0],p)
467477
elif command == "LOCALERROR":
468478
if localcurrent == None: parse_error("LOCAL must be used before "+command)
469479
else:
470-
defs_local[localcurrent][10].append(("ERROR_"+p[0],p[1]))
480+
add_unique_entry(defs_local[localcurrent][10],1,command+" "+p[0],("ERROR_"+p[0],p[1]))
471481
parse_path = None
472482

473483
def parse_enum_files(files):
@@ -551,7 +561,7 @@ def generate_enums(file_enum,file_data,do_write):
551561
# locale tables contain a byte index to every generated string in gen_data_blob
552562
# defs_local: key, name, list, group, set, prop, songprop, unit, channel, channelset,text
553563
#
554-
table_locale = [[]] * locs
564+
table_locale = [[] for i in range(locs)]
555565
#
556566
# generate list data
557567
#
@@ -835,8 +845,8 @@ def generate_enums(file_enum,file_data,do_write):
835845
for i in range(locs):
836846
name = None
837847
mapped = False
838-
for (lti,lname) in defs_local[i][10]:
839-
if lti == ti:
848+
for (lkey,lname) in defs_local[i][10]:
849+
if lkey == text_key:
840850
mapped = True
841851
name = lname
842852
break

include/nsfplayenums.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22
// generated by nsfplayenums.py
3-
// Sun Apr 21 03:40:40 2024
3+
// 2024-04-21 04:21:35
44

55
#define NSFP_LIST_COUNT 2
66
#define NSFP_LIST_ENABLE 0

0 commit comments

Comments
 (0)