Skip to content

Commit 34f2830

Browse files
author
r-lyeh
committed
v1.16-WIP
fix: disabled /GS check in clang-cl builds for now (win32) palette color swapper apply palette bloom levels while editor is displayed fix bloom settings per pcw/amber palettes try a different dialogs library (win32)
1 parent f70cb71 commit 34f2830

8 files changed

Lines changed: 84 additions & 35 deletions

File tree

MAKE.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ where /q cl.exe || call "%ProgramFiles(x86)%/microsoft visual studio/2017/commun
207207

208208
setlocal enableDelayedExpansion
209209
if "%cc%"=="" (
210-
set "cc=clang-cl -Wno-multichar -Wno-unused-value -Wno-macro-redefined -Wno-implicit-function-declaration -Wno-deprecated-declarations -Wno-empty-body -Wno-pointer-sign -Wno-dangling-else -Wno-string-plus-int"
210+
set "cc=clang-cl -GS- -Wno-multichar -Wno-unused-value -Wno-macro-redefined -Wno-implicit-function-declaration -Wno-deprecated-declarations -Wno-empty-body -Wno-pointer-sign -Wno-dangling-else -Wno-string-plus-int"
211211
(where /q clang-cl || set "cc=cl" >nul 2>nul)
212212
)
213213

@@ -251,7 +251,7 @@ ping -n 2 -w 1500 localhost > nul && rem wait 1s between 2 consecutive pings, so
251251
where /q rcedit-x64 || curl -LO https://github.com/electron/rcedit/releases/download/v2.0.0/rcedit-x64.exe
252252
where /q rcedit-x64 && ^
253253
rcedit-x64 "Spectral.exe" --set-file-version "!year!.!month!.!today!.!today!!month!" && ^
254-
rcedit-x64 "Spectral.exe" --set-product-version "1.15" && ^
254+
rcedit-x64 "Spectral.exe" --set-product-version "1.16-WIP" && ^
255255
rcedit-x64 "Spectral.exe" --set-icon src\res\img\noto_1f47b.ico || goto error
256256

257257
if "%__DOTNET_PREFERRED_BITNESS%"=="32" (

src/3rd.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@
5555
#include "3rd_thread.h"
5656
#include "3rd_bin.h"
5757

58-
#if 1 // ndef __linux__
58+
#ifndef _WIN32 // ndef __linux__
5959
#define TFD_IMPLEMENTATION
6060
//#define GetForegroundWindow GetActiveWindow
61-
#define GetForegroundWindow() ((HWND)app->handle)
61+
//#define GetForegroundWindow() ((HWND)app->handle)
6262
#include "3rd_tfd.h"
63-
#undef GetForegroundWindow
63+
//#undef GetForegroundWindow
6464
#else
6565
#include "3rd_osdialog.h"
6666
#include "3rd_osdialog.c"

src/3rd_tigr.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2611,6 +2611,8 @@ WPARAM MapLeftRightKeys( WPARAM vk, LPARAM lParam)
26112611
return new_vk;
26122612
}
26132613

2614+
static int tigrWinVK(int key); //< @r-lyeh
2615+
26142616
LRESULT CALLBACK tigrWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
26152617
Tigr* bmp;
26162618
TigrInternal* win = NULL;
@@ -3218,7 +3220,7 @@ static int tigrWinVK_DEPRECATED(int key) { //< @r-lyeh
32183220
return 0;
32193221
}
32203222

