Skip to content

Commit

Permalink
v0.9 wip
Browse files Browse the repository at this point in the history
GZ support
deprecate SQLite; implement custom DB file format
integrate ZXDB: year, genre, brand, score, authors, inlays, screen$, instructions, maps, cheats,
new resizable image loader
new ui overlay layer
console logo
redo ZXDB import scripts
implement download()
fixed bug that prevented loading very small .pok files
fixed tigr under virtualbox/osx
replaced fdc motor sound
add fdc sounds to betadisk interface
may drag folders into window now
added button to scan games when no library is found
  • Loading branch information
r-lyeh committed Jun 15, 2024
1 parent 0abf356 commit da7d9c8
Show file tree
Hide file tree
Showing 79 changed files with 77,318 additions and 265,276 deletions.
10 changes: 8 additions & 2 deletions MAKE.bat
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ if [ "$(uname)" != "Darwin" ]; then
[ ! -f ".setup" ] && sudo apt-get -y update && sudo apt-get -y install gcc libx11-dev gcc libgl1-mesa-dev libasound2-dev mesa-common-dev && echo>.setup

# compile --------------------------------------------------------------------
gcc src/zx.c -I src -o ./Spectral.linux -O3 -DNDEBUG=3 -Wno-unused-result -Wno-format -Wno-multichar -Wno-pointer-sign -Wno-string-plus-int -Wno-empty-body -lm -lX11 -lGL -lasound -lpthread || exit
gcc src/zx.c -I src -o ./Spectral.linux -O3 -DNDEBUG=3 -Wno-unused-result -Wno-unused-value -Wno-format -Wno-multichar -Wno-pointer-sign -Wno-string-plus-int -Wno-empty-body -lm -lX11 -lGL -lasound -lpthread $* || exit
upx -9 Spectral.linux
src/res/zxdb/append.linux Spectral.linux src/res/zxdb/Spectral.db.gz

fi

if [ "$(uname)" = "Darwin" ]; then

# compile --------------------------------------------------------------------
export SDKROOT=$(xcrun --show-sdk-path)
gcc -ObjC src/zx.c -I src -o ./Spectral.osx -O3 -DNDEBUG=3 -Wno-unused-result -Wno-format -Wno-multichar -Wno-pointer-sign -Wno-string-plus-int -Wno-empty-body -framework cocoa -framework iokit -framework CoreFoundation -framework CoreAudio -framework AudioToolbox -framework OpenGL -lm || exit
gcc -ObjC src/zx.c -I src -o ./Spectral.osx -O3 -DNDEBUG=3 -Wno-unused-result -Wno-unused-value -Wno-format -Wno-multichar -Wno-pointer-sign -Wno-string-plus-int -Wno-empty-body -framework cocoa -framework iokit -framework CoreFoundation -framework CoreAudio -framework AudioToolbox -framework OpenGL -lm $* || exit
src/res/zxdb/append.osx Spectral.osx src/res/zxdb/Spectral.db.gz

