commit f88b636

zzo38  ·  2023-06-20 01:21:10 +0000 UTC
parent 843f68a
Implement user customization of palettes by command-line arguments.
2 files changed,  +18, -3
M main.c
+6, -2
 1@@ -81,6 +81,9 @@
 2 -p #
 3   Select the palette. Valid palette numbers are 0 to 7, where 7 is the
 4   default setting and means that the running Uxn program can set colours.
 5+  If you follow the palette number by a equal sign and then RGB hex codes
 6+  then it will define that palette. Specify eight RGB colours each of which
 7+  is six hex digits, with commas in between.
 8 
 9 -q
10   Disable standard I/O.
11@@ -234,7 +237,8 @@ emulator to the program), ? for parameters that may be input and/or output,
12 
13 03 device_id uuid% >version ?extra%
14   Loads a nonstandard device, or a nonstandard command for an existing
15-  device or that applies globally; see below section for details.
16+  device or that applies globally; see below section for details. This is
17+  called a "UUID-based extension".
18 
19 a0 offset%
20   Given a 32-bit offset, seek the currently opened file to the specified
21@@ -299,7 +303,7 @@ attempt to write anything here, and MUST NOT override any devices.
22 
23 === Implemented extensions ===
24 
25-This section lists the "03 extensions" (see above) that are implemented in
26+This section lists the UUID-based extensions that are implemented in
27 this emulator (the -x switch is required, since they use nonstandard
28 expansion commands to activate them).
29 
M main.c
+12, -1
 1@@ -1514,6 +1514,17 @@ static void set_other_program(const char*s) {
 2   }
 3 }
 4 
 5+static void set_palette(char*s) {
 6+  int p=palet<<3;
 7+  FILE*f=fmemopen(s,strlen(s),"r");
 8+  if(!f) err(1,"Error with fmemopen during parsing command-line arguments");
 9+  while(p<64 && fscanf(f,"%2hhX%2hhX%2hhX",&colors[p].r,&colors[p].g,&colors[p].b)) {
10+    p++;
11+    fscanf(f,"%*[, ]");
12+  }
13+  fclose(f);
14+}
15+
16 int main(int argc,char**argv) {
17   int i,j;
18   for(i=0;i<16;i++) {
19@@ -1546,7 +1557,7 @@ int main(int argc,char**argv) {
20     case 'i': hide_cursor=1; break;
21     case 'j': joypad_repeat=1; break;
22     case 'n': use_screen=0; break;
23-    case 'p': palet=strtol(optarg,0,10)&7; break;
24+    case 'p': palet=strtol(optarg,0,10)&7; if(*optarg && optarg[1]=='=') set_palette(optarg+2); break;
25     case 'q': use_console=0; break;
26     case 's': scroll_size=strtol(optarg,0,10); break;
27     case 't': timer_rate=strtol(optarg,0,10); break;