3221-
static int tigrWinVK(int key) {
3223+
int tigrWinVK(int key) {
32223224
if (key >= 'A' && key <= 'Z')
32233225
return key;
32243226
if (key >= '0' && key <= '9')

src/app.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/*
2+
int _getch();
3+
#include <string.h>
4+
#define strdup _strdup // fucking m$
5+
#define strcmpi _strcmpi // fucking m$
6+
#include <stdio.h>
7+
#define fileno _fileno // fucking m$
8+
*/
9+
110
/* planned for v1.16
211
312
- [ ] irc/lobby (mount server)
@@ -317,7 +326,7 @@ void loggers(int m);
317326
// [ ] XL1 (Compilation)
318327
#endif
319328

320-
#define SPECTRAL "v1.15"
329+
#define SPECTRAL "v1.16-WIP"
321330

322331
#ifndef DEV
323332
#if NDEBUG >= 2
@@ -524,7 +533,7 @@ int save_config() {
524533
if(ZX_FOLDER && ZX_FOLDER[0]) ZX_FOLDER = strdup(relpath(ZX_FOLDER,cwd())); // @leak
525534
//if(ZX_SHADER && ZX_SHADER[0]) ZX_SHADER = strdup(relpath(ZX_SHADER,cwd())); // @leak
526535

527-
mkdir(".Spectral", 0777);
536+
sys_mkdir(".Spectral", 0777);
528537
int errors = 0;
529538
for( FILE *fp = fopen(".Spectral/Spectral.ini", "wt"); fp; fclose(fp), fp = 0 ) {
530539
#define INI_SAVE_NUM(opt) errors += fprintf(fp, "%s=%d\n", #opt, opt) != 2;
@@ -551,23 +560,29 @@ int load_config() {
551560
extern int cmdkey;
552561
extern const char* cmdarg;
553562
ZX_PENTAGON = ZX & 1; ZX &= ~1;
554-
if(ZX_FOLDER && ZX_FOLDER[0] > 32) cmdkey = 'SCAN', cmdarg = ZX_FOLDER;
555563
}
556564
{
557565
int size;
558566
// load custom shader. revert option if file cannot be loaded or does not exist
559567
unsigned char *fx = readfile(".Spectral/Spectral.fx", &size);
560568
ZX_SHADED *= fx && size ? load_shaderbin(fx, size), free(fx), 1 : 0;
561569
// load custom palette. revert option if file cannot be loaded or does not exist
570+
if( ZX_PALETTE == ZX_PALETTE_EXTERNAL ) {
562571
unsigned char *pal = readfile(".Spectral/Spectral.pal", &size);
563572
ZX_PALETTE *= pal && size ? pal_loadbin(pal, size), free(pal), 1 : 0;
573+
}
564574
}
565575
{
566576
// convert relative to absolute paths
567577
if(ZX_FOLDER && ZX_FOLDER[0]) ZX_FOLDER = strdup(abspath(ZX_FOLDER)); // @leak
568578
if(ZX_MEDIA && ZX_MEDIA[0] && ZX_MEDIA[0] != '#' ) ZX_MEDIA = strdup(abspath(ZX_MEDIA)); // @leak
569579
//if(ZX_SHADER && ZX_SHADER[0]) ZX_SHADER = strdup(abspath(ZX_SHADER)); // @leak
570580
}
581+
582+
// scan
583+
// if(!ZX_PLAYER)
584+
// if(ZX_FOLDER && ZX_FOLDER[0] > 32) rescan(ZX_FOLDER); // cmdkey = 'SCAN', cmdarg = ZX_FOLDER;
585+
571586
return !errors;
572587
}
573588

@@ -1920,6 +1935,7 @@ char* game_browser(int version) { // returns true if loaded
19201935
}
19211936

19221937
void logo(void) {
1938+
cputs("");
19231939
cputs("\3 \3 \3 \3 \3 \3 \3 \3 \2 \2 \2 \2 \2 \2 \2 \2 \2 \2 \2 \2 \2 \2 \2 \2 \6 \6 \6 \6 \6 \6 \6 \6 \6 \6 \6 \6 \6 \6 \6 \4 \4 \4 \4 \4 \4 \4 \4 \4 \4 \4 \4 \4 \4 \4 \4 \5 \5 \5 \5 \5 \5 \5 \5 \5 \5 \5 \5 \5 \5 \5 \5 \5 \5 \1 \1 \1 \1 \1█");
19241940
cputs("\3█\3▀\3▀\3▀\3▀\3▀\2▀\2▀\2▀\2▀\2 \2█\2▀\2▀\2▀\2▀\2▀\2▀\2▀\2▀\2█\2 \6█\6▀\6▀\6▀\6▀\6▀\6▀\6▀\6▀\6▀\6 \6█\6▀\4▀\4▀\4▀\4▀\4▀\4▀\4▀\4▀\4 \4▀\4▀\4▀\4▀\4█\4▀\4▀\4▀\4▀\5▀\5 \5█\5▀\5▀\5▀\5▀\5▀\5▀\5▀\5▀\5▀\5 \5▀\5▀\5▀\5▀\5▀\1▀\1▀\1▀\1▀\1█\1 \1█");
19251941
cputs("\3▀\3▀\3▀\3▀\2▀\2▀\2▀\2▀\2▀\2█\2 \2█\2 \2 \2 \2 \2 \2 \2 \2 \6█\6 \6█\6▀\6▀\6▀\6▀\6▀\6▀\6▀\6▀\6▀\6 \4█\4 \4 \4 \4 \4 \4 \4 \4 \4 \4 \4 \4 \4 \4 \4█\4 \4 \5 \5 \5 \5 \5█\5 \5 \5 \5 \5 \5 \5 \5 \5 \5 \5█\5▀\5▀\1▀\1▀\1▀\1▀\1▀\1▀\1█\1 \1█");
@@ -2062,7 +2078,7 @@ int main() {
20622078
// fixed settings on zxplayer builds
20632079
if( ZX_PLAYER ) {
20642080
ZX_HORACE = 0;
2065-
ZX_PALETTE = ZX_PLAYER_PALETTE; // vivid
2081+
ZX_PALETTE = ZX_PALETTE_PLAYER; // vivid
20662082
ZX_CONSOLE = 0;
20672083
ZX_ULAPLUS = 0; // no ula+
20682084
ZX_RF = strstri(__argv[0], "-rf") ? 1 : 0;
@@ -2591,7 +2607,7 @@ if( do_runahead == 0 ) {
25912607

25922608
if(ZX_PALETTE_PREVIEW)
25932609
if(draw_palette(app, ZXPalettes[ZX_PALETTE] /*ZXPalette*/, 2+ZXPaletteNames[ZX_PALETTE % countof(ZXPaletteNames)]))
2594-
palette_use(ZX_PALETTE);
2610+
palette_use(ZX_PALETTE, 1);
25952611