# embed icon and make .app
test -d Spectral.app && rm -rf Spectral.app
Expand Down Expand Up @@ -98,6 +100,7 @@ if "%1"=="test" (

if "%1"=="dev" (
cl src\zx.c src\sys_window.cc -I src /FeSpectral.exe /Zi %ALL_BUT_FIRST% || goto error
copy /y src\res\zxdb\Spectral.db.gz Spectral.db 1>nul 2>nul

tasklist /fi "ImageName eq remedybg.exe" 2>NUL | find /I "exe">NUL || start remedybg -q -g Spectral.exe

Expand All @@ -107,12 +110,14 @@ if "%1"=="dev" (
if "%1"=="opt" (
rem do not use /O1 or /O2 below. ayumi drums will be broken in AfterBurner.dsk otherwise
call make nil /Ox /MT /DNDEBUG /GL /GF /arch:AVX2 %ALL_BUT_FIRST% || goto error
copy /y src\res\zxdb\Spectral.db.gz Spectral.db 1>nul 2>nul
exit /b
)

if "%1"=="rel" (
call make opt -Dmain=WinMain -DNDEBUG=3 %ALL_BUT_FIRST% || goto error
where /q upx.exe && upx Spectral.exe
src\res\zxdb\append Spectral.exe src\res\zxdb\Spectral.db.gz && if exist "Spectral.db" del Spectral.db
exit /b 1
)

Expand All @@ -127,6 +132,7 @@ where /q cl.exe || call "%ProgramFiles(x86)%/microsoft visual studio/2017/commun

@echo on
cl src\zx.c src\sys_window.cc -I src /FeSpectral.exe %ALL_BUT_FIRST% || goto error
copy /y src\res\zxdb\Spectral.db.gz Spectral.db 1>nul 2>nul

@echo off
where /Q ResourceHacker.exe && ResourceHacker.exe -open Spectral.exe -save Spectral.exe -action addskip -res src\res\img\noto_1f47b.ico -mask ICONGROUP,MAINICON,0
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ Code is highly experimental and prone to change in the future. I will keep alter
- [x] TAP/TZX/CSW tapes. Z80/SNA snaps. ROM/IF2 roms. <!-- @todo: tzx info on window title -->
- [x] DSK/EDSK/TRD/SCL/FDI/MGT/IMG/HOBETA disks.
- [x] SCR/PNG screenshots. <!-- ulaplus screenshots. video recording -->
- [x] ZIP/RAR archives.
- [x] ZIP/RAR/GZ archives.
- [x] µ765/Betadisk interfaces.
- [x] Auto load games. Auto play/stop tape. Turbo loads.
- [x] Auto load games. Auto play/stop tape. TurboROM.
- [x] Game browser. <!-- @todo: rewrite this -->
- [x] Graphical tape browser.
- [x] 50/60Hz fps lock.
Expand All @@ -35,7 +35,7 @@ Code is highly experimental and prone to change in the future. I will keep alter
- [x] Internal savestates.
- [x] Graphical User Interface.
- [x] Portable: Windows, Linux, MacOS.
- [ ] ZXDB integration.
- [x] ZXDB integration.
- [ ] Gallery marquee. <!-- Flex. Tape cases. ZX catalog on demand. -->
- [ ] Extra accurate Z80 backend. <!-- @todo: contended mem, contended ports, memptr, snow, Q, floating bus (+2a/+3) -->
- [ ] Cycle accurate (border, multicolor, etc).
Expand Down
Binary file removed Spectral.exe
Binary file not shown.
Binary file removed releases/Spectral-01.exe
Binary file not shown.
Binary file added releases/Spectral-01.zip
Binary file not shown.
Binary file removed releases/Spectral-02.exe
Binary file not shown.
Binary file added releases/Spectral-02.zip
Binary file not shown.
Binary file removed releases/Spectral-03.exe
Binary file not shown.
Binary file added releases/Spectral-03.zip
Binary file not shown.
Binary file removed releases/Spectral-04.exe
Binary file not shown.
Binary file added releases/Spectral-04.zip
Binary file not shown.
Binary file removed releases/Spectral-05.exe
Binary file not shown.
Binary file added releases/Spectral-05.zip
Binary file not shown.
Binary file removed releases/Spectral-06.exe
Binary file not shown.
Binary file added releases/Spectral-06.zip
Binary file not shown.
Binary file removed releases/Spectral-07.exe
Binary file not shown.
Binary file added releases/Spectral-07.zip
Binary file not shown.
Binary file removed releases/Spectral-08.exe
Binary file not shown.
Binary file added releases/Spectral-08.zip
Binary file not shown.
122 changes: 99 additions & 23 deletions src/3rd.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define TIGR_C
#define TIGR_DO_NOT_PRESERVE_WINDOW_POSITION
#include "3rd_tigr.h"
#include "3rd_tigrobjc.h"
#include "3rd_tigrmousecursor.h"
#include "3rd_tigrdragndrop.h"

Expand All @@ -23,36 +24,111 @@
#define DEFLATE_C
#include "3rd_deflate.h"
#include "3rd_zlib.h" // for zlib streams, like CSW2
#include "3rd_gz.h" // gunzip
#define ZIP_C
#include "3rd_zip.h"
#include "3rd_rar.h"
#define DIR_C
#include "3rd_dir.h"
#define STB_IMAGE_IMPLEMENTATION
#include "3rd_stbimage.h"
#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include "3rd_stbimage_resize2.h"

#if 0 // defined __has_include
# if __has_include ("3rd_sqlite3.c")
// gcc: #pragma GCC warning "warning message"
// msc: #pragma message ( "your warning text here" ) // works in gcc too, albeit not as intended
# pragma message ("ZXDB/Sqlite enabled")
# define SQLITE_C 1
# endif
#if 1
#define TFD_IMPLEMENTATION
extern Tigr *app;
#define GetForegroundWindow() ((HWND)(app->handle))
#include "3rd_tfd.h"
#undef GetForegroundWindow
#else
#include "3rd_osdialog.h"
#include "3rd_osdialog.c"
# if defined __APPLE__
#include "3rd_osdialog_mac.m"
#elif defined _WIN32
#include "3rd_osdialog_win.c"
#pragma comment(lib, "comdlg32")
#else
//#include "3rd_osdialog_gtk2.c"
#include "3rd_osdialog_gtk3.c"
#endif

#if SQLITE_C
//#include "3rd_sqlite3.h"
#include "3rd_sqlite3.c"
#undef TK_ESCAPE
#undef TK_SPACE
#undef TK_END
#undef TK_INSERT
#undef TK_DELETE
#undef TK_LSHIFT
#undef TK_RSHIFT
#undef TK_COMMA
#undef TK_MINUS
#undef TK_DOT
#undef TK_SLASH
#undef NB
#endif


#include "3rd_bin.h"


#ifdef _WIN32

#include <wininet.h>
#pragma comment(lib,"wininet")

int download_file( FILE *out, const char *url ) {
int ok = false;
char buffer[ 4096 ];
DWORD response_size = 0;

if( out )
for( HINTERNET session = InternetOpenA("" /*"fwk.download_file"*/, PRE_CONFIG_INTERNET_ACCESS, NULL,NULL/*INTERNET_INVALID_PORT_NUMBER*/, 0); session; InternetCloseHandle(session), session = 0 ) // @fixme: download_file
for( HINTERNET request = InternetOpenUrlA(session, url, NULL, 0, INTERNET_FLAG_RELOAD|INTERNET_FLAG_SECURE, 0); request; InternetCloseHandle(request), request = 0 )
for(; InternetReadFile(request, buffer, sizeof(buffer), &response_size) != FALSE && response_size > 0; ) {
ok = (fwrite(buffer, response_size, 1, out) == 1);
if(!ok) break;
}

return ok;
}

#elif 1

int download_file( FILE *out, const char *url ) {
if( !out ) return 0;

int ok = false;
char buffer[ 2048 ];

if( url[0] != '!' ) {
if( !ok ) sprintf(buffer, "!curl %s", url), ok = download_file(out, buffer);
if( !ok ) sprintf(buffer, "!wget -qO- %s", url), ok = download_file(out, buffer);
}
else
for( FILE *fp = popen(url+1, "r"); fp; pclose(fp), fp = 0)
for(; !feof(fp); ) {
int count = fread(buffer, 1, sizeof(buffer), fp);
printf("downloading from `%s` (%d bytes)\n", url+1, count);
ok = count > 0;
if(!ok) break;
fwrite(buffer, count, 1, fp);
ok = count > 0;
if(!ok) break;
}

return ok;
}

#else

#define HTTPS_IMPLEMENTATION
#define copy copy2
#include "3rd_https.h"
#undef I
#undef R

int download_file( FILE *out, const char *url ) {
int ok = false;
if( out ) for( https_t *h = https_get(url, NULL); h; https_release(h), h = NULL ) {
while (https_process(h) == HTTPS_STATUS_PENDING)
#ifdef _WIN32
Sleep(1); // 1ms
#else
usleep(1000); // 1ms
#endif
printf("fetch status L%d, %d %s\n\n%.*s\n", https_process(h), h->status_code, h->content_type, (int)h->response_size, (char*)h->response_data);
if(https_process(h) == HTTPS_STATUS_COMPLETED)
ok = fwrite(h->response_data, h->response_size, 1, out) == 1;
}
return ok;
}

#endif
42 changes: 42 additions & 0 deletions src/3rd_gz.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// gunzip unpacker
// - rlyeh, public domain

char *gunzip(const void *data_, unsigned len, unsigned *outlen_) {
const unsigned char *data = (const unsigned char *)data_;
if( data && !memcmp(data, "\x1f\x8b\x08", 3) ) {
int flags = data[3];

const unsigned char *ptr = data + 3+1 + 4 + 1 + 1; // header+flags + timestamp + extra flags + os

// https://www.rfc-editor.org/rfc/rfc1952
if( flags & 4 ) ptr += ptr[0] << 0 | ptr[1] << 8; // FEXTRA
if( flags & 8 ) ptr += strlen(ptr) + 1; // FNAME
if( flags & 16 ) ptr += strlen(ptr) + 1; // FCOMMENT
if( flags & 2 ) ptr += 2; // FHCRC
// if( flags & 1 ) ptr += strlen(ptr) + 1; // FTEXT

const unsigned outlen = *(unsigned *)&data[ len - 4 ];

unsigned char *out = 0;
out = realloc(out, outlen);

mz_stream z = {0};
z.avail_in = (len - 4 /*crc*/ - 4 /*outlen*/) - (ptr - data);
z.next_in = ptr;
z.avail_out = outlen;
z.next_out = out;

mz_inflateInit2(&z, -MZ_DEFAULT_WINDOW_BITS);
int ret = mz_inflate(&z, MZ_SYNC_FLUSH);
mz_inflateEnd(&z);

if( ret >= 0 ) {
if( outlen_ ) *outlen_ = outlen;
return out;
}

// alert("error: cant decompress .gz file (gzip)");
out = realloc(out, 0);
}
return NULL;
}
Loading

0 comments on commit da7d9c8

Please sign in to comment.