25962612
// rec before/after UI,
25972613
int rec(Tigr*);
@@ -2696,10 +2712,9 @@ if( do_runahead == 0 ) {
26962712
if(cmdkey_) alert(va("command not found `%08x`", cmdkey_));
26972713
#endif
26982714
break; case 'SETG': ZX_BLUR = 50;
2699-
ZX_BLOOM = 0;
27002715
ZX_GRAIN = 0;
27012716
ZX_ULAPLUS = 2;
2702-
palette_use(ZX_PALETTE = 0);
2717+
palette_use(ZX_PALETTE = 0, ZX_BLOOM = 1);
27032718
ZX_PALETTE_PREVIEW = 0;
27042719
ZX_SHADED = 0;
27052720
ZX_RF = 1;
@@ -2858,8 +2873,8 @@ if( do_runahead == 0 ) {
28582873
if(game) free(game);
28592874
}}
28602875

2861-
break; case 'PALB': { const char *file = app_loadfile(ZX_FOLDER); if( file && strendi(file, ".pal") ) if( pal_load(file) ) palette_use(ZX_PALETTE = countof(ZXPalettes) - 1), cmdkey = 'PAL0'; }
2862-
break; case 'PAL': ZX_PALETTE = (ZX_PALETTE+1)%countof(ZXPalettes); if(cmdarg_) ZX_PALETTE=atoi(cmdarg_); palette_use(ZX_PALETTE), ZX_BLOOM = atoi(ZXPaletteNames[ZX_PALETTE]);
2876+
break; case 'PALB': { const char *file = app_loadfile(ZX_FOLDER); if( file && strendi(file, ".pal") ) if( pal_load(file) ) palette_use(ZX_PALETTE = countof(ZXPalettes) - 1, 1), cmdkey = 'PAL0'; }
2877+
break; case 'PAL': ZX_PALETTE = (ZX_PALETTE+1)%countof(ZXPalettes); if(cmdarg_) ZX_PALETTE=atoi(cmdarg_); palette_use(ZX_PALETTE, 1);
28632878
break; case 'PALP': ZX_PALETTE_PREVIEW ^= 1; if(cmdarg_) ZX_PALETTE_PREVIEW=(ZX_PALETTE_PREVIEW * (cmdarg_[0] == '^')) ^ atoi(cmdarg_ + !isdigit(cmdarg_[0]));
28642879
break; case 'MICE': ZX_MOUSE = (ZX_MOUSE+1)%3; if(cmdarg_) ZX_MOUSE=atoi(cmdarg_); if(ZX_GUNSTICK) ZX_JOYSTICKS[0] = 0; // cycle mouse/guns
28652880
break; case 'ULA': ZX_ULAPLUS = (ZX_ULAPLUS+1)%3; if(cmdarg_) ZX_ULAPLUS=atoi(cmdarg_); // cycle ulaplus
@@ -3067,11 +3082,11 @@ if( do_runahead == 0 ) {
30673082

30683083
ui_dialog_checkbox2(&ZX_PALETTE_PREVIEW,"Editor ","- Display Palette editor -",NULL);
30693084

3070-
ui_dialog_option(1,"OK\n",0,'PAL',va("%d", ZX_PALETTE));
3085+
ui_dialog_option(1,"OK\n",0,0,NULL); //'PAL',va("%d", ZX_PALETTE));
30713086

30723087
case 'PAL1':
30733088
cmdkey = 'PAL1';
3074-
palette_use(ZX_PALETTE);
3089+
palette_use(ZX_PALETTE, 1);
30753090

30763091
break; case 'RJOY': cmdkey = 'JOY0';
30773092
break; case 'JOY0': {

src/sys_xplat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ typedef unsigned int rgba;
2626
#endif
2727

2828
#ifdef _WIN32
29-
#define mkdir(p,m) mkdir(p)
29+
#define sys_mkdir(p,m) mkdir(p)
3030
#else
31+
#define sys_mkdir(p,m) mkdir(p,m)
3132
#include <limits.h>
3233
#define MAX_PATH PATH_MAX // (defined in limits.h)
3334

src/zx.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,7 +2083,7 @@ void reset(unsigned FLAGS) {
20832083
audio_reset();
20842084

20852085
ula_reset();
2086-
palette_use(ZX_PALETTE);
2086+
palette_use(ZX_PALETTE, 0);
20872087

20882088
mouse_clip(0);
20892089
mouse_cursor(1);
@@ -2593,7 +2593,7 @@ int load(const char *filename, int model) { // `model`: explicit model to use, o
25932593
}
25942594
if( strendi(filename, ".pal") ) {
25952595
if( pal_load(filename) ) { // .pal
2596-
palette_use(ZX_PALETTE = countof(ZXPalettes) - 1);
2596+
palette_use(ZX_PALETTE = countof(ZXPalettes) - 1, 0);
25972597
return 1;
25982598
}
25992599
}

src/zx_db.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,8 @@ char* zxdb_download(const zxdb z, const char *url, int *len) {
630630

631631
// convert /url/basename to /path/file.zip/basename
632632
char path[128];
633-
do_once mkdir(".Spectral", 0777);
634-
snprintf(path, 128, ".Spectral/%c", index); mkdir(path, 0777);
633+
do_once sys_mkdir(".Spectral", 0777);
634+
snprintf(path, 128, ".Spectral/%c", index); sys_mkdir(path, 0777);
635635
snprintf(path, 128, ".Spectral/%c/%s[%s].zip/%s", index, roman, id, basename(url));
636636

637637
char *cache = unzip(path, len);

src/zx_pal.h

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
#define hex(rrggbb) rgb((0x##rrggbb)>>24,(0x##rrggbb&0xff00)>>16,(0x##rrggbb&0xff))
88

99
// default palette for the standalone player
10-
enum { ZX_PLAYER_PALETTE = 14 }; // vivid
10+
enum { ZX_PALETTE_PLAYER = 15 }; // vivid
11+
enum { ZX_PALETTE_EXTERNAL = 26 };
12+
enum { ZX_PALETTE_GRAY = 24 };
1113

1214
// first 2-digit number configures ZX_BLOOM
1315
const char *ZXPaletteNames[] = {
1416
/*#00*/ "00" "Spectral",
17+
"00" "?",
1518
/*#01*/ "00" "Modern",
1619
/*#02*/ "00" "Reborn",
1720
/*#03*/ "00" "Remix\n",
@@ -30,12 +33,13 @@ const char *ZXPaletteNames[] = {
3033
/*#16*/ "00" "Sintez2\n",
3134
/*#17*/ "40" "CPC",
3235
/*#18*/ "00" "EGA",
33-
/*#19*/ "00" "Gameboy",
34-
/*#20*/ "20" "PCW", // best with ZX_BLOOM=20
35-
/*#21*/ "90" "Amber", // best with ZX_BLOOM=90
36-
/*#22*/ "20" "Gray", // best with ZX_BLOOM=20
37-
/*#23*/ "20" "Negative\n", // best with ZX_BLOOM=20
38-
/*#24*/ "00" "External", // must be last entry
36+
/*#19*/ "00" "MSX2",
37+
/*#20*/ "00" "Gameboy",
38+
/*#21*/ "90" "PCW", // best with ZX_BLOOM=90
39+
/*#22*/ "90" "Amber", // best with ZX_BLOOM=90
40+
/*#23*/ "20" "Gray", // best with ZX_BLOOM=20
41+
/*#24*/ "20" "Negative\n", // best with ZX_BLOOM=20
42+
/*#25*/ "00" "External", // must be last entry
3943
};
4044

4145
rgba ZXPalettes[][64] = {
@@ -51,6 +55,15 @@ rgba ZXPalettes[][64] = {
5155
rgb(0x12,0x10,0x12),rgb(0x00,0x00,0xFF),rgb(0xFF,0x00,0x00),rgb(0xFF,0x00,0xFF),
5256
rgb(0x00,0xFF,0x00),rgb(0x00,0xFF,0xFF),rgb(0xFF,0xFF,0x00),rgb(0xFF,0xFF,0xFF),
5357
},
58+
{
59+
// "?"
60+
rgb( 4, 12, 24),rgb( 64, 12, 184),rgb( 211, 61, 1),rgb( 208, 0, 79),rgb( 22, 165, 40),rgb( 0, 191, 153),rgb( 255, 180, 21),rgb( 230, 200, 180),
61+
rgb( 4, 12, 24),rgb( 83, 16, 239),rgb( 255, 71, 0),rgb( 255, 0, 96),rgb( 11, 227, 38),rgb( 26, 255, 164),rgb( 255, 227, 0),rgb( 255, 255, 175),
62+
63+
// fantasy15, v1
64+
// rgb(0x04,0x0c,0x18),rgb(0x00,0x00,0xc0),rgb(0xc0,0x00,0x00),rgb(0x9d,0x00,0xd9),rgb(0x00,0xc0,0x00),rgb(0x00,0xc0,0xc0),rgb(0xc8,0xc8,0x00),rgb(0xc0,0xc0,0xc0),
65+
// rgb(0x04,0x0c,0x18),rgb(0x00,0x40,0xff),rgb(0xea,0x06,0x40),rgb(0xff,0x40,0xff),rgb(0x40,0xff,0x00),rgb(0x04,0xff,0xa2),rgb(0xff,0xd8,0x00),rgb(0xff,0xff,0xff),
66+
},
5467
{
5568
// modern, experiment with modern blue-ish 0, reddish 7, also yellowish 15 among other modifs
5669
//rgb( 37, 44, 56),rgb( 0, 82,149),rgb(170, 0, 30),rgb(165, 1, 96),
@@ -270,6 +283,11 @@ rgba ZXPalettes[][64] = {
270283
rgb( 0, 0, 0),rgb( 0, 0,255),rgb(255, 0, 0),rgb(255, 0, 85),
271284
rgb( 0,255, 0),rgb( 0,255,255),rgb(255,255, 0),rgb(255,255,255),
272285
},
286+
{
287+
// adapted from msx2 values. v9958 3-bit: 0,40,83,116,156,187,225,255
288+
rgb( 000, 000, 000),rgb( 000, 000, 156),rgb( 156, 000, 000),rgb( 156, 000, 156),rgb( 000, 156, 000),rgb( 000, 156, 156),rgb( 156, 156, 000),rgb( 156, 156, 156),
289+
rgb( 000, 000, 000),rgb( 000, 000, 225),rgb( 225, 000, 000),rgb( 225, 000, 225),rgb( 000, 225, 000),rgb( 000, 225, 225),rgb( 225, 225, 000),rgb( 225, 225, 225),
290+
},
273291
{
274292
// gameboy. should be 4 shades, but we're doing 8 shades: many games are unplayable otherwise.
275293
rgb( 35-10, 84-10, 28-10),rgb( 35, 84, 28),rgb( 59-10,158-10, 59-10),rgb( 59,158, 59),rgb(124-10,186-10, 49-10),rgb(124,186, 49),rgb(174-10,255-10, 38-10),rgb(174,255, 38),
@@ -335,13 +353,14 @@ rgba ZXPalettes[][64] = {
335353
},
336354
};
337355

338-
void palette_use(int palette) {
356+
void palette_use(int palette, int bloom_cfg) {
339357
#if 0
340358
memcpy(&ZXPalettes[palette][16], ZXPalette+16, sizeof(rgba) * (64-16) );
341359
memcpy(ZXPalette, ZXPalettes[palette], sizeof(rgba) * 64);
342360
#else
343361
memcpy(ZXPalette, ZXPalettes[palette], sizeof(rgba) * 16);
344362
#endif
363+
if(bloom_cfg) ZX_BLOOM = atoi(ZXPaletteNames[palette]);
345364
}
346365

347366
int pal_loadbin(const void *palette, int size) {
@@ -404,7 +423,19 @@ int draw_palette(Tigr *app, unsigned* pal16, const char *name) {
404423
if( lmb ) {
405424
if( key_pressed(TK_SHIFT) ) {
406425
ZXBorderColor = i;
407-
} else {
426+
}
427+
else
428+
if( key_pressed(TK_CONTROL) ) {
429+
static int swap = -1;
430+
if( swap < 0 ) swap = index;
431+
else {
432+
unsigned copy = pal16[swap];
433+
pal16[swap] = pal16[index];
434+
pal16[index] = copy;
435+
swap = -1;
436+
}
437+
}
438+
else {
408439
byte *entry = (byte*)(&pal16[index]);
409440
char *hexcolor = tinyfd_colorChooser(NULL,NULL,entry,entry); // #hex = pick(title,#hex,in,out)
410441
changed = 1;
@@ -446,11 +477,11 @@ int draw_palette(Tigr *app, unsigned* pal16, const char *name) {
446477
ui_at(app, _320/2+offx/2+16*4,offy-theFontH+theFontH/2);
447478
if(ui_click(NULL,">")) changed = 1, ZX_PALETTE = (ZX_PALETTE+1) % countof(ZXPalettes);
448479

449-
if( 0 )
450480
if( lmb ) {
451-
for(int i = 0; i < 16; ++i ) {
452-
TPixel p = (TPixel){.rgba = pal16[i]};
453-
printf("rgb(%3d,%3d,%3d),%s", p.r, p.g, p.b, !((i+1) % 8) ? "\n" : "" );
481+
if( name ) printf("// %s\n", name);
482+
for(int j = 0; j < 16; ++j ) {
483+
TPixel p = (TPixel){.rgba = pal16[j]};
484+
printf("rgb(%4d,%4d,%4d),%s", p.r, p.g, p.b, !((j+1) % 8) ? "\n" : "" );
454485
}
455486
}
456487

0 commit comments

Comments
 (